Skip to content

Commit

Permalink
Merge pull request #42 from TestStack/issue-40-fix
Browse files Browse the repository at this point in the history
Issue 40 fix
  • Loading branch information
robdmoore committed Jun 18, 2015
2 parents 3d53abb + aace6e4 commit 92bf513
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
19 changes: 19 additions & 0 deletions TestStack.Dossier.Tests/BuildListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using TestStack.Dossier.Tests.TestHelpers.Objects.Entities;

namespace TestStack.Dossier.Tests.TestHelpers.Builders
{
public class BuilderWithDefaults : TestDataBuilder<Customer, BuilderWithDefaults>
{
public const string DefaultFirstName = "Joe";
public const string DefaultLastName = "Bloggs";

public BuilderWithDefaults()
{
Set(x => x.FirstName, DefaultFirstName);
Set(x => x.LastName, DefaultLastName);
}
}
}
1 change: 1 addition & 0 deletions TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Compile Include="Factories\AutoFixtureFactoryTests.cs" />
<Compile Include="Factories\CallConstructorFactoryTests.cs" />
<Compile Include="Factories\PublicPropertySettersFactoryTests.cs" />
<Compile Include="TestHelpers\Builders\BuilderWithDefaults.cs" />
<Compile Include="TestHelpers\Objects\Entities\Company.cs" />
<Compile Include="TestHelpers\Objects\Entities\Customer.cs" />
<Compile Include="TestHelpers\Objects\Entities\CustomerClass.cs" />
Expand Down
3 changes: 2 additions & 1 deletion TestStack.Dossier.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions TestStack.Dossier/Lists/ListBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ public class ListBuilder<TObject, TBuilder>
where TBuilder : TestDataBuilder<TObject, TBuilder>, new()
where TObject : class
{
private int _start = 0;
private int _count = 0;
private int _start;
private int _count;
private readonly List<TBuilder> _list;

internal ListBuilder(int size)
{
_list = new List<TBuilder>();
BuilderProxy = (TBuilder) ListBuilderGenerator.Generator
.CreateClassProxy(typeof (TBuilder), new ProxyGenerationOptions(new EnsureAllMethodsVirtual()), new ListBuilderInterceptor<TObject, TBuilder>(this));
BuilderProxy.ListBuilder = this;
_list = new List<TBuilder>();
var fixture = new AnonymousValueFixture();
for (var i = 0; i < size; i++)
_list.Add(new TBuilder {Any = fixture});
Expand Down

0 comments on commit 92bf513

Please sign in to comment.