Skip to content

Commit cc2e92b

Browse files
committed
added the 8 additional person data sources
1 parent 92fb2cd commit cc2e92b

24 files changed

Lines changed: 487 additions & 184 deletions

NTestDataBuilder.Tests/DataSources/DataSourceTests.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void WhenGeneratingValuesFromDefaultDataSource_ThenShouldGenerateRandomIt
3434
var sut = new DummyDataSource();
3535

3636
var results = new List<string>();
37-
for (int i = 0; i < 10; i++)
37+
for (int i = 0; i < 20; i++)
3838
{
3939
results.Add(sut.Next());
4040
}
@@ -66,14 +66,6 @@ public void WhenGeneratingValuesFromUniqueSequentialDataSource_ThenShouldThrowWh
6666
sut.Next().ShouldBe(sut.List[2]);
6767
Should.Throw<InvalidOperationException>(() => sut.Next());
6868
}
69-
70-
[Fact]
71-
public void WhenGeneratingValuesFromPersonDataSource_ThenShouldHave500Records()
72-
{
73-
new FirstNameSource().List.Count.ShouldBe(500);
74-
new LastNameSource().List.Count.ShouldBe(500);
75-
new FullNameSource().List.Count.ShouldBe(500);
76-
}
7769
}
7870

7971
public class DummyDataSource : DataSource<string>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using NTestDataBuilder.DataSources;
4+
using Shouldly;
5+
using Xunit.Extensions;
6+
7+
namespace NTestDataBuilder.Tests.DataSources
8+
{
9+
public class PersonSourceTests
10+
{
11+
[Theory]
12+
[PropertyData("TestCases")]
13+
public void PersonSourceSpec(DataSource<string> sut, int expectedCount)
14+
{
15+
var collection = sut.List.ToList();
16+
collection.Count.ShouldBe(expectedCount);
17+
collection.Count.ShouldBe(sut.List.Distinct().ToList().Count);
18+
collection.ForEach(item => item.ShouldNotBeNullOrEmpty());
19+
}
20+
21+
public static IEnumerable<object[]> TestCases
22+
{
23+
get
24+
{
25+
yield return new object[] { new FirstNameSource(), 479 };
26+
yield return new object[] { new LastNameSource(), 498 };
27+
yield return new object[] { new FullNameSource(), 500 };
28+
yield return new object[] { new CompanySource(), 496 };
29+
yield return new object[] { new StreetSource(), 498 };
30+
yield return new object[] { new CitySource(), 483 };
31+
yield return new object[] { new CountySource(), 214 };
32+
yield return new object[] { new PostCodeSource(), 433 };
33+
yield return new object[] { new PhoneSource(), 500 };
34+
yield return new object[] { new EmailSource(), 500 };
35+
yield return new object[] { new WebsiteSource(), 498 };
36+
37+
}
38+
}
39+
}
40+
}

NTestDataBuilder.Tests/EquivalenceClasses/CompanyEquivalenceClassTests.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using NTestDataBuilder.DataSources;
5+
using NTestDataBuilder.EquivalenceClasses;
6+
using Shouldly;
7+
using Xunit.Extensions;
8+
9+
namespace NTestDataBuilder.Tests.EquivalenceClasses
10+
{
11+
public class PersonEquivalenceClassesTests
12+
{
13+
public static AnonymousValueFixture Any { get; private set; }
14+
15+
public PersonEquivalenceClassesTests()
16+
{
17+
Any = new AnonymousValueFixture();
18+
}
19+
20+
[Theory]
21+
[PropertyData("TestCases")]
22+
public void WhenGettingAnyPersonData_ThenReturnRandomPersonDataWhichIsReasonablyUnique(DataSource<string> source,
23+
List<string> testCases)
24+
{
25+
foreach (var testCase in testCases)
26+
{
27+
testCase.ShouldBeOfType<string>();
28+
testCase.ShouldNotBeNullOrEmpty();
29+
source.List.ShouldContain(testCase);
30+
}
31+
var unique = testCases.Distinct().Count();
32+
unique.ShouldBeGreaterThan(5);
33+
}
34+
35+
public static IEnumerable<object[]> TestCases
36+
{
37+
get
38+
{
39+
yield return new object[] { new FirstNameSource(), GenerateTestCasesForSut(Any.FirstName) };
40+
yield return new object[] { new LastNameSource(), GenerateTestCasesForSut(Any.LastName) };
41+
yield return new object[] { new FullNameSource(), GenerateTestCasesForSut(Any.FullName) };
42+
yield return new object[] { new CompanySource(), GenerateTestCasesForSut(Any.Company) };
43+
yield return new object[] { new StreetSource(), GenerateTestCasesForSut(Any.Street) };
44+
yield return new object[] { new CitySource(), GenerateTestCasesForSut(Any.City) };
45+
yield return new object[] { new CountySource(), GenerateTestCasesForSut(Any.County) };
46+
yield return new object[] { new PostCodeSource(), GenerateTestCasesForSut(Any.PostCode) };
47+
yield return new object[] { new PhoneSource(), GenerateTestCasesForSut(Any.Phone) };
48+
yield return new object[] { new EmailSource(), GenerateTestCasesForSut(Any.Email) };
49+
yield return new object[] { new WebsiteSource(), GenerateTestCasesForSut(Any.Website) };
50+
}
51+
}
52+
53+
private static List<string> GenerateTestCasesForSut(Func<string> any)
54+
{
55+
var results = new List<string>();
56+
for (int i = 0; i < 10; i++)
57+
{
58+
results.Add(any());
59+
}
60+
return results;
61+
}
62+
}
63+
}

NTestDataBuilder.Tests/NTestDataBuilder.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
<Compile Include="DataSources\DataSourceTests.cs" />
5656
<Compile Include="DataSources\Generators\RandomGeneratorTests.cs" />
5757
<Compile Include="DataSources\Generators\SequentiaGeneratorTests.cs" />
58-
<Compile Include="EquivalenceClasses\CompanyEquivalenceClassTests.cs" />
58+
<Compile Include="DataSources\PersonSourceTests.cs" />
59+
<Compile Include="EquivalenceClasses\PersonEquivalenceClassesTests.cs" />
5960
<Compile Include="EquivalenceClasses\StringEquivalenceClassesTests.cs" />
6061
<Compile Include="AsProxyTests.cs" />
6162
<Compile Include="BuildListTests.cs" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using NTestDataBuilder.DataSources.FileData;
4+
using NTestDataBuilder.DataSources.Generators;
5+
6+
namespace NTestDataBuilder.DataSources
7+
{
8+
/// <summary>
9+
/// Free sample data for testing obtained from http://www.briandunning.com/sample-data/
10+
/// </summary>
11+
public class CitySource : DataSource<string>
12+
{
13+
/// <inheritdoc />
14+
public CitySource()
15+
: base() { }
16+
17+
/// <inheritdoc />
18+
public CitySource(IGenerator generator)
19+
: base(generator) { }
20+
21+
/// <inheritdoc />
22+
protected override IList<string> InitializeList()
23+
{
24+
return FileDataRepository.People
25+
.Select(person => person.City)
26+
.Distinct()
27+
.ToList();
28+
}
29+
}
30+
}
Lines changed: 12 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,30 @@
11
using System.Collections.Generic;
2+
using System.Linq;
3+
using NTestDataBuilder.DataSources.FileData;
24
using NTestDataBuilder.DataSources.Generators;
35

46
namespace NTestDataBuilder.DataSources
57
{
8+
/// <summary>
9+
/// Free sample data for testing obtained from http://www.briandunning.com/sample-data/
10+
/// </summary>
611
public class CompanySource : DataSource<string>
712
{
13+
/// <inheritdoc />
814
public CompanySource()
915
: base() { }
1016

17+
/// <inheritdoc />
1118
public CompanySource(IGenerator generator)
1219
: base(generator) { }
1320

21+
/// <inheritdoc />
1422
protected override IList<string> InitializeList()
1523
{
16-
return new List<string>
17-
{
18-
"Wal-Mart Stores",
19-
"Exxon Mobil",
20-
"Chevron",
21-
"Phillips ",
22-
"Berkshire Hathaway",
23-
"Apple",
24-
"General Motors",
25-
"General Electric",
26-
"Valero Energy",
27-
"Ford Motor",
28-
"AT&T",
29-
"Fannie Mae",
30-
"CVS Caremark",
31-
"McKesson",
32-
"Hewlett-Packard",
33-
"Verizon Communications",
34-
"UnitedHealth Group",
35-
"J.P. Morgan Chase & Co.",
36-
"Cardinal Health",
37-
"International Business Machines",
38-
"Bank of America Corp.",
39-
"Costco Wholesale",
40-
"Kroger",
41-
"Express Scripts Holding",
42-
"Wells Fargo",
43-
"Citigroup",
44-
"Archer Daniels Midland",
45-
"Procter & Gamble",
46-
"Prudential Financial",
47-
"Boeing",
48-
"Freddie Mac",
49-
"AmerisourceBergen",
50-
"Marathon Petroleum",
51-
"Home Depot",
52-
"Microsoft",
53-
"Target",
54-
"Walgreen",
55-
"American International Group",
56-
"INTL FCStone",
57-
"MetLife",
58-
"Johnson & Johnson",
59-
"Caterpillar",
60-
"PepsiCo",
61-
"State Farm Insurance Cos.",
62-
"ConocoPhillips",
63-
"Comcast",
64-
"WellPoint",
65-
"Pfizer",
66-
"Amazon.com",
67-
"United Technologies",
68-
"Dell",
69-
"Dow Chemical",
70-
"United Parcel Service",
71-
"Intel",
72-
"Google",
73-
"Lowe's",
74-
"Coca-Cola",
75-
"Merck",
76-
"Lockheed Martin",
77-
"Cisco Systems",
78-
"Best Buy",
79-
"Safeway",
80-
"FedEx",
81-
"Enterprise Products Partners",
82-
"Sysco",
83-
"Walt Disney",
84-
"Johnson Controls",
85-
"Goldman Sachs Group",
86-
"CHS",
87-
"Abbott Laboratories",
88-
"Sears Holdings",
89-
"DuPont",
90-
"Humana",
91-
"World Fuel Services",
92-
"Hess",
93-
"Ingram Micro",
94-
"Plains All American Pipeline",
95-
"Honeywell International",
96-
"United Continental Holdings",
97-
"Oracle",
98-
"Liberty Mutual Insurance Group",
99-
"HCA Holdings",
100-
"Delta Air Lines",
101-
"Aetna",
102-
"Deere",
103-
"Supervalu",
104-
"Sprint Nextel",
105-
"Mondelēz International",
106-
"New York Life Insurance",
107-
"American Express",
108-
"News Corp.",
109-
"Allstate",
110-
"Tyson Foods",
111-
"Massachusetts Mutual Life Insurance",
112-
"Tesoro",
113-
"Morgan Stanley",
114-
"TIAA-CREF",
115-
"General Dynamics",
116-
"Philip Morris International",
117-
"Nationwide"
118-
};
24+
return FileDataRepository.People
25+
.Select(person => person.CompanyName)
26+
.Distinct()
27+
.ToList();
11928
}
12029
}
12130
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using NTestDataBuilder.DataSources.FileData;
4+
using NTestDataBuilder.DataSources.Generators;
5+
6+
namespace NTestDataBuilder.DataSources
7+
{
8+
/// <summary>
9+
/// Free sample data for testing obtained from http://www.briandunning.com/sample-data/
10+
/// </summary>
11+
public class CountySource : DataSource<string>
12+
{
13+
/// <inheritdoc />
14+
public CountySource()
15+
: base() { }
16+
17+
/// <inheritdoc />
18+
public CountySource(IGenerator generator)
19+
: base(generator) { }
20+
21+
/// <inheritdoc />
22+
protected override IList<string> InitializeList()
23+
{
24+
return FileDataRepository.People
25+
.Select(person => person.County)
26+
.Distinct()
27+
.ToList();
28+
}
29+
}
30+
}

NTestDataBuilder/DataSources/DataSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace NTestDataBuilder.DataSources
77
/// The base class for data sources to inherit from.
88
/// </summary>
99
/// <typeparam name="T"></typeparam>
10-
public abstract class DataSource<T>
10+
public abstract class DataSource<T> : IDataSource<T>
1111
{
1212
/// <summary>
1313
/// Allows a custom data generation strategy to be passed to the data source

0 commit comments

Comments
 (0)