Skip to content

Feature: Allow skipping stages #10

@vzam

Description

@vzam

I see some great use cases for the library in unit testing, to create some fake objects and convert them into my models. It would be nice if steps were skippable, such that the long lists such as:

CreateFakeStudent
  .WithRandomId()
  .WithRandomName()
  .WithRandomPhone()
  .WithBudget(100)

could be replaced with: CreateFakeStudent.WithBudget(100). This makes the intent of the faked object clearer. The WithRandomX methods I have shown are FluentDefaults so they would be implicit. A possible implementation would allow doing that:

[FluentApi]
class FakeStudent {
  [FluentMember(0)]
  [FluentSkippable]
  public Guid Id {get;set;} = Guid.NewGuid();

  [FluentMember(1)]
  [FluentSkippable]
  public string Name {get;set;} = "John Doe"; // not random but you get the point

  [FluentMember(2)]
  [FluentSkippable]
  public string Phome {get;set;} = "123";

  [FluentMember(3)]
  public int Budget {get;set;}
}

and generate:

// no interface for Id because it is the first step

interface INameSkippable : IPhoneSkippable {
  void WithName();
}

interface IPhoneSkippable : IBudget {
  void WithPhone();
}

interface IBudget {
  FakeStudent WithBudget();
}

static class CreateFakeStudent {
  static INameSkippable WithId() { ... }
  static IPhoneSkippable WithPhone() { ... }
  static IBudget WithBudget() { ... }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions