Skip to content

Commit fc47c51

Browse files
committed
Added IsListBuilderProxy method to the builder base class
1 parent 95dc44a commit fc47c51

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

NTestDataBuilder.Tests/BuildListTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ namespace NTestDataBuilder.Tests
1111
{
1212
public class BuildListTests
1313
{
14+
[Fact]
15+
public void GivenANormalBuilderInstance_WhenCallingIsListBuilderProxy_ThenReturnFalse()
16+
{
17+
var builder = new BasicCustomerBuilder();
18+
19+
builder.IsListBuilderProxy().ShouldBe(false);
20+
}
21+
22+
[Fact]
23+
public void GivenAListBuilderProxyInstance_WhenCallingIsListBuilderProxy_ThenReturnTrue()
24+
{
25+
var builder = BasicCustomerBuilder.CreateListOfSize(1).TheFirst(1);
26+
27+
builder.IsListBuilderProxy().ShouldBe(true);
28+
}
29+
1430
[Fact]
1531
public void GivenListOfBuilders_WhenCallingBuildList_ThenAListOfEntitiesOfTheRightSizeShouldBeReturned()
1632
{

NTestDataBuilder/Lists/ListBuilderInterceptor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public ListBuilderInterceptor(ListBuilder<TObject, TBuilder> builder)
1616

1717
public void Intercept(IInvocation invocation)
1818
{
19+
if (invocation.Method.Name == "IsListBuilderProxy")
20+
{
21+
invocation.Proceed();
22+
return;
23+
}
24+
1925
if (invocation.Method.ReturnType != typeof (TBuilder))
2026
{
2127
throw new InvalidOperationException("Non-fluent builder method invoked while creating a list of builders: " + invocation.Method.Name);

NTestDataBuilder/TestDataBuilder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,14 @@ protected bool Has<TValue>(Expression<Func<TObject, TValue>> property)
134134
{
135135
return _properties.ContainsKey(PropertyNameGetter.Get(property));
136136
}
137+
138+
/// <summary>
139+
/// Returns whether or not the builder instance is a proxy for building a list or an actual builder instance.
140+
/// </summary>
141+
/// <returns>Whether or not the instance is a list builder proxy</returns>
142+
public virtual bool IsListBuilderProxy()
143+
{
144+
return ListBuilder != null;
145+
}
137146
}
138147
}

0 commit comments

Comments
 (0)