Skip to content

Commit 8ff41fb

Browse files
committed
Added default value supplier for value types
1 parent 67e81a8 commit 8ff41fb

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

NTestDataBuilder.Tests/GetAnonymousTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ public void GivenNoValueHasBeenSetForAStringProperty_WhenRetrievingTheValueForTh
5454
}
5555

5656
[Test]
57-
public void GivenNoValueHasBeenSetForAnIntProperty_WhenRetrievingTheValueForThatProperty_ThenReturnDefaultValue()
57+
public void GivenNoValueHasBeenSetForAnIntProperty_WhenRetrievingTheValueForThatProperty_ThenReturnAnonymousInteger()
5858
{
59-
Assert.That(_b.Get(x => x.YearJoined), Is.EqualTo(default(int)));
59+
var val1 = _b.Get(x => x.YearJoined);
60+
var val2 = _b.Get(x => x.YearJoined);
61+
62+
Assert.That(val1, Is.Not.EqualTo(val2));
6063
}
6164
}
6265
}

NTestDataBuilder/AnonymousValueFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static AnonymousValueFixture()
2020
DefaultValueSuppliers = new IAnonymousValueSupplier[]
2121
{
2222
new DefaultStringValueSupplier(),
23+
new DefaultValueTypeValueSupplier(),
2324
new DefaultValueSupplier()
2425
};
2526
}

NTestDataBuilder/NTestDataBuilder.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<Compile Include="PropertyNameGetter.cs" />
5555
<Compile Include="Suppliers\DefaultValueSupplier.cs" />
5656
<Compile Include="Suppliers\DefaultStringValueSupplier.cs" />
57+
<Compile Include="Suppliers\DefaultValueTypeValueSupplier.cs" />
5758
<Compile Include="TestDataBuilder.cs" />
5859
<Compile Include="TestDataBuilderExtensions.cs" />
5960
<Compile Include="Properties\AssemblyInfo.cs" />

NTestDataBuilder/Suppliers/DefaultStringValueSupplier.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using NSubstitute.Core.Arguments;
2-
using NTestDataBuilder.EquivalenceClasses;
3-
using Ploeh.AutoFixture;
1+
using NTestDataBuilder.EquivalenceClasses;
42

53
namespace NTestDataBuilder.Suppliers
64
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Ploeh.AutoFixture;
2+
3+
namespace NTestDataBuilder.Suppliers
4+
{
5+
/// <summary>
6+
/// Supplies default anonymous value for a value type e.g. int, double, etc.
7+
/// </summary>
8+
public class DefaultValueTypeValueSupplier : IAnonymousValueSupplier
9+
{
10+
public bool CanSupplyValue<TObject, TValue>(string propertyName)
11+
{
12+
return typeof (TValue).IsValueType;
13+
}
14+
15+
public TValue GenerateAnonymousValue<TObject, TValue>(AnonymousValueFixture any, string propertyName)
16+
{
17+
return any.Fixture.Create<TValue>();
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)