public static IEnumerable <TestCaseData> TestCase2(string testName) { const int minValue = 1; const int maxValue = 101; const int iterations = 1_000_000; const float maxDeviationPercent = 10; int count = maxValue - minValue; int[] values1 = Enumerable.Range(minValue, count).ToArray(); int[] values2 = values1.Select(value => value == minValue + 1 ? minValue : value).ToArray(); int[] values3 = values1.Select(value => value == count - 1 ? count : value).ToArray(); IValueProvider <int> valueProviderRandomStandard = ValueProvider.Create(() => GetNextRandomStandardValue(minValue, maxValue)); IValueProvider <int> valueProviderRandomCrypto = ValueProvider.Create(() => GetNextRandomCryptoValue(minValue, maxValue)); IValueProvider <int> valueProviderStub1 = ValueProviderStub.Create(values1); IValueProvider <int> valueProviderStub2 = ValueProviderStub.Create(values2); IValueProvider <int> valueProviderStub3 = ValueProviderStub.Create(values3); yield return(new TestCaseData(valueProviderRandomStandard, minValue, maxValue, iterations, maxDeviationPercent).SetName($"{testName} - Random Standard").Returns(true)); yield return(new TestCaseData(valueProviderRandomCrypto, minValue, maxValue, iterations, maxDeviationPercent).SetName($"{testName} - Random Crypto").Returns(true)); yield return(new TestCaseData(valueProviderStub1, minValue, maxValue, count, maxDeviationPercent).SetName($"{testName} - ValueProviderStub - 1").Returns(true)); yield return(new TestCaseData(valueProviderStub2, minValue, maxValue, count, maxDeviationPercent).SetName($"{testName} - ValueProviderStub - 2").Returns(false)); yield return(new TestCaseData(valueProviderStub3, minValue, maxValue, count, maxDeviationPercent).SetName($"{testName} - ValueProviderStub - 3").Returns(false)); }
// After all cards have been retrieved by the GetCard2() method the RemainingCards // property must be empty. public void WhenAllCardsHaveBeenRetrievedByInvokingTheGetCard2Method_ThenTheRemainingCardsPropertyIsEmpty() { Card[] allCards = GetAllCards(); CardGame cardGame = new CardGame(ValueProviderStub.Create <Card>(allCards)); for (int i = 0; i < allCards.Length; i++) // After the last iteration of this { _ = cardGame.GetCard2(); // loop there will be no cards remaining. } CollectionAssert.IsEmpty(cardGame.RemainingCards); // RemainingCards property must be // empty at this point. }
// If the GetCard2() method is invoked when there are no cards remaining then an // InvalidOperationException should be thrown. // InvalidOperationException: There are no cards remaining to dispurse. public void WhenCardsRemainingPropertyIsEmptyAndTheGetCard2MethodIsInvoked_ThenAnInvalidOperationExceptionIsThrown() { Card[] allCards = GetAllCards(); CardGame cardGame = new CardGame(ValueProviderStub.Create <Card>(allCards)); for (int i = 0; i < allCards.Length; i++) // After the last iteration of this { _ = cardGame.GetCard2(); // loop there will be no cards remaining. } Assert.Throws <InvalidOperationException>(() => cardGame.GetCard2()); // Attempting to get a card when there // are no cards remaining should throw // an exception. }
// After a card is retrieved by the GetCard2() method the RemainingCards // property must no longer contain the card retrieved. public void WhenACardIsRetrievedByInvokingTheGetCard2Method_ThenTheCardIsNoLongerContainedInTheRemainingCardsSet() { Card[] allCards = GetAllCards(); CardGame cardGame = new CardGame(ValueProviderStub.Create <Card>(allCards)); for (int i = 0; i < allCards.Length; i++) { Card card = cardGame.GetCard2(); // Retrieve one card. CollectionAssert.DoesNotContain(cardGame.RemainingCards, card); // Verify that the card retrieved is no // longer contained in the RemainingCards // set. } }
public static IEnumerable <TestCaseData> TestCase1(string testName) { const int minValue = 1; const int maxValue = 1001; int count = maxValue - minValue; IValueProvider <int> valueProviderRandomStandard = ValueProvider.Create(() => GetNextRandomStandardValue(minValue, maxValue)); IValueProvider <int> valueProviderRandomCrypto = ValueProvider.Create(() => GetNextRandomCryptoValue(minValue, maxValue)); IValueProvider <int> valueProviderStub = ValueProviderStub.Create(Enumerable.Range(minValue, count).ToArray()); yield return(new TestCaseData(valueProviderRandomStandard, count).SetName($"{testName} - Random Standard")); yield return(new TestCaseData(valueProviderRandomCrypto, count).SetName($"{testName} - Random Crypto")); yield return(new TestCaseData(valueProviderStub, count).SetName($"{testName} - ValueProviderStub")); }