I want to create a list of custom objects using AutoFixture . I want the first N objects to have the property set to one value, and the rest to set it to another value (or just set according to the Fixture strategy by default).
I know that I can use Fixture.CreateMany<T>.With , but this will apply the function to all members of the list.
NBuilder has methods called TheFirst and TheNext (among others) that provide this functionality. An example of their use:
For the Foo class:
class Foo { public string Bar {get; set;} public int Blub {get; set;} }
You can create an instance of Foo like this:
class TestSomethingUsingFoo {
Here is a list of objects of type Foo with the following properties:
[Object] Foo.Bar Foo.Blub -------------------------------- 0 Baz 10 1 Baz 10 2 Baz 10 3 Baz 10 4 Baz 10 5 Qux 10 6 Qux 10 7 Qux 10 8 Bar9 10 9 Bar10 10
(The values Bar9 and Bar10 represent NBuilder 's default naming scheme)
Is there a βbuilt-inβ way to achieve this with AutoFixture ? Or an idiomatic way to tune the device this way?
source share