From 80361f48b5f879b7fe56cb05a99e33e17713b18e Mon Sep 17 00:00:00 2001 From: Michael Whelan Date: Thu, 4 Feb 2016 18:27:47 +0000 Subject: [PATCH 01/15] Removed need for file dictionary source classes --- .../DataSources/DataSourceConventionTests.cs | 32 ++++---- ...leDictionaryRepositoryIntegrationTests.cs} | 2 +- ...DictionarySourceTests.cs => WordsTests.cs} | 6 +- .../GeoEquivalenceClassesTests.cs | 21 ++---- .../PersonEquivalenceClassesTests.cs | 30 +++----- TestStack.Dossier.Tests/GetAnonymousTests.cs | 6 +- .../TestStack.Dossier.Tests.csproj | 4 +- TestStack.Dossier/AnonymousValueFixture.cs | 20 +++++ .../Dictionaries/FromDictionary.cs | 75 +++++++++++++++++++ .../{FileDictionarySource.cs => Words.cs} | 17 +++-- .../Geography/GeoContinentSource.cs | 11 --- .../Geography/GeoCountryCodeSource.cs | 11 --- .../DataSources/Geography/GeoCountrySource.cs | 11 --- .../Geography/GeoLatitudeSource.cs | 11 --- .../Geography/GeoLongitudeSource.cs | 11 --- .../Person/PersonEmailAddressSource.cs | 24 ------ .../Person/PersonLanguageSource.cs | 11 --- .../Person/PersonNameFirstFemaleSource.cs | 11 --- .../Person/PersonNameFirstMaleSource.cs | 11 --- .../Person/PersonNameFirstSource.cs | 11 --- .../Person/PersonNameFullSource.cs | 11 --- .../Person/PersonNameLastSource.cs | 11 --- .../Person/PersonNameSuffixSource.cs | 11 --- .../Person/PersonNameTitleSource.cs | 11 --- ...escs.cs => GeographyEquivalenceClasses.cs} | 29 +++---- .../{Person => }/PersonEquivalenceClasses.cs | 53 +++++-------- .../Suppliers/DefaultEmailValueSupplier.cs | 2 +- .../DefaultFirstNameValueSupplier.cs | 2 +- .../Suppliers/DefaultLastNameValueSupplier.cs | 2 +- 29 files changed, 178 insertions(+), 290 deletions(-) rename TestStack.Dossier.Tests/DataSources/Dictionaries/{FileDictionaryRepositoryIntegrationTests.cs => CachedFileDictionaryRepositoryIntegrationTests.cs} (94%) rename TestStack.Dossier.Tests/DataSources/Dictionaries/{FileDictionarySourceTests.cs => WordsTests.cs} (79%) create mode 100644 TestStack.Dossier/DataSources/Dictionaries/FromDictionary.cs rename TestStack.Dossier/DataSources/Dictionaries/{FileDictionarySource.cs => Words.cs} (53%) delete mode 100644 TestStack.Dossier/DataSources/Geography/GeoContinentSource.cs delete mode 100644 TestStack.Dossier/DataSources/Geography/GeoCountryCodeSource.cs delete mode 100644 TestStack.Dossier/DataSources/Geography/GeoCountrySource.cs delete mode 100644 TestStack.Dossier/DataSources/Geography/GeoLatitudeSource.cs delete mode 100644 TestStack.Dossier/DataSources/Geography/GeoLongitudeSource.cs delete mode 100644 TestStack.Dossier/DataSources/Person/PersonEmailAddressSource.cs delete mode 100644 TestStack.Dossier/DataSources/Person/PersonLanguageSource.cs delete mode 100644 TestStack.Dossier/DataSources/Person/PersonNameFirstFemaleSource.cs delete mode 100644 TestStack.Dossier/DataSources/Person/PersonNameFirstMaleSource.cs delete mode 100644 TestStack.Dossier/DataSources/Person/PersonNameFirstSource.cs delete mode 100644 TestStack.Dossier/DataSources/Person/PersonNameFullSource.cs delete mode 100644 TestStack.Dossier/DataSources/Person/PersonNameLastSource.cs delete mode 100644 TestStack.Dossier/DataSources/Person/PersonNameSuffixSource.cs delete mode 100644 TestStack.Dossier/DataSources/Person/PersonNameTitleSource.cs rename TestStack.Dossier/EquivalenceClasses/{Geo/GeographyEquivalenceClassescs.cs => GeographyEquivalenceClasses.cs} (60%) rename TestStack.Dossier/EquivalenceClasses/{Person => }/PersonEquivalenceClasses.cs (60%) diff --git a/TestStack.Dossier.Tests/DataSources/DataSourceConventionTests.cs b/TestStack.Dossier.Tests/DataSources/DataSourceConventionTests.cs index a5c3167..7fa4538 100644 --- a/TestStack.Dossier.Tests/DataSources/DataSourceConventionTests.cs +++ b/TestStack.Dossier.Tests/DataSources/DataSourceConventionTests.cs @@ -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 @@ -25,21 +23,21 @@ public static IEnumerable 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 }; } } } diff --git a/TestStack.Dossier.Tests/DataSources/Dictionaries/FileDictionaryRepositoryIntegrationTests.cs b/TestStack.Dossier.Tests/DataSources/Dictionaries/CachedFileDictionaryRepositoryIntegrationTests.cs similarity index 94% rename from TestStack.Dossier.Tests/DataSources/Dictionaries/FileDictionaryRepositoryIntegrationTests.cs rename to TestStack.Dossier.Tests/DataSources/Dictionaries/CachedFileDictionaryRepositoryIntegrationTests.cs index 50171e7..1665ced 100644 --- a/TestStack.Dossier.Tests/DataSources/Dictionaries/FileDictionaryRepositoryIntegrationTests.cs +++ b/TestStack.Dossier.Tests/DataSources/Dictionaries/CachedFileDictionaryRepositoryIntegrationTests.cs @@ -5,7 +5,7 @@ namespace TestStack.Dossier.Tests.DataSources.Dictionaries { - public class FileDictionaryRepositoryIntegrationTests + public class CachedFileDictionaryRepositoryIntegrationTests { [Fact] public void GivenAnExternalFileDictionaryExists_WhenRetrievingWords_ThenExternalDictionaryIsUsed() diff --git a/TestStack.Dossier.Tests/DataSources/Dictionaries/FileDictionarySourceTests.cs b/TestStack.Dossier.Tests/DataSources/Dictionaries/WordsTests.cs similarity index 79% rename from TestStack.Dossier.Tests/DataSources/Dictionaries/FileDictionarySourceTests.cs rename to TestStack.Dossier.Tests/DataSources/Dictionaries/WordsTests.cs index 0394497..1053125 100644 --- a/TestStack.Dossier.Tests/DataSources/Dictionaries/FileDictionarySourceTests.cs +++ b/TestStack.Dossier.Tests/DataSources/Dictionaries/WordsTests.cs @@ -5,7 +5,7 @@ namespace TestStack.Dossier.Tests.DataSources.Dictionaries { - public class FileDictionarySourceTests + public class WordsTests { [Fact] public void WhenInitializingList_ThenPassClassNameToRepositoryAsDictionaryName() @@ -19,9 +19,9 @@ public void WhenInitializingList_ThenPassClassNameToRepositoryAsDictionaryName() } } - public class DummySource : FileDictionarySource + public class DummySource : Words { internal DummySource(IDictionaryRepository repository) - : base(Substitute.For(), repository) { } + : base(Substitute.For(), repository, "Dummy") { } } } diff --git a/TestStack.Dossier.Tests/EquivalenceClasses/GeoEquivalenceClassesTests.cs b/TestStack.Dossier.Tests/EquivalenceClasses/GeoEquivalenceClassesTests.cs index c5fa667..30e7f0f 100644 --- a/TestStack.Dossier.Tests/EquivalenceClasses/GeoEquivalenceClassesTests.cs +++ b/TestStack.Dossier.Tests/EquivalenceClasses/GeoEquivalenceClassesTests.cs @@ -3,21 +3,14 @@ using System.Linq; using Shouldly; using TestStack.Dossier.DataSources; -using TestStack.Dossier.DataSources.Geography; -using TestStack.Dossier.EquivalenceClasses.Geo; -using Xunit; +using TestStack.Dossier.DataSources.Dictionaries; using Xunit.Extensions; namespace TestStack.Dossier.Tests.EquivalenceClasses { public class GeoEquivalenceClassesTests { - public static AnonymousValueFixture Any { get; private set; } - - public GeoEquivalenceClassesTests() - { - Any = new AnonymousValueFixture(); - } + public static AnonymousValueFixture Any { get; private set; } = new AnonymousValueFixture(); [Theory] [PropertyData("TestCases")] @@ -41,11 +34,11 @@ public static IEnumerable TestCases { get { - yield return new object[] { new GeoContinentSource(), GenerateTestCasesForSut(Any.Continent) }; - yield return new object[] { new GeoCountrySource(), GenerateTestCasesForSut(Any.Country) }; - yield return new object[] { new GeoCountryCodeSource(), GenerateTestCasesForSut(Any.CountryCode) }; - yield return new object[] { new GeoLatitudeSource(), GenerateTestCasesForSut(Any.Latitude) }; - yield return new object[] { new GeoLongitudeSource(), GenerateTestCasesForSut(Any.Longitude) }; + yield return new object[] { new Words(FromDictionary.GeoContinent), GenerateTestCasesForSut(Any.Continent) }; + yield return new object[] { new Words(FromDictionary.GeoCountry), GenerateTestCasesForSut(Any.Country) }; + yield return new object[] { new Words(FromDictionary.GeoCountryCode), GenerateTestCasesForSut(Any.CountryCode) }; + yield return new object[] { new Words(FromDictionary.GeoLatitude), GenerateTestCasesForSut(Any.Latitude) }; + yield return new object[] { new Words(FromDictionary.GeoLongitude), GenerateTestCasesForSut(Any.Longitude) }; } } diff --git a/TestStack.Dossier.Tests/EquivalenceClasses/PersonEquivalenceClassesTests.cs b/TestStack.Dossier.Tests/EquivalenceClasses/PersonEquivalenceClassesTests.cs index 81db6dd..f2b40ee 100644 --- a/TestStack.Dossier.Tests/EquivalenceClasses/PersonEquivalenceClassesTests.cs +++ b/TestStack.Dossier.Tests/EquivalenceClasses/PersonEquivalenceClassesTests.cs @@ -3,8 +3,7 @@ using System.Linq; using Shouldly; using TestStack.Dossier.DataSources; -using TestStack.Dossier.DataSources.Person; -using TestStack.Dossier.EquivalenceClasses.Person; +using TestStack.Dossier.DataSources.Dictionaries; using Xunit; using Xunit.Extensions; @@ -12,12 +11,7 @@ namespace TestStack.Dossier.Tests.EquivalenceClasses { public class PersonEquivalenceClassesTests { - public static AnonymousValueFixture Any { get; private set; } - - public PersonEquivalenceClassesTests() - { - Any = new AnonymousValueFixture(); - } + public static AnonymousValueFixture Any { get; } = new AnonymousValueFixture(); [Theory] [PropertyData("TestCases")] @@ -40,7 +34,7 @@ public void WhenGettingAnyPersonData_ThenReturnRandomPersonDataWhichIsReasonably [Fact] public void WhenGettingUniqueEmail_ThenReturnUniqueEmailsAcrossFixtureInstances() { - var source = new PersonEmailAddressSource(); + var source = new Words(FromDictionary.PersonEmailAddress); var generatedValues = new List(); var any2 = new AnonymousValueFixture(); @@ -58,15 +52,15 @@ public static IEnumerable TestCases { get { - yield return new object[] { new PersonEmailAddressSource(), GenerateTestCasesForSut(Any.EmailAddress) }; - yield return new object[] { new PersonLanguageSource(), GenerateTestCasesForSut(Any.Language) }; - yield return new object[] { new PersonNameFirstFemaleSource(), GenerateTestCasesForSut(Any.FemaleFirstName) }; - yield return new object[] { new PersonNameFirstSource(), GenerateTestCasesForSut(Any.FirstName) }; - yield return new object[] { new PersonNameFullSource(), GenerateTestCasesForSut(Any.FullName) }; - yield return new object[] { new PersonNameLastSource(), GenerateTestCasesForSut(Any.LastName) }; - yield return new object[] { new PersonNameFirstMaleSource(), GenerateTestCasesForSut(Any.MaleFirstName) }; - yield return new object[] { new PersonNameSuffixSource(), GenerateTestCasesForSut(Any.Suffix) }; - yield return new object[] { new PersonNameTitleSource(), GenerateTestCasesForSut(Any.Title) }; + yield return new object[] { new Words(FromDictionary.PersonEmailAddress), GenerateTestCasesForSut(Any.EmailAddress) }; + yield return new object[] { new Words(FromDictionary.PersonLanguage), GenerateTestCasesForSut(Any.Language) }; + yield return new object[] { new Words(FromDictionary.PersonNameFirstFemale), GenerateTestCasesForSut(Any.FemaleFirstName) }; + yield return new object[] { new Words(FromDictionary.PersonNameFirst), GenerateTestCasesForSut(Any.FirstName) }; + yield return new object[] { new Words(FromDictionary.PersonNameFull), GenerateTestCasesForSut(Any.FullName) }; + yield return new object[] { new Words(FromDictionary.PersonNameLast), GenerateTestCasesForSut(Any.LastName) }; + yield return new object[] { new Words(FromDictionary.PersonNameFirstMale), GenerateTestCasesForSut(Any.MaleFirstName) }; + yield return new object[] { new Words(FromDictionary.PersonNameSuffix), GenerateTestCasesForSut(Any.Suffix) }; + yield return new object[] { new Words(FromDictionary.PersonNameTitle), GenerateTestCasesForSut(Any.Title) }; } } diff --git a/TestStack.Dossier.Tests/GetAnonymousTests.cs b/TestStack.Dossier.Tests/GetAnonymousTests.cs index b5a0ddf..3a2203e 100644 --- a/TestStack.Dossier.Tests/GetAnonymousTests.cs +++ b/TestStack.Dossier.Tests/GetAnonymousTests.cs @@ -1,6 +1,6 @@ using System; using Shouldly; -using TestStack.Dossier.DataSources.Person; +using TestStack.Dossier.DataSources.Dictionaries; using TestStack.Dossier.Lists; using TestStack.Dossier.Tests.TestHelpers; using TestStack.Dossier.Tests.TestHelpers.Builders; @@ -55,7 +55,7 @@ public void GivenNoValueHasBeenSetForAPropertyNamedFirstName_WhenRetrievingTheVa { var firstName = _b.Get(x => x.FirstName); - new PersonNameFirstSource().Data + new Words(FromDictionary.PersonNameFirst).Data .ShouldContain(firstName); } @@ -64,7 +64,7 @@ public void GivenNoValueHasBeenSetForAPropertyNamedLastName_WhenRetrievingTheVal { var lastName = _b.Get(x => x.LastName); - new PersonNameLastSource().Data + new Words(FromDictionary.PersonNameLast).Data .ShouldContain(lastName); } diff --git a/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj b/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj index e8fe2ff..34f79c8 100644 --- a/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj +++ b/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj @@ -72,8 +72,8 @@ - - + + diff --git a/TestStack.Dossier/AnonymousValueFixture.cs b/TestStack.Dossier/AnonymousValueFixture.cs index 3558fd6..bda1e63 100644 --- a/TestStack.Dossier/AnonymousValueFixture.cs +++ b/TestStack.Dossier/AnonymousValueFixture.cs @@ -1,8 +1,11 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Text; using Ploeh.AutoFixture; +using TestStack.Dossier.DataSources.Dictionaries; using TestStack.Dossier.Suppliers; namespace TestStack.Dossier @@ -25,6 +28,7 @@ static AnonymousValueFixture() new DefaultValueTypeValueSupplier(), new DefaultValueSupplier() }; + _dictionaries = new ConcurrentDictionary(); } /// @@ -106,5 +110,21 @@ public object Get(Type type, string propertyName) return valueSupplier.GenerateAnonymousValue(this, type, propertyName); } + + /// + /// Gets a data source for a file dictionary, which can be built-in or a user-supplied text file. + /// + /// The name of the file dictionary, without the extension + /// + public Words DictionaryFor(string dictionaryName) + { + if (!_dictionaries.ContainsKey(dictionaryName)) + { + _dictionaries[dictionaryName] = new Words(dictionaryName); + } + return _dictionaries[dictionaryName]; + } + + private static ConcurrentDictionary _dictionaries; } } diff --git a/TestStack.Dossier/DataSources/Dictionaries/FromDictionary.cs b/TestStack.Dossier/DataSources/Dictionaries/FromDictionary.cs new file mode 100644 index 0000000..ac4d958 --- /dev/null +++ b/TestStack.Dossier/DataSources/Dictionaries/FromDictionary.cs @@ -0,0 +1,75 @@ +#pragma warning disable 1591 +namespace TestStack.Dossier.DataSources.Dictionaries +{ + /// + /// Provides strongly-typed access to all of the built-in file dictionary names. + /// + public class FromDictionary + { + public const string AddressAusCity = "AddressAusCity"; + public const string AddressAusCompany = "AddressAusCompany"; + public const string AddressAusPhone = "AddressAusPhone"; + public const string AddressAusPostCode = "AddressAusPostCode"; + public const string AddressAusState = "AddressAusState"; + public const string AddressAusStateAbbreviation = "AddressAusStateAbbreviation"; + public const string AddressAusStreet = "AddressAusStreet"; + public const string AddressAusWebsite = "AddressAusWebsite"; + public const string AddressUkCity = "AddressUKCity"; + public const string AddressUkCompany = "AddressUKCompany"; + public const string AddressUkCounty = "AddressUKCounty"; + public const string AddressUkPhone = "AddressUKPhone"; + public const string AddressUkPostCode = "AddressUKPostCode"; + public const string AddressUkStreet = "AddressUKStreet"; + public const string AddressUkWebsite = "AddressUKWebsite"; + public const string AddressUsCity = "AddressUSCity"; + public const string AddressUsCompany = "AddressUSCompany"; + public const string AddressUsPhone = "AddressUSPhone"; + public const string AddressUsSocialSecurityNumber = "AddressUSSocialSecurityNumber"; + public const string AddressUsState = "AddressUSState"; + public const string AddressUsStateAbbreviation = "AddressUSStateAbbreviation"; + public const string AddressUsStreet = "AddressUSStreet"; + public const string AddressUsWebsite = "AddressUSWebsite"; + public const string AddressUsZipCode = "AddressUSZipCode"; + public const string ColourHex = "ColourHex"; + public const string ColourName = "ColourName"; + public const string CompanyIndustry = "CompanyIndustry"; + public const string CompanyJobTitle = "CompanyJobTitle"; + public const string CompanyLocation = "CompanyLocation"; + public const string CompanyName = "CompanyName"; + public const string FinanceCreditCardNumber = "FinanceCreditCardNumber"; + public const string FinanceCreditCardType = "FinanceCreditCardType"; + public const string FinanceCurrency = "FinanceCurrency"; + public const string FinanceCurrencyCode = "FinanceCurrencyCode"; + public const string Frequency = "Frequency"; + public const string GeoContinent = "GeoContinent"; + public const string GeoCountry = "GeoCountry"; + public const string GeoCountryCode = "GeoCountryCode"; + public const string GeoLatitude = "GeoLatitude"; + public const string GeoLongitude = "GeoLongitude"; + public const string IdentifierBitcoinAddress = "IdentifierBitcoinAddress"; + public const string IdentifierIban = "IdentifierIBAN"; + public const string IdentifierIpAddressV4 = "IdentifierIPAddressV4"; + public const string IdentifierIpAddressV6 = "IdentifierIPAddressV6"; + public const string IdentifierIsbn = "IdentifierISBN"; + public const string IdentifierMacAddress = "IdentifierMacAddress"; + public const string InternetDomainCountryCodeTopLevelDomain = "InternetDomainCountryCodeTopLevelDomain"; + public const string InternetDomainName = "InternetDomainName"; + public const string InternetDomainTopLevel = "InternetDomainTopLevel"; + public const string InternetUrl = "InternetURL"; + public const string LoremIpsum = "LoremIpsum"; + public const string PersonEmailAddress = "PersonEmailAddress"; + public const string PersonLanguage = "PersonLanguage"; + public const string PersonNameFirst = "PersonNameFirst"; + public const string PersonNameFirstFemale = "PersonNameFirstFemale"; + public const string PersonNameFirstMale = "PersonNameFirstMale"; + public const string PersonNameFull = "PersonNameFull"; + public const string PersonNameLast = "PersonNameLast"; + public const string PersonNameSuffix = "PersonNameSuffix"; + public const string PersonNameTitle = "PersonNameTitle"; + public const string PersonPassword = "PersonPassword"; + public const string PersonRace = "PersonRace"; + public const string PersonUsername = "PersonUsername"; + public const string ShirtSize = "ShirtSize"; + } +} +#pragma warning restore 1591 \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Dictionaries/FileDictionarySource.cs b/TestStack.Dossier/DataSources/Dictionaries/Words.cs similarity index 53% rename from TestStack.Dossier/DataSources/Dictionaries/FileDictionarySource.cs rename to TestStack.Dossier/DataSources/Dictionaries/Words.cs index e931f9f..40b8e91 100644 --- a/TestStack.Dossier/DataSources/Dictionaries/FileDictionarySource.cs +++ b/TestStack.Dossier/DataSources/Dictionaries/Words.cs @@ -4,28 +4,31 @@ namespace TestStack.Dossier.DataSources.Dictionaries { /// - /// The base class for data sources that load their data from dictionaries stored in files + /// The wrapper class for data sources that load words from dictionaries stored in files /// - public abstract class FileDictionarySource : DataSource + public class Words : DataSource { + private readonly string _dictionaryName; private readonly IDictionaryRepository _repository; /// - protected FileDictionarySource() - : this(new RandomGenerator(), new CachedFileDictionaryRepository()) { } + public Words(string dictionaryName) + : this(new RandomGenerator(), new CachedFileDictionaryRepository(), dictionaryName) + { + } /// - internal FileDictionarySource(IGenerator generator, IDictionaryRepository repository) + internal Words(IGenerator generator, IDictionaryRepository repository, string dictionaryName) : base(generator) { _repository = repository; + _dictionaryName = dictionaryName; } /// protected override IList InitializeDataSource() { - var dictionary = GetType().Name.Replace("Source", string.Empty); - return _repository.GetWordsFrom(dictionary); + return _repository.GetWordsFrom(_dictionaryName); } } } \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Geography/GeoContinentSource.cs b/TestStack.Dossier/DataSources/Geography/GeoContinentSource.cs deleted file mode 100644 index 7f0b525..0000000 --- a/TestStack.Dossier/DataSources/Geography/GeoContinentSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Geography -{ - /// - /// Dictionary of continent names - /// - public class GeoContinentSource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Geography/GeoCountryCodeSource.cs b/TestStack.Dossier/DataSources/Geography/GeoCountryCodeSource.cs deleted file mode 100644 index 4e398b0..0000000 --- a/TestStack.Dossier/DataSources/Geography/GeoCountryCodeSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Geography -{ - /// - /// Dictionary of country codes - /// - public class GeoCountryCodeSource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Geography/GeoCountrySource.cs b/TestStack.Dossier/DataSources/Geography/GeoCountrySource.cs deleted file mode 100644 index 0f9c3e0..0000000 --- a/TestStack.Dossier/DataSources/Geography/GeoCountrySource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Geography -{ - /// - /// Dictionary of country names - /// - public class GeoCountrySource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Geography/GeoLatitudeSource.cs b/TestStack.Dossier/DataSources/Geography/GeoLatitudeSource.cs deleted file mode 100644 index f692bfb..0000000 --- a/TestStack.Dossier/DataSources/Geography/GeoLatitudeSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Geography -{ - /// - /// Dictionary of latitude coordinates - /// - public class GeoLatitudeSource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Geography/GeoLongitudeSource.cs b/TestStack.Dossier/DataSources/Geography/GeoLongitudeSource.cs deleted file mode 100644 index 1396c24..0000000 --- a/TestStack.Dossier/DataSources/Geography/GeoLongitudeSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Geography -{ - /// - /// Dictionary of longitude coordinates codes - /// - public class GeoLongitudeSource : FileDictionarySource - { - } -} diff --git a/TestStack.Dossier/DataSources/Person/PersonEmailAddressSource.cs b/TestStack.Dossier/DataSources/Person/PersonEmailAddressSource.cs deleted file mode 100644 index 5f0645d..0000000 --- a/TestStack.Dossier/DataSources/Person/PersonEmailAddressSource.cs +++ /dev/null @@ -1,24 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; -using TestStack.Dossier.DataSources.Generators; - -namespace TestStack.Dossier.DataSources.Person -{ - /// - /// Dictionary of email addresses names - /// - public class PersonEmailAddressSource : FileDictionarySource - { - /// - /// Create a person email address source with random generation. - /// - public PersonEmailAddressSource() {} - - /// - /// Create a person email address source with custom generation. - /// - /// The generator to use - public PersonEmailAddressSource(IGenerator generator) - : base(generator, new CachedFileDictionaryRepository()) - {} - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Person/PersonLanguageSource.cs b/TestStack.Dossier/DataSources/Person/PersonLanguageSource.cs deleted file mode 100644 index 74ac97b..0000000 --- a/TestStack.Dossier/DataSources/Person/PersonLanguageSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Person -{ - /// - /// Dictionary of language names - /// - public class PersonLanguageSource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Person/PersonNameFirstFemaleSource.cs b/TestStack.Dossier/DataSources/Person/PersonNameFirstFemaleSource.cs deleted file mode 100644 index 866ff15..0000000 --- a/TestStack.Dossier/DataSources/Person/PersonNameFirstFemaleSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Person -{ - /// - /// Dictionary of female first names - /// - public class PersonNameFirstFemaleSource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Person/PersonNameFirstMaleSource.cs b/TestStack.Dossier/DataSources/Person/PersonNameFirstMaleSource.cs deleted file mode 100644 index fa33c33..0000000 --- a/TestStack.Dossier/DataSources/Person/PersonNameFirstMaleSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Person -{ - /// - /// Dictionary of male first names - /// - public class PersonNameFirstMaleSource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Person/PersonNameFirstSource.cs b/TestStack.Dossier/DataSources/Person/PersonNameFirstSource.cs deleted file mode 100644 index c913cbd..0000000 --- a/TestStack.Dossier/DataSources/Person/PersonNameFirstSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Person -{ - /// - /// Dictionary of male and female first names - /// - public class PersonNameFirstSource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Person/PersonNameFullSource.cs b/TestStack.Dossier/DataSources/Person/PersonNameFullSource.cs deleted file mode 100644 index a94c348..0000000 --- a/TestStack.Dossier/DataSources/Person/PersonNameFullSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Person -{ - /// - /// Dictionary of male and female full names - first and last name - /// - public class PersonNameFullSource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Person/PersonNameLastSource.cs b/TestStack.Dossier/DataSources/Person/PersonNameLastSource.cs deleted file mode 100644 index 286557d..0000000 --- a/TestStack.Dossier/DataSources/Person/PersonNameLastSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Person -{ - /// - /// Dictionary of last names - /// - public class PersonNameLastSource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Person/PersonNameSuffixSource.cs b/TestStack.Dossier/DataSources/Person/PersonNameSuffixSource.cs deleted file mode 100644 index cab816a..0000000 --- a/TestStack.Dossier/DataSources/Person/PersonNameSuffixSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Person -{ - /// - /// Dictionary of name suffixes - /// - public class PersonNameSuffixSource : FileDictionarySource - { - } -} \ No newline at end of file diff --git a/TestStack.Dossier/DataSources/Person/PersonNameTitleSource.cs b/TestStack.Dossier/DataSources/Person/PersonNameTitleSource.cs deleted file mode 100644 index d69a6b8..0000000 --- a/TestStack.Dossier/DataSources/Person/PersonNameTitleSource.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TestStack.Dossier.DataSources.Dictionaries; - -namespace TestStack.Dossier.DataSources.Person -{ - /// - /// Dictionary of name titles - /// - public class PersonNameTitleSource : FileDictionarySource - { - } -} diff --git a/TestStack.Dossier/EquivalenceClasses/Geo/GeographyEquivalenceClassescs.cs b/TestStack.Dossier/EquivalenceClasses/GeographyEquivalenceClasses.cs similarity index 60% rename from TestStack.Dossier/EquivalenceClasses/Geo/GeographyEquivalenceClassescs.cs rename to TestStack.Dossier/EquivalenceClasses/GeographyEquivalenceClasses.cs index c8c4377..5cde003 100644 --- a/TestStack.Dossier/EquivalenceClasses/Geo/GeographyEquivalenceClassescs.cs +++ b/TestStack.Dossier/EquivalenceClasses/GeographyEquivalenceClasses.cs @@ -1,18 +1,13 @@ -using TestStack.Dossier.DataSources.Geography; +using TestStack.Dossier.DataSources.Dictionaries; -namespace TestStack.Dossier.EquivalenceClasses.Geo +// ReSharper disable once CheckNamespace +namespace TestStack.Dossier { /// /// Extension methods that describe equivalence classes for generating anonymous geography-related values. /// - public static class GeographyEquivalenceClassescs + public static class GeographyEquivalenceClasses { - private static GeoContinentSource _geoContinentSource; - private static GeoCountrySource _geoCountrySource; - private static GeoCountryCodeSource _geoCountryCodeSource; - private static GeoLatitudeSource _geoLatitudeSource; - private static GeoLongitudeSource _geoLongitudeSource; - /// /// Generate and return a continent name. /// @@ -20,8 +15,7 @@ public static class GeographyEquivalenceClassescs /// The generated continent public static string Continent(this AnonymousValueFixture fixture) { - if (_geoContinentSource == null) _geoContinentSource = new GeoContinentSource(); - return _geoContinentSource.Next(); + return fixture.DictionaryFor(FromDictionary.GeoContinent).Next(); } /// @@ -31,8 +25,7 @@ public static string Continent(this AnonymousValueFixture fixture) /// The generated country public static string Country(this AnonymousValueFixture fixture) { - if (_geoCountrySource == null) _geoCountrySource = new GeoCountrySource(); - return _geoCountrySource.Next(); + return fixture.DictionaryFor(FromDictionary.GeoCountry).Next(); } /// @@ -42,11 +35,9 @@ public static string Country(this AnonymousValueFixture fixture) /// The generated country code public static string CountryCode(this AnonymousValueFixture fixture) { - if (_geoCountryCodeSource == null) _geoCountryCodeSource = new GeoCountryCodeSource(); - return _geoCountryCodeSource.Next(); + return fixture.DictionaryFor(FromDictionary.GeoCountryCode).Next(); } - /// /// Generate and return a latitude coordinate. /// @@ -54,8 +45,7 @@ public static string CountryCode(this AnonymousValueFixture fixture) /// The generated latitude public static string Latitude(this AnonymousValueFixture fixture) { - if (_geoLatitudeSource == null) _geoLatitudeSource = new GeoLatitudeSource(); - return _geoLatitudeSource.Next(); + return fixture.DictionaryFor(FromDictionary.GeoLatitude).Next(); } /// @@ -65,8 +55,7 @@ public static string Latitude(this AnonymousValueFixture fixture) /// The generated longitude public static string Longitude(this AnonymousValueFixture fixture) { - if (_geoLongitudeSource == null) _geoLongitudeSource = new GeoLongitudeSource(); - return _geoLongitudeSource.Next(); + return fixture.DictionaryFor(FromDictionary.GeoLongitude).Next(); } } } diff --git a/TestStack.Dossier/EquivalenceClasses/Person/PersonEquivalenceClasses.cs b/TestStack.Dossier/EquivalenceClasses/PersonEquivalenceClasses.cs similarity index 60% rename from TestStack.Dossier/EquivalenceClasses/Person/PersonEquivalenceClasses.cs rename to TestStack.Dossier/EquivalenceClasses/PersonEquivalenceClasses.cs index d2f30b7..917153e 100644 --- a/TestStack.Dossier/EquivalenceClasses/Person/PersonEquivalenceClasses.cs +++ b/TestStack.Dossier/EquivalenceClasses/PersonEquivalenceClasses.cs @@ -1,23 +1,16 @@ -using TestStack.Dossier.DataSources.Generators; -using TestStack.Dossier.DataSources.Person; +using TestStack.Dossier.DataSources.Dictionaries; +using TestStack.Dossier.DataSources.Generators; -namespace TestStack.Dossier.EquivalenceClasses.Person +// ReSharper disable once CheckNamespace +namespace TestStack.Dossier { /// /// Extension methods that describe equivalence classes for generating anonymous person-related values. /// - public static class NameEquivalenceClasses + public static class PersonEquivalenceClasses { - private static PersonEmailAddressSource _personEmailAddressSource; - private static PersonEmailAddressSource _uniquePersonEmailAddressSource; - private static PersonLanguageSource _personLanguageSource; - private static PersonNameFirstFemaleSource _personNameFirstFemaleSource; - private static PersonNameFirstSource _personNameFirstSource; - private static PersonNameFullSource _personNameFullSource; - private static PersonNameLastSource _personNameLastSource; - private static PersonNameFirstMaleSource _personNameFirstMaleSource; - private static PersonNameSuffixSource _personNameSuffixSource; - private static PersonNameTitleSource _personNameTitleSource; + private static Words _personEmailAddressSource; + private static Words _uniquePersonEmailAddressSource; /// /// Generate and return an email address. @@ -26,8 +19,7 @@ public static class NameEquivalenceClasses /// The generated email public static string EmailAddress(this AnonymousValueFixture fixture) { - if (_personEmailAddressSource == null) _personEmailAddressSource = new PersonEmailAddressSource(); - return _personEmailAddressSource.Next(); + return fixture.DictionaryFor(FromDictionary.PersonEmailAddress).Next(); } /// @@ -39,9 +31,9 @@ public static string UniqueEmailAddress(this AnonymousValueFixture fixture) { if (_uniquePersonEmailAddressSource == null) { - if (_personEmailAddressSource == null) _personEmailAddressSource = new PersonEmailAddressSource(); + if (_personEmailAddressSource == null) _personEmailAddressSource = fixture.DictionaryFor(FromDictionary.PersonEmailAddress); var generator = new SequentialGenerator(0, _personEmailAddressSource.Data.Count, listShouldBeUnique: true); - _uniquePersonEmailAddressSource = new PersonEmailAddressSource(generator); + _uniquePersonEmailAddressSource = new Words(generator, new CachedFileDictionaryRepository(), FromDictionary.PersonEmailAddress); } return _uniquePersonEmailAddressSource.Next(); @@ -54,8 +46,7 @@ public static string UniqueEmailAddress(this AnonymousValueFixture fixture) /// The generated language public static string Language(this AnonymousValueFixture fixture) { - if (_personLanguageSource == null) _personLanguageSource = new PersonLanguageSource(); - return _personLanguageSource.Next(); + return fixture.DictionaryFor(FromDictionary.PersonLanguage).Next(); } /// @@ -65,8 +56,7 @@ public static string Language(this AnonymousValueFixture fixture) /// The generated female first name public static string FemaleFirstName(this AnonymousValueFixture fixture) { - if (_personNameFirstFemaleSource == null) _personNameFirstFemaleSource = new PersonNameFirstFemaleSource(); - return _personNameFirstFemaleSource.Next(); + return fixture.DictionaryFor(FromDictionary.PersonNameFirstFemale).Next(); } /// @@ -76,8 +66,7 @@ public static string FemaleFirstName(this AnonymousValueFixture fixture) /// The generated first name public static string FirstName(this AnonymousValueFixture fixture) { - if (_personNameFirstSource == null) _personNameFirstSource = new PersonNameFirstSource(); - return _personNameFirstSource.Next(); + return fixture.DictionaryFor(FromDictionary.PersonNameFirst).Next(); } /// @@ -87,8 +76,7 @@ public static string FirstName(this AnonymousValueFixture fixture) /// The generated full name public static string FullName(this AnonymousValueFixture fixture) { - if (_personNameFullSource == null) _personNameFullSource = new PersonNameFullSource(); - return _personNameFullSource.Next(); + return fixture.DictionaryFor(FromDictionary.PersonNameFull).Next(); } /// @@ -98,8 +86,7 @@ public static string FullName(this AnonymousValueFixture fixture) /// The generated last name public static string LastName(this AnonymousValueFixture fixture) { - if (_personNameLastSource == null) _personNameLastSource = new PersonNameLastSource(); - return _personNameLastSource.Next(); + return fixture.DictionaryFor(FromDictionary.PersonNameLast).Next(); } /// @@ -109,8 +96,7 @@ public static string LastName(this AnonymousValueFixture fixture) /// The generated male first name public static string MaleFirstName(this AnonymousValueFixture fixture) { - if (_personNameFirstMaleSource == null) _personNameFirstMaleSource = new PersonNameFirstMaleSource(); - return _personNameFirstMaleSource.Next(); + return fixture.DictionaryFor(FromDictionary.PersonNameFirstMale).Next(); } /// @@ -120,8 +106,7 @@ public static string MaleFirstName(this AnonymousValueFixture fixture) /// The generated suffix public static string Suffix(this AnonymousValueFixture fixture) { - if (_personNameSuffixSource == null) _personNameSuffixSource = new PersonNameSuffixSource(); - return _personNameSuffixSource.Next(); + return fixture.DictionaryFor(FromDictionary.PersonNameSuffix).Next(); } /// @@ -131,10 +116,8 @@ public static string Suffix(this AnonymousValueFixture fixture) /// The generated title public static string Title(this AnonymousValueFixture fixture) { - if (_personNameTitleSource == null) _personNameTitleSource = new PersonNameTitleSource(); - return _personNameTitleSource.Next(); + return fixture.DictionaryFor(FromDictionary.PersonNameTitle).Next(); } } - } diff --git a/TestStack.Dossier/Suppliers/DefaultEmailValueSupplier.cs b/TestStack.Dossier/Suppliers/DefaultEmailValueSupplier.cs index 5db3f94..275ae44 100644 --- a/TestStack.Dossier/Suppliers/DefaultEmailValueSupplier.cs +++ b/TestStack.Dossier/Suppliers/DefaultEmailValueSupplier.cs @@ -1,5 +1,5 @@ using System; -using TestStack.Dossier.EquivalenceClasses.Person; +using TestStack.Dossier.EquivalenceClasses; namespace TestStack.Dossier.Suppliers { diff --git a/TestStack.Dossier/Suppliers/DefaultFirstNameValueSupplier.cs b/TestStack.Dossier/Suppliers/DefaultFirstNameValueSupplier.cs index 57edf91..fea53d3 100644 --- a/TestStack.Dossier/Suppliers/DefaultFirstNameValueSupplier.cs +++ b/TestStack.Dossier/Suppliers/DefaultFirstNameValueSupplier.cs @@ -1,5 +1,5 @@ using System; -using TestStack.Dossier.EquivalenceClasses.Person; +using TestStack.Dossier.EquivalenceClasses; namespace TestStack.Dossier.Suppliers { diff --git a/TestStack.Dossier/Suppliers/DefaultLastNameValueSupplier.cs b/TestStack.Dossier/Suppliers/DefaultLastNameValueSupplier.cs index a5f3fc0..332100a 100644 --- a/TestStack.Dossier/Suppliers/DefaultLastNameValueSupplier.cs +++ b/TestStack.Dossier/Suppliers/DefaultLastNameValueSupplier.cs @@ -1,5 +1,5 @@ using System; -using TestStack.Dossier.EquivalenceClasses.Person; +using TestStack.Dossier.EquivalenceClasses; namespace TestStack.Dossier.Suppliers { From 3b4ef747346ed6df399d987168c5ed4d2917c880 Mon Sep 17 00:00:00 2001 From: Michael Whelan Date: Thu, 4 Feb 2016 18:28:56 +0000 Subject: [PATCH 02/15] ... and the project file --- TestStack.Dossier/TestStack.Dossier.csproj | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/TestStack.Dossier/TestStack.Dossier.csproj b/TestStack.Dossier/TestStack.Dossier.csproj index ebc247e..24d0036 100644 --- a/TestStack.Dossier/TestStack.Dossier.csproj +++ b/TestStack.Dossier/TestStack.Dossier.csproj @@ -52,31 +52,18 @@ + + + + - - - - - - - - - - - - - - - - - @@ -179,6 +166,7 @@ +