Skip to content

Commit 8a65799

Browse files
committed
Moving test around and added tests for string equivalence classes
1 parent 51615ff commit 8a65799

4 files changed

Lines changed: 58 additions & 27 deletions

File tree

NTestDataBuilder.Tests/AnyTests.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using NTestDataBuilder.EquivalenceClasses;
2+
using NUnit.Framework;
3+
using Shouldly;
4+
5+
namespace NTestDataBuilder.Tests.EquivalenceClasses
6+
{
7+
public class StringEquivalenceClassesTests
8+
{
9+
public AnonymousValueFixture Any { get; private set; }
10+
11+
[SetUp]
12+
public void Setup()
13+
{
14+
Any = new AnonymousValueFixture();
15+
}
16+
17+
[Test]
18+
public void WhenGettingAnyString_ThenReturnDifferentNonEmptyStringsEveryTime()
19+
{
20+
var s1 = Any.String();
21+
var s2 = Any.String();
22+
23+
s1.ShouldBeOfType<string>();
24+
s2.ShouldBeOfType<string>();
25+
s1.ShouldNotBeNullOrEmpty();
26+
s2.ShouldNotBeNullOrEmpty();
27+
s1.ShouldNotBe(s2);
28+
}
29+
30+
[Test]
31+
public void WhenGettingAnyStringStartingWithSomething_ThenReturnDifferentStringsStartingWithThatStringEveryTime()
32+
{
33+
var s1 = Any.StringStartingWith("St4rt");
34+
var s2 = Any.StringStartingWith("St4rt");
35+
var s3 = Any.StringStartingWith("Something Else");
36+
37+
s1.ShouldNotBe(s2);
38+
s1.ShouldNotBe(s3);
39+
s2.ShouldNotBe(s3);
40+
s1.ShouldStartWith("St4rt");
41+
s2.ShouldStartWith("St4rt");
42+
s3.ShouldStartWith("Something Else");
43+
}
44+
}
45+
}

NTestDataBuilder.Tests/NTestDataBuilder.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<Reference Include="Microsoft.CSharp" />
5050
</ItemGroup>
5151
<ItemGroup>
52-
<Compile Include="AnyTests.cs" />
52+
<Compile Include="EquivalenceClasses\StringEquivalenceClassesTests.cs" />
5353
<Compile Include="AsProxyTests.cs" />
5454
<Compile Include="BuildListTests.cs" />
5555
<Compile Include="Builders\BasicCustomerBuilder.cs" />
@@ -76,6 +76,7 @@
7676
<Name>NTestDataBuilder</Name>
7777
</ProjectReference>
7878
</ItemGroup>
79+
<ItemGroup />
7980
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8081
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
8182
Other similar extension points exist, see Microsoft.Common.targets.

NTestDataBuilder/EquivalenceClasses/StringEquivalenceClasses.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,16 @@ public static string StringStartingWith(this AnonymousValueFixture fixture, stri
2727
{
2828
return fixture.Fixture.Create(prefix);
2929
}
30+
31+
/// <summary>
32+
/// Generate and return a string ending with the given suffix.
33+
/// </summary>
34+
/// <param name="fixture">The fixture to generate a string for</param>
35+
/// <param name="suffix">String to end the returned anonymous string with</param>
36+
/// <returns>The generated string</returns>
37+
public static string StringEndingWith(this AnonymousValueFixture fixture, string suffix)
38+
{
39+
return string.Format("{0}{1}", fixture.Fixture.Create<string>(), suffix);
40+
}
3041
}
3142
}

0 commit comments

Comments
 (0)