diff --git a/TestStack.Dossier.Tests/BuildListTests.cs b/TestStack.Dossier.Tests/BuildListTests.cs index 5e0e15b..5c28a61 100644 --- a/TestStack.Dossier.Tests/BuildListTests.cs +++ b/TestStack.Dossier.Tests/BuildListTests.cs @@ -172,5 +172,24 @@ public void WhenBuildingEntitiesImplicitly_ThenTheAnonymousValueFixtureIsSharedA customers[3].CustomerClass.ShouldBe(CustomerClass.Gold); customers[4].CustomerClass.ShouldBe(CustomerClass.Platinum); } + + [Fact] + public void GivenBuilderWithSetCallsInConstructor_WhenBuildingAListOfTheBuilders_ThenDefaultValuesShouldBeRespectedUnlessOverridden() + { + const string overriddenFirstName = "FirstOverride"; + const string overriddenLastName = "LastOverride"; + + var customers = BuilderWithDefaults.CreateListOfSize(3) + .TheFirst(1).With(x => x.Set(y => y.FirstName, overriddenFirstName)) + .TheNext(1).With(x => x.Set(y => y.LastName, overriddenLastName)) + .BuildList(); + + customers[0].FirstName.ShouldBe(overriddenFirstName); + customers[0].LastName.ShouldBe(BuilderWithDefaults.DefaultLastName); + customers[1].FirstName.ShouldBe(BuilderWithDefaults.DefaultFirstName); + customers[1].LastName.ShouldBe(overriddenLastName); + customers[2].FirstName.ShouldBe(BuilderWithDefaults.DefaultFirstName); + customers[2].LastName.ShouldBe(BuilderWithDefaults.DefaultLastName); + } } } diff --git a/TestStack.Dossier.Tests/TestHelpers/Builders/BuilderWithDefaults.cs b/TestStack.Dossier.Tests/TestHelpers/Builders/BuilderWithDefaults.cs new file mode 100644 index 0000000..32f9bec --- /dev/null +++ b/TestStack.Dossier.Tests/TestHelpers/Builders/BuilderWithDefaults.cs @@ -0,0 +1,16 @@ +using TestStack.Dossier.Tests.TestHelpers.Objects.Entities; + +namespace TestStack.Dossier.Tests.TestHelpers.Builders +{ + public class BuilderWithDefaults : TestDataBuilder + { + public const string DefaultFirstName = "Joe"; + public const string DefaultLastName = "Bloggs"; + + public BuilderWithDefaults() + { + Set(x => x.FirstName, DefaultFirstName); + Set(x => x.LastName, DefaultLastName); + } + } +} diff --git a/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj b/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj index 380dd50..4391a4f 100644 --- a/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj +++ b/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj @@ -65,6 +65,7 @@ + diff --git a/TestStack.Dossier.sln b/TestStack.Dossier.sln index 954293b..f467254 100644 --- a/TestStack.Dossier.sln +++ b/TestStack.Dossier.sln @@ -1,11 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BC8508D1-6FCB-46B2-9C14-F41F6AD76B09}" ProjectSection(SolutionItems) = preProject BREAKING_CHANGES.md = BREAKING_CHANGES.md + CONTRIBUTING.md = CONTRIBUTING.md LICENSE = LICENSE logo.png = logo.png NextVersion.txt = NextVersion.txt diff --git a/TestStack.Dossier/Lists/ListBuilder.cs b/TestStack.Dossier/Lists/ListBuilder.cs index 370a800..595e94b 100644 --- a/TestStack.Dossier/Lists/ListBuilder.cs +++ b/TestStack.Dossier/Lists/ListBuilder.cs @@ -14,16 +14,16 @@ public class ListBuilder where TBuilder : TestDataBuilder, new() where TObject : class { - private int _start = 0; - private int _count = 0; + private int _start; + private int _count; private readonly List _list; internal ListBuilder(int size) { + _list = new List(); BuilderProxy = (TBuilder) ListBuilderGenerator.Generator .CreateClassProxy(typeof (TBuilder), new ProxyGenerationOptions(new EnsureAllMethodsVirtual()), new ListBuilderInterceptor(this)); BuilderProxy.ListBuilder = this; - _list = new List(); var fixture = new AnonymousValueFixture(); for (var i = 0; i < size; i++) _list.Add(new TBuilder {Any = fixture});