public void ShouldReturnPrimesUnder30() { // Arrange var primeNumbers = new PrimeNumbers(); var primesReturned = false; var primesGenerated = new List <int>(); // Primes taken from https://oeis.org/A000040 var primesUnder30 = new List <int> { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; // Act foreach (var prime in primeNumbers.Generate(30)) { Assert.IsTrue(primesUnder30.Contains(prime), $"Unexpected prime: {prime}"); primesGenerated.Add(prime); primesReturned = true; } // Assert Assert.IsTrue(primesReturned, "Expected the on prime action to be called."); Assert.IsFalse(primesUnder30.Except(primesGenerated).Any(), "Expected all primes under 30 to be generated."); }