|
| 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 | +} |
0 commit comments