Skip to content

Commit dbbeb4e

Browse files
committed
Merge pull request #11 from Quantumplation/FluentSet
Fluent set
2 parents a803219 + d8f9192 commit dbbeb4e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

NTestDataBuilder.Tests/BuildTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,19 @@ public void GivenBuilderWithMethodCalls_WhenCallingBuild_ThenReturnAnObjectWithT
3030
Assert.That(customer.LastName, Is.EqualTo("Kocaj"));
3131
Assert.That(customer.YearJoined, Is.EqualTo(2010));
3232
}
33+
34+
[Test]
35+
public void GivenBuilder_WhenCallingSet_ShouldOverrideValues()
36+
{
37+
var builder = new CustomerBuilder()
38+
.Set(x => x.FirstName, "Pi")
39+
.Set(x => x.LastName, "Lanningham")
40+
.Set(x => x.YearJoined, 2014);
41+
42+
var customer = builder.Build();
43+
Assert.That(customer.FirstName, Is.EqualTo("Pi"));
44+
Assert.That(customer.LastName, Is.EqualTo("Lanningham"));
45+
Assert.That(customer.YearJoined, Is.EqualTo(2014));
46+
}
3347
}
3448
}

NTestDataBuilder/TestDataBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ protected virtual void AlterProxy(TObject proxy) {}
7575
/// <typeparam name="TValue">The type of the property</typeparam>
7676
/// <param name="property">A lambda expression specifying the property to record a value for</param>
7777
/// <param name="value">The value to record</param>
78-
public void Set<TValue>(Expression<Func<TObject, TValue>> property, TValue value)
78+
public TBuilder Set<TValue>(Expression<Func<TObject, TValue>> property, TValue value)
7979
{
8080
_properties[GetPropertyName(property)] = value;
81+
return this as TBuilder;
8182
}
8283

8384
/// <summary>

0 commit comments

Comments
 (0)