Skip to content

Commit 67e81a8

Browse files
committed
Changed the string default value supplier to use Any.StringStartingWith
1 parent 10effc7 commit 67e81a8

5 files changed

Lines changed: 22 additions & 9 deletions

File tree

NTestDataBuilder.Tests/TestHelpers/StaticAnonymousValueSupplier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public bool CanSupplyValue<TObject, TValue>(string propertyName)
1414
return typeof(TValue) == _valueToSupply.GetType();
1515
}
1616

17-
public TValue GenerateAnonymousValue<TObject, TValue>(AnonymousValueFixture fixture, string propertyName)
17+
public TValue GenerateAnonymousValue<TObject, TValue>(AnonymousValueFixture any, string propertyName)
1818
{
1919
return (TValue) _valueToSupply;
2020
}

NTestDataBuilder/EquivalenceClasses/StringEquivalenceClasses.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,16 @@ public static string String(this AnonymousValueFixture fixture)
1616
{
1717
return fixture.Fixture.Create<string>();
1818
}
19+
20+
/// <summary>
21+
/// Generate and return a string starting with the given prefix.
22+
/// </summary>
23+
/// <param name="fixture">The fixture to generate a string for</param>
24+
/// <param name="prefix">String to prefix the returned anonymous string with</param>
25+
/// <returns>The generated string</returns>
26+
public static string StringStartingWith(this AnonymousValueFixture fixture, string prefix)
27+
{
28+
return fixture.Fixture.Create(prefix);
29+
}
1930
}
2031
}

NTestDataBuilder/IAnonymousValueSupplier.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public interface IAnonymousValueSupplier
1919
/// </summary>
2020
/// <typeparam name="TObject">The type that the property is enclosed in</typeparam>
2121
/// <typeparam name="TValue">The type of the target property - the required anonymous value is of this type</typeparam>
22-
/// <param name="fixture"></param>
23-
/// <param name="propertyName"></param>
24-
/// <returns></returns>
25-
TValue GenerateAnonymousValue<TObject, TValue>(AnonymousValueFixture fixture, string propertyName);
22+
/// <param name="any">Anonymous value fixture</param>
23+
/// <param name="propertyName">The name of the property to return an anonymous value for</param>
24+
/// <returns>The anonymous value</returns>
25+
TValue GenerateAnonymousValue<TObject, TValue>(AnonymousValueFixture any, string propertyName);
2626
}
2727
}

NTestDataBuilder/Suppliers/DefaultStringValueSupplier.cs

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

35
namespace NTestDataBuilder.Suppliers
46
{
@@ -14,9 +16,9 @@ public bool CanSupplyValue<TObject, TValue>(string propertyName)
1416
}
1517

1618
/// <inheritdoc />
17-
public TValue GenerateAnonymousValue<TObject, TValue>(AnonymousValueFixture fixture, string propertyName)
19+
public TValue GenerateAnonymousValue<TObject, TValue>(AnonymousValueFixture any, string propertyName)
1820
{
19-
return (TValue) (object) fixture.Fixture.Create(propertyName);
21+
return (TValue) (object) any.StringStartingWith(propertyName);
2022
}
2123
}
2224
}

NTestDataBuilder/Suppliers/DefaultValueSupplier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public bool CanSupplyValue<TObject, TValue>(string propertyName)
1212
}
1313

1414
/// <inheritdoc />
15-
public TValue GenerateAnonymousValue<TObject, TValue>(AnonymousValueFixture fixture, string propertyName)
15+
public TValue GenerateAnonymousValue<TObject, TValue>(AnonymousValueFixture any, string propertyName)
1616
{
1717
return default(TValue);
1818
}

0 commit comments

Comments
 (0)