Skip to content

Major improvements to the Words functionality #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
Breaking Changes
================

Version 3.3
-----------
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)`.

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:

```c#
Any.InternetURL();
Any.LoremIpsum();
Any.ColourName();
```

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`:

```c#
var names = new Words(FromDictionary.PersonNameFirst).Data;
var days = new List<string> {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
var customers = Builder<Customer>
.CreateListOfSize(15)
.All()
.Set(x => x.Name, Pick.RandomItemFrom(names).Next)
.Set(x => x.Day, Pick.RepeatingSequenceFrom(days).Next)
.BuildList();
```

Version 3.0
-----------

Expand Down
32 changes: 15 additions & 17 deletions TestStack.Dossier.Tests/DataSources/DataSourceConventionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using System.Linq;
using Shouldly;
using TestStack.Dossier.DataSources;
using TestStack.Dossier.DataSources.Geography;
using TestStack.Dossier.DataSources.Person;
using Xunit;
using TestStack.Dossier.DataSources.Dictionaries;
using Xunit.Extensions;

namespace TestStack.Dossier.Tests.DataSources
Expand All @@ -25,21 +23,21 @@ public static IEnumerable<object[]> TestCases
{
get
{
yield return new object[] { new GeoContinentSource(), 7 };
yield return new object[] { new GeoCountrySource(), 249 };
yield return new object[] { new GeoCountryCodeSource(), 64 };
yield return new object[] { new GeoLatitudeSource(), 1000 };
yield return new object[] { new GeoLongitudeSource(), 1000 };
yield return new object[] { new Words(FromDictionary.GeoContinent), 7 };
yield return new object[] { new Words(FromDictionary.GeoCountry), 249 };
yield return new object[] { new Words(FromDictionary.GeoCountryCode), 64 };
yield return new object[] { new Words(FromDictionary.GeoLatitude), 1000 };
yield return new object[] { new Words(FromDictionary.GeoLongitude), 1000 };

yield return new object[] { new PersonEmailAddressSource(), 1000 };
yield return new object[] { new PersonLanguageSource(), 97 };
yield return new object[] { new PersonNameFirstFemaleSource(), 100 };
yield return new object[] { new PersonNameFirstSource(), 479 };
yield return new object[] { new PersonNameFullSource(), 1000 };
yield return new object[] { new PersonNameLastSource(), 747 };
yield return new object[] { new PersonNameFirstMaleSource(), 100 };
yield return new object[] { new PersonNameSuffixSource(), 5 };
yield return new object[] { new PersonNameTitleSource(), 9 };
yield return new object[] { new Words(FromDictionary.PersonEmailAddress), 1000 };
yield return new object[] { new Words(FromDictionary.PersonLanguage), 97 };
yield return new object[] { new Words(FromDictionary.PersonNameFirstFemale), 100 };
yield return new object[] { new Words(FromDictionary.PersonNameFirst), 479 };
yield return new object[] { new Words(FromDictionary.PersonNameFull), 1000 };
yield return new object[] { new Words(FromDictionary.PersonNameLast), 747 };
yield return new object[] { new Words(FromDictionary.PersonNameFirstMale), 100 };
yield return new object[] { new Words(FromDictionary.PersonNameSuffix), 5 };
yield return new object[] { new Words(FromDictionary.PersonNameTitle), 9 };
}
}
}
Expand Down
62 changes: 0 additions & 62 deletions TestStack.Dossier.Tests/DataSources/Dictionaries/CacheTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace TestStack.Dossier.Tests.DataSources.Dictionaries
{
public class FileDictionaryRepositoryIntegrationTests
public class CachedFileDictionaryRepositoryIntegrationTests
{
[Fact]
public void GivenAnExternalFileDictionaryExists_WhenRetrievingWords_ThenExternalDictionaryIsUsed()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.IO;
using Shouldly;
using TestStack.Dossier.DataSources.Dictionaries;
using Xunit;

namespace TestStack.Dossier.Tests.DataSources.Dictionaries
{
public class WordsCacheTests : IDisposable
{
private const string DictionaryThatDoesNotExist = "DictionaryThatDoesNotExist";

public WordsCacheTests()
{
WordsCache.Clear();
}

[Fact]
public void WhenRequestingAnItemInTheCache_ThenReturnsSameItem()
{
var words1 = WordsCache.Get(FromDictionary.InternetUrl);
var words2 = WordsCache.Get(FromDictionary.InternetUrl);
words1.ShouldBeSameAs(words2);
}

[Fact]
public void WhenRequestingAnItemNotInTheCache_ThenReturnsWordsSourceForItemDictionary()
{
var words = WordsCache.Get(DictionaryThatDoesNotExist);
words.DictionaryName.ShouldBe(DictionaryThatDoesNotExist);
}

[Fact]
public void WhenUsingCachedWordsForNonExistentDictionary_ThenWordsSourceThrowsFileNotFoundException()
{
var words = WordsCache.Get(DictionaryThatDoesNotExist);
Should.Throw<FileNotFoundException>(() => words.Next());
}

public void Dispose()
{
WordsCache.Clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace TestStack.Dossier.Tests.DataSources.Dictionaries
{
public class FileDictionarySourceTests
public class WordsTests
{
[Fact]
public void WhenInitializingList_ThenPassClassNameToRepositoryAsDictionaryName()
Expand All @@ -19,9 +19,9 @@ public void WhenInitializingList_ThenPassClassNameToRepositoryAsDictionaryName()
}
}

public class DummySource : FileDictionarySource
public class DummySource : Words
{
internal DummySource(IDictionaryRepository repository)
: base(Substitute.For<IGenerator>(), repository) { }
: base(Substitute.For<IGenerator>(), repository, "Dummy") { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Collections.Generic;
using TestStack.Dossier.DataSources;
using TestStack.Dossier.DataSources.Dictionaries;
using Xunit.Extensions;

namespace TestStack.Dossier.Tests.EquivalenceClasses
{
public class AddressAusEquivalenceTests : FileDictionaryEquivalenceTests
{
[Theory]
[ClassData(typeof(AddressAusTestCases))]
public override void WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(DataSource<string> source, List<string> testCases)
{
base.WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(source, testCases);
}
}

public class AddressAusTestCases : FileDictionaryEquivalenceTestCases
{
protected override List<object[]> GetData()
{
return new List<object[]>
{
new object[]
{new Words(FromDictionary.AddressAusCity), GenerateTestCasesForSut(Any.AddressAusCity)},
new object[]
{new Words(FromDictionary.AddressAusCompany), GenerateTestCasesForSut(Any.AddressAusCompany)},
new object[]
{new Words(FromDictionary.AddressAusPhone), GenerateTestCasesForSut(Any.AddressAusPhone)},
new object[]
{new Words(FromDictionary.AddressAusPostCode), GenerateTestCasesForSut(Any.AddressAusPostCode)},
new object[]
{new Words(FromDictionary.AddressAusState), GenerateTestCasesForSut(Any.AddressAusState)},
new object[]
{
new Words(FromDictionary.AddressAusStateAbbreviation),
GenerateTestCasesForSut(Any.AddressAusStateAbbreviation)
},
new object[]
{new Words(FromDictionary.AddressAusStreet), GenerateTestCasesForSut(Any.AddressAusStreet)},
new object[]
{new Words(FromDictionary.AddressAusWebsite), GenerateTestCasesForSut(Any.AddressAusWebsite)},
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using TestStack.Dossier.DataSources;
using TestStack.Dossier.DataSources.Dictionaries;
using Xunit.Extensions;

namespace TestStack.Dossier.Tests.EquivalenceClasses
{
public class AddressUkEquivalenceClasses : FileDictionaryEquivalenceTests
{
[Theory]
[ClassData(typeof(AddressUkTestCases))]
public override void WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(DataSource<string> source, List<string> testCases)
{
base.WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(source, testCases);
}
}

public class AddressUkTestCases : FileDictionaryEquivalenceTestCases
{
protected override List<object[]> GetData()
{
return new List<object[]>
{
new object[]
{new Words(FromDictionary.AddressUkCounty), GenerateTestCasesForSut(Any.AddressUkCounty)},
new object[]
{new Words(FromDictionary.AddressUkCity), GenerateTestCasesForSut(Any.AddressUkCity)},
new object[]
{new Words(FromDictionary.AddressUkCompany), GenerateTestCasesForSut(Any.AddressUkCompany)},
new object[]
{new Words(FromDictionary.AddressUkPhone), GenerateTestCasesForSut(Any.AddressUkPhone)},
new object[]
{new Words(FromDictionary.AddressUkPostCode), GenerateTestCasesForSut(Any.AddressUkPostCode)},
new object[]
{new Words(FromDictionary.AddressUkStreet), GenerateTestCasesForSut(Any.AddressUkStreet)},
new object[]
{new Words(FromDictionary.AddressUkWebsite), GenerateTestCasesForSut(Any.AddressUkWebsite)},
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections.Generic;
using TestStack.Dossier.DataSources;
using TestStack.Dossier.DataSources.Dictionaries;
using Xunit.Extensions;

namespace TestStack.Dossier.Tests.EquivalenceClasses
{
public class AddressUsEquivalenceTests : FileDictionaryEquivalenceTests
{
[Theory]
[ClassData(typeof(AddressUsTestCases))]
public override void WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(DataSource<string> source, List<string> testCases)
{
base.WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(source, testCases);
}
}

public class AddressUsTestCases : FileDictionaryEquivalenceTestCases
{
protected override List<object[]> GetData()
{
return new List<object[]>
{
new object[]
{new Words(FromDictionary.AddressUsCity), GenerateTestCasesForSut(Any.AddressUsCity)},
new object[]
{new Words(FromDictionary.AddressUsCompany), GenerateTestCasesForSut(Any.AddressUsCompany)},
new object[]
{new Words(FromDictionary.AddressUsPhone), GenerateTestCasesForSut(Any.AddressUsPhone)},
new object[]
{new Words(FromDictionary.AddressUsSocialSecurityNumber), GenerateTestCasesForSut(Any.AddressUsSocialSecurityNumber)},
new object[]
{new Words(FromDictionary.AddressUsState), GenerateTestCasesForSut(Any.AddressUsState)},
new object[]
{
new Words(FromDictionary.AddressUsStateAbbreviation),
GenerateTestCasesForSut(Any.AddressUsStateAbbreviation)
},
new object[]
{new Words(FromDictionary.AddressUsStreet), GenerateTestCasesForSut(Any.AddressUsStreet)},
new object[]
{new Words(FromDictionary.AddressUsWebsite), GenerateTestCasesForSut(Any.AddressUsWebsite)},
new object[]
{new Words(FromDictionary.AddressUsZipCode), GenerateTestCasesForSut(Any.AddressUsZipCode)}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using TestStack.Dossier.DataSources;
using TestStack.Dossier.DataSources.Dictionaries;
using Xunit.Extensions;

namespace TestStack.Dossier.Tests.EquivalenceClasses
{
public class ColourEquivalenceTests : FileDictionaryEquivalenceTests
{
[Theory]
[ClassData(typeof(ColourTestCases))]
public override void WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(DataSource<string> source, List<string> testCases)
{
base.WhenGettingAnyData_ThenReturnRandomDataWhichIsReasonablyUnique(source, testCases);
}
}

public class ColourTestCases : FileDictionaryEquivalenceTestCases
{
protected override List<object[]> GetData()
{
return new List<object[]>
{
new object[]
{new Words(FromDictionary.ColourHex), GenerateTestCasesForSut(Any.ColourHex)},
new object[]
{new Words(FromDictionary.ColourName), GenerateTestCasesForSut(Any.ColourName)}
};
}
}
}
Loading