Skip to content

Commit 8310b7f

Browse files
committed
Merge pull request #50 from mwhelan/any-api
Major improvements to the Words functionality
2 parents a6ffe80 + 799b336 commit 8310b7f

File tree

68 files changed

+2440
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2440
-317
lines changed

BREAKING_CHANGES.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
Breaking Changes
22
================
33

4+
Version 3.3
5+
-----------
6+
The classes inheriting from `FileDictionarySource` have been marked as obsolete and will be removed in version 4. Instead you should use the new `Words` class, passing in the name of a file dictionary (either one of the built-in ones or one that you create). All the built-in ones are listed in the FromDictionary class where the constants match the filename embedded into Dossier. So, for example, instead of using the `GeoCountrySource` class you would instead use `Words(FromDictionary.GeoCountry)`.
7+
8+
All of the file dictionaries have been added to the AnonymousValueFixture class as equivalence class extension methods. So, for example, in your builder class you can now call:
9+
10+
```c#
11+
Any.InternetURL();
12+
Any.LoremIpsum();
13+
Any.ColourName();
14+
```
15+
16+
Picking functionality has been added which allows you to select items from a list according to different strategies. Currently, two strategies have been added, `RandomItemFrom` and `RepeatingSequenceFrom`:
17+
18+
```c#
19+
var names = new Words(FromDictionary.PersonNameFirst).Data;
20+
var days = new List<string> {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
21+
var customers = Builder<Customer>
22+
.CreateListOfSize(15)
23+
.All()
24+
.Set(x => x.Name, Pick.RandomItemFrom(names).Next)
25+
.Set(x => x.Day, Pick.RepeatingSequenceFrom(days).Next)
26+
.BuildList();
27+
```
28+
429
Version 3.0
530
-----------
631

TestStack.Dossier.Tests/DataSources/DataSourceConventionTests.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
using System.Linq;
33
using Shouldly;
44
using TestStack.Dossier.DataSources;
5-
using TestStack.Dossier.DataSources.Geography;
6-
using TestStack.Dossier.DataSources.Person;
7-
using Xunit;
5+
using TestStack.Dossier.DataSources.Dictionaries;
86
using Xunit.Extensions;
97

108
namespace TestStack.Dossier.Tests.DataSources
@@ -25,21 +23,21 @@ public static IEnumerable<object[]> TestCases
2523
{
2624
get
2725
{
28-
yield return new object[] { new GeoContinentSource(), 7 };
29-
yield return new object[] { new GeoCountrySource(), 249 };
30-
yield return new object[] { new GeoCountryCodeSource(), 64 };
31-
yield return new object[] { new GeoLatitudeSource(), 1000 };
32-
yield return new object[] { new GeoLongitudeSource(), 1000 };
26+
yield return new object[] { new Words(FromDictionary.GeoContinent), 7 };
27+
yield return new object[] { new Words(FromDictionary.GeoCountry), 249 };
28+
yield return new object[] { new Words(FromDictionary.GeoCountryCode), 64 };
29+
yield return new object[] { new Words(FromDictionary.GeoLatitude), 1000 };
30+
yield return new object[] { new Words(FromDictionary.GeoLongitude), 1000 };
3331

34-
yield return new object[] { new PersonEmailAddressSource(), 1000 };
35-
yield return new object[] { new PersonLanguageSource(), 97 };
36-
yield return new object[] { new PersonNameFirstFemaleSource(), 100 };
37-
yield return new object[] { new PersonNameFirstSource(), 479 };
38-
yield return new object[] { new PersonNameFullSource(), 1000 };
39-
yield return new object[] { new PersonNameLastSource(), 747 };
40-
yield return new object[] { new PersonNameFirstMaleSource(), 100 };
41-
yield return new object[] { new PersonNameSuffixSource(), 5 };
42-
yield return new object[] { new PersonNameTitleSource(), 9 };
32+
yield return new object[] { new Words(FromDictionary.PersonEmailAddress), 1000 };
33+
yield return new object[] { new Words(FromDictionary.PersonLanguage), 97 };
34+
yield return new object[] { new Words(FromDictionary.PersonNameFirstFemale), 100 };
35+
yield return new object[] { new Words(FromDictionary.PersonNameFirst), 479 };
36+
yield return new object[] { new Words(FromDictionary.PersonNameFull), 1000 };
37+
yield return new object[] { new Words(FromDictionary.PersonNameLast), 747 };
38+
yield return new object[] { new Words(FromDictionary.PersonNameFirstMale), 100 };
39+
yield return new object[] { new Words(FromDictionary.PersonNameSuffix), 5 };
40+
yield return new object[] { new Words(FromDictionary.PersonNameTitle), 9 };
4341
}
4442
}
4543
}

TestStack.Dossier.Tests/DataSources/Dictionaries/CacheTests.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

