public void WhenMinIsLessThanMax_ThenReturnRandomLength()
            {
                var createdLen2 = false;
                var createdLen3 = false;

                using (var sut = new CryptoRandomString("A"))
                {
                    for (var i = 0; i < 100; i++)
                    {
                        var result = sut.GenerateArray(2, 3);

                        if (result.Length == 2)
                        {
                            createdLen2 = true;
                            Assert.That(result.First(), Is.EqualTo('A'));
                            Assert.That(result.Second(), Is.EqualTo('A'));
                        }
                        else if (result.Length == 3)
                        {
                            createdLen3 = true;
                            Assert.That(result.First(), Is.EqualTo('A'));
                            Assert.That(result.Second(), Is.EqualTo('A'));
                            Assert.That(result.Third(), Is.EqualTo('A'));
                        }
                        else
                        {
                            Assert.Fail($"Array was length {result.Length}.");
                        }
                    }
                }

                Assert.That(createdLen2, Is.True);
                Assert.That(createdLen3, Is.True);
            }
 public void WhenMinIsGreaterThanMax_ThenThrowException()
 {
     using (var sut = new CryptoRandomString(CharacterSets.Digits))
     {
         Assert.Throws <ArgumentOutOfRangeException>(() => sut.GenerateArray(2, 1));
     }
 }
            public void WhenValidChars_ThenReturnOnlyValidChars()
            {
                using (var sut = new CryptoRandomString(CharacterSets.Digits))
                {
                    var result = sut.GenerateArray(100);

                    Assert.That(result.IsDigitsOnly, Is.True);
                }
            }
            public void WhenOnlyOneValidChar_AndLengthOne_ThenReturnChar()
            {
                using (var sut = new CryptoRandomString("A"))
                {
                    var result = sut.GenerateArray(1);

                    Assert.That(result.Single(), Is.EqualTo('A'));
                }
            }
            public void WhenLengthIsLessThanOne_ThenReturnEmptyArray(int length)
            {
                using (var sut = new CryptoRandomString(CharacterSets.Digits))
                {
                    var result = sut.GenerateArray(length);

                    Assert.That(result, Is.Empty);
                }
            }
            public void WhenMinIsMinusAndMaxIsZero_ThenReturnEmpty()
            {
                using (var sut = new CryptoRandomString(CharacterSets.Digits))
                {
                    var result = sut.GenerateArray(-1, 0);

                    Assert.That(result, Is.Empty);
                }
            }
            public void WhenLongEnoughLength_ThenUsesValidCharsEdgeCases()
            {
                using (var sut = new CryptoRandomString(CharacterSets.Digits))
                {
                    var result = sut.GenerateArray(1000);

                    Assert.That(result.Contains(CharacterSets.Digits.First()), Is.True);
                    Assert.That(result.Contains(CharacterSets.Digits.Last()), Is.True);
                }
            }
            public void WhenValidLength_ThenReturnCorrectLength()
            {
                const int length = 50;

                using (var sut = new CryptoRandomString(CharacterSets.Digits))
                {
                    var result = sut.GenerateArray(length);

                    Assert.That(result.Length, Is.EqualTo(length));
                }
            }
            public void WhenOnlyOneValidChar_ThenReturnSequenceOfChar()
            {
                using (var sut = new CryptoRandomString("A"))
                {
                    var result = sut.GenerateArray(3);

                    Assert.That(result.First(), Is.EqualTo('A'));
                    Assert.That(result.Second(), Is.EqualTo('A'));
                    Assert.That(result.Third(), Is.EqualTo('A'));
                }
            }