Beispiel #1
0
 public static string Create(string prefix)
 {
     using (var r = new CryptoRandom(CharacterSets.AlphaNumeric))
     {
         return(prefix + "-" + r.GenerateString(10));
     }
 }
            public void WhenMinIsLessThanMax_ThenReturnRandomLength()
            {
                var createdLen2 = false;
                var createdLen3 = false;

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

                        Assert.That(result, Is.EqualTo("AA").Or.EqualTo("AAA"));

                        if (result.Length == 2)
                        {
                            createdLen2 = true;
                        }

                        if (result.Length == 3)
                        {
                            createdLen3 = true;
                        }
                    }
                }

                Assert.That(createdLen2, Is.True);
                Assert.That(createdLen3, Is.True);
            }
            public void WhenLongEnoughLength_ThenUsesValidCharsEdgeCases()
            {
                using (var sut = new CryptoRandom(CharacterSets.Digits))
                {
                    var result = sut.GenerateString(1000, 2000);

                    StringAssert.Contains(CharacterSets.Digits[0].ToString(), result);
                    StringAssert.Contains(CharacterSets.Digits[9].ToString(), result);
                }
            }