TestStack.Dossier.Tests/DataSources/Dictionaries/FileDictionaryRepositoryIntegrationTests.cs renamed to TestStack.Dossier.Tests/DataSources/Dictionaries/CachedFileDictionaryRepositoryIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace TestStack.Dossier.Tests.DataSources.Dictionaries
77
{
8-
public class FileDictionaryRepositoryIntegrationTests
8+
public class CachedFileDictionaryRepositoryIntegrationTests
99
{
1010
[Fact]
1111
public void GivenAnExternalFileDictionaryExists_WhenRetrievingWords_ThenExternalDictionaryIsUsed()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.IO;
3+
using Shouldly;
4+
using TestStack.Dossier.DataSources.Dictionaries;
5+
using Xunit;
6+
7+
namespace TestStack.Dossier.Tests.DataSources.Dictionaries
8+
{
9+
public class WordsCacheTests : IDisposable
10+
{
11+
private const string DictionaryThatDoesNotExist = "DictionaryThatDoesNotExist";
12+
13+
public WordsCacheTests()
14+
{
15+
WordsCache.Clear();
16+
}
17+
18+
[Fact]
19+
public void WhenRequestingAnItemInTheCache_ThenReturnsSameItem()
20+
{
21+
var words1 = WordsCache.Get(FromDictionary.InternetUrl);
22+
var words2 = WordsCache.Get(FromDictionary.InternetUrl);
23+
words1.ShouldBeSameAs(words2);
24+
}
25+
26+
[Fact]
27+
public void WhenRequestingAnItemNotInTheCache_ThenReturnsWordsSourceForItemDictionary()
28+
{
29+
var words = WordsCache.Get(DictionaryThatDoesNotExist);
30+
words.DictionaryName.ShouldBe(DictionaryThatDoesNotExist);
31+
}
32+
33+
[Fact]
34+
public void WhenUsingCachedWordsForNonExistentDictionary_ThenWordsSourceThrowsFileNotFoundException()
35+
{
36+
var words = WordsCache.Get(DictionaryThatDoesNotExist);
37+
Should.Throw<FileNotFoundException>(() => words.Next());
38+
}
39+
40+
public void Dispose()
41+
{
42+
WordsCache.Clear();
43+
}
44+
}
45+
}

TestStack.Dossier.Tests/DataSources/Dictionaries/FileDictionarySourceTests.cs renamed to TestStack.Dossier.Tests/DataSources/Dictionaries/WordsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace TestStack.Dossier.Tests.DataSources.Dictionaries
77
{
8-
public class FileDictionarySourceTests
8+
public class WordsTests
99
{
1010
[Fact]
1111
public void WhenInitializingList_ThenPassClassNameToRepositoryAsDictionaryName()
@@ -19,9 +19,9 @@ public void WhenInitializingList_ThenPassClassNameToRepositoryAsDictionaryName()
1919
}
2020
}
2121

22-
public class DummySource : FileDictionarySource
22+
public class DummySource : Words
2323
{
2424
internal DummySource(IDictionaryRepository repository)
25-
: base(Substitute.For<IGenerator>(), repository) { }
25+
: base(Substitute.For<IGenerator>(), repository, "Dummy") { }
2626
}
2727
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Collections.Generic;
2+
using TestStack.Dossier.DataSources;
3+
using TestStack.Dossier.DataSources.Dictionaries;
4+
using Xunit.Extensions;
5+
6+
namespace TestStack.Dossier.Tests.EquivalenceClasses
7+
{
8+
public class AddressAusEquivalenceTests : FileDictionaryEquivalenceTests
9+
{
10+
[Theory]
11+
[ClassData(typeof(AddressAusTestCases))]
12+
public override void WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(DataSource<string> source, List<string> testCases)
13+
{
14+
base.WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(source, testCases);
15+
}
16+
}
17+
18+
public class AddressAusTestCases : FileDictionaryEquivalenceTestCases
19+
{
20+
protected override List<object[]> GetData()
21+
{
22+
return new List<object[]>
23+
{
24+
new object[]
25+
{new Words(FromDictionary.AddressAusCity), GenerateTestCasesForSut(Any.AddressAusCity)},
26+
new object[]
27+
{new Words(FromDictionary.AddressAusCompany), GenerateTestCasesForSut(Any.AddressAusCompany)},
28+
new object[]
29+
{new Words(FromDictionary.AddressAusPhone), GenerateTestCasesForSut(Any.AddressAusPhone)},
30+
new object[]
31+
{new Words(FromDictionary.AddressAusPostCode), GenerateTestCasesForSut(Any.AddressAusPostCode)},
32+
new object[]
33+
{new Words(FromDictionary.AddressAusState), GenerateTestCasesForSut(Any.AddressAusState)},
34+
new object[]
35+
{
36+
new Words(FromDictionary.AddressAusStateAbbreviation),
37+
GenerateTestCasesForSut(Any.AddressAusStateAbbreviation)
38+
},
39+
new object[]
40+
{new Words(FromDictionary.AddressAusStreet), GenerateTestCasesForSut(Any.AddressAusStreet)},
41+
new object[]
42+
{new Words(FromDictionary.AddressAusWebsite), GenerateTestCasesForSut(Any.AddressAusWebsite)},
43+
};
44+
}
45+
}
46+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Collections.Generic;
2+
using TestStack.Dossier.DataSources;
3+
using TestStack.Dossier.DataSources.Dictionaries;
4+
using Xunit.Extensions;
5+
6+
namespace TestStack.Dossier.Tests.EquivalenceClasses
7+
{
8+
public class AddressUkEquivalenceClasses : FileDictionaryEquivalenceTests
9+
{
10+
[Theory]
11+
[ClassData(typeof(AddressUkTestCases))]
12+
public override void WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(DataSource<string> source, List<string> testCases)
13+
{
14+
base.WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(source, testCases);
15+
}
16+
}
17+
18+
public class AddressUkTestCases : FileDictionaryEquivalenceTestCases
19+
{
20+
protected override List<object[]> GetData()
21+
{
22+
return new List<object[]>
23+
{
24+
new object[]
25+
{new Words(FromDictionary.AddressUkCounty), GenerateTestCasesForSut(Any.AddressUkCounty)},
26+
new object[]
27+
{new Words(FromDictionary.AddressUkCity), GenerateTestCasesForSut(Any.AddressUkCity)},
28+
new object[]
29+
{new Words(FromDictionary.AddressUkCompany), GenerateTestCasesForSut(Any.AddressUkCompany)},
30+
new object[]
31+
{new Words(FromDictionary.AddressUkPhone), GenerateTestCasesForSut(Any.AddressUkPhone)},
32+
new object[]
33+
{new Words(FromDictionary.AddressUkPostCode), GenerateTestCasesForSut(Any.AddressUkPostCode)},
34+
new object[]
35+
{new Words(FromDictionary.AddressUkStreet), GenerateTestCasesForSut(Any.AddressUkStreet)},
36+
new object[]
37+
{new Words(FromDictionary.AddressUkWebsite), GenerateTestCasesForSut(Any.AddressUkWebsite)},
38+
};
39+
}
40+
}
41+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections.Generic;
2+
using TestStack.Dossier.DataSources;
3+
using TestStack.Dossier.DataSources.Dictionaries;
4+
using Xunit.Extensions;
5+
6+
namespace TestStack.Dossier.Tests.EquivalenceClasses
7+
{
8+
public class AddressUsEquivalenceTests : FileDictionaryEquivalenceTests
9+
{
10+
[Theory]
11+
[ClassData(typeof(AddressUsTestCases))]
12+
public override void WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(DataSource<string> source, List<string> testCases)
13+
{
14+
base.WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(source, testCases);
15+
}
16+
}
17+
18+
public class AddressUsTestCases : FileDictionaryEquivalenceTestCases
19+
{
20+
protected override List<object[]> GetData()
21+
{
22+
return new List<object[]>
23+
{
24+
new object[]
25+
{new Words(FromDictionary.AddressUsCity), GenerateTestCasesForSut(Any.AddressUsCity)},
26+
new object[]
27+
{new Words(FromDictionary.AddressUsCompany), GenerateTestCasesForSut(Any.AddressUsCompany)},
28+
new object[]
29+
{new Words(FromDictionary.AddressUsPhone), GenerateTestCasesForSut(Any.AddressUsPhone)},
30+
new object[]
31+
{new Words(FromDictionary.AddressUsSocialSecurityNumber), GenerateTestCasesForSut(Any.AddressUsSocialSecurityNumber)},
32+
new object[]
33+
{new Words(FromDictionary.AddressUsState), GenerateTestCasesForSut(Any.AddressUsState)},
34+
new object[]
35+
{
36+
new Words(FromDictionary.AddressUsStateAbbreviation),
37+
GenerateTestCasesForSut(Any.AddressUsStateAbbreviation)
38+
},
39+
new object[]
40+
{new Words(FromDictionary.AddressUsStreet), GenerateTestCasesForSut(Any.AddressUsStreet)},
41+
new object[]
42+
{new Words(FromDictionary.AddressUsWebsite), GenerateTestCasesForSut(Any.AddressUsWebsite)},
43+
new object[]
44+
{new Words(FromDictionary.AddressUsZipCode), GenerateTestCasesForSut(Any.AddressUsZipCode)}
45+
};
46+
}
47+
}
48+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Collections.Generic;
2+
using TestStack.Dossier.DataSources;
3+
using TestStack.Dossier.DataSources.Dictionaries;
4+
using Xunit.Extensions;
5+
6+
namespace TestStack.Dossier.Tests.EquivalenceClasses
7+
{
8+
public class ColourEquivalenceTests : FileDictionaryEquivalenceTests
9+
{
10+
[Theory]
11+
[ClassData(typeof(ColourTestCases))]
12+
public override void WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(DataSource<string> source, List<string> testCases)
13+
{
14+
base.WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(source, testCases);
15+
}
16+
}
17+
18+
public class ColourTestCases : FileDictionaryEquivalenceTestCases
19+
{
20+
protected override List<object[]> GetData()
21+
{
22+
return new List<object[]>
23+
{
24+
new object[]
25+
{new Words(FromDictionary.ColourHex), GenerateTestCasesForSut(Any.ColourHex)},
26+
new object[]
27+
{new Words(FromDictionary.ColourName), GenerateTestCasesForSut(Any.ColourName)}
28+
};
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)