public void Generate_GeneratesPasswordWithLettersAndNumbers() {
     var gen = new PasswordGenerator();
     for (var i = 0; i < 10; i++) {
         var pass = gen.Generate();
         Assert.IsTrue(pass.All(c => char.IsLetterOrDigit(c)));
     }
 }
 public void Generate_GeneratesPasswordWithLength() {
     var gen = new PasswordGenerator();
     foreach (var i in new[] { 0, 1, 5, 50, 500 }) {
         gen.Length = i;
         var pass = gen.Generate();
         Assert.AreEqual(i, pass.Length);
     }
 }
 public void ConfigurePasswordGenerator(PasswordGenerator passwordGenerator) {
     var element = Section;
     if (element != null) {
         var elementInformation = element.ElementInformation;
         if (elementInformation != null && elementInformation.IsPresent) {
             element.ConfigurePasswordGenerator(passwordGenerator);
         }
     }
 }
 public void Symbols_ContainsAllDigitsAndLetters() {
     var gen = new PasswordGenerator();
     var sym = gen.Symbols;
     var lower = "abcdefghijklmnopqrstuvwxyz";
     var upper = lower.ToUpperInvariant();
     var digits = "0123456789";
     var all = lower + upper + digits;
     Assert.AreEqual(all.Length, sym.Length);
     Assert.IsTrue(all.All(c => sym.Contains(c)));
 }
 public void Symbols_NullThrowsException() {
     var gen = new PasswordGenerator();
     var exception = default(ArgumentNullException);
     try {
         gen.Symbols = null;
     }
     catch (ArgumentNullException ex) {
         exception = ex;
     }
     Assert.AreEqual("Symbols", exception.ParamName);
 }
Ejemplo n.º 6
0
        public void Symbols_ContainsAllDigitsAndLetters()
        {
            var gen    = new PasswordGenerator();
            var sym    = gen.Symbols;
            var lower  = "abcdefghijklmnopqrstuvwxyz";
            var upper  = lower.ToUpperInvariant();
            var digits = "0123456789";
            var all    = lower + upper + digits;

            Assert.AreEqual(all.Length, sym.Length);
            Assert.IsTrue(all.All(c => sym.Contains(c)));
        }
Ejemplo n.º 7
0
        public void Symbols_NullThrowsException()
        {
            var gen       = new PasswordGenerator();
            var exception = default(ArgumentNullException);

            try {
                gen.Symbols = null;
            }
            catch (ArgumentNullException ex) {
                exception = ex;
            }
            Assert.AreEqual("Symbols", exception.ParamName);
        }
Ejemplo n.º 8
0
        public void Constructor_PropertiesDefaultIfSectionDoesNotExistInAppConfig()
        {
            var appConfig = @"<?xml version='1.0'?>
                <configuration>
                </configuration>
            ";

            using (AppConfig.With(appConfig)) {
                var gen = new PasswordGenerator();
                Assert.AreEqual(10, gen.Length);
                Assert.AreEqual("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", gen.Symbols);
            }
        }
Ejemplo n.º 9
0
        public void Symbols_EmptyStringThrowsException()
        {
            var gen       = new PasswordGenerator();
            var exception = default(ArgumentException);

            try {
                gen.Symbols = "";
            }
            catch (ArgumentException ex) {
                exception = ex;
            }
            Assert.IsNotNull(exception);
            Assert.AreEqual("Symbols", exception.ParamName);
        }
 public void Length_LessThanZeroThrowsException() {
     var gen = new PasswordGenerator();
     foreach (var i in new[] { -1, -5, -50 }) {
         var exception = default(ArgumentOutOfRangeException);
         try {
             gen.Length = i;
         }
         catch (ArgumentOutOfRangeException ex) {
             exception = ex;
         }
         Assert.IsNotNull(exception);
         Assert.AreEqual("Length", exception.ParamName);
         Assert.AreEqual(i, exception.ActualValue);
     }
 }
Ejemplo n.º 11
0
        public void Length_LessThanZeroThrowsException()
        {
            var gen = new PasswordGenerator();

            foreach (var i in new[] { -1, -5, -50 })
            {
                var exception = default(ArgumentOutOfRangeException);
                try {
                    gen.Length = i;
                }
                catch (ArgumentOutOfRangeException ex) {
                    exception = ex;
                }
                Assert.IsNotNull(exception);
                Assert.AreEqual("Length", exception.ParamName);
                Assert.AreEqual(i, exception.ActualValue);
            }
        }
Ejemplo n.º 12
0
        public void Constructor_PropertiesDefaultIfNotSetInAppConfig()
        {
            var appConfig = @"<?xml version='1.0'?>
                <configuration>
                    <configSections>
                        <section name='ensues.security' type='Ensues.Configuration.SecuritySection, Ensues.Security' />
                    </configSections>
                    <ensues.security>
                        <passwordGenerator />
                    </ensues.security>
                </configuration>
            ";

            using (AppConfig.With(appConfig)) {
                var gen = new PasswordGenerator();
                Assert.AreEqual(10, gen.Length);
                Assert.AreEqual("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", gen.Symbols);
            }
        }
Ejemplo n.º 13
0
        public void Constructor_PropertiesSetViaAppConfig()
        {
            var appConfig = @"<?xml version='1.0'?>
                <configuration>
                    <configSections>
                        <section name='ensues.security' type='Ensues.Configuration.SecuritySection, Ensues.Security' />
                    </configSections>
                    <ensues.security>
                        <passwordGenerator length='100' symbols='abcdefghijklmnopqrstuvwxyz' />
                    </ensues.security>
                </configuration>
            ";

            using (AppConfig.With(appConfig)) {
                var gen = new PasswordGenerator();
                Assert.AreEqual(100, gen.Length);
                Assert.AreEqual("abcdefghijklmnopqrstuvwxyz", gen.Symbols);
            }
        }
 public void ConfigurePasswordGenerator_ConfiguresInstance() {
     var appConfig = @"<?xml version='1.0'?>
         <configuration>
             <configSections>
                 <section name='ensues.security' type='Ensues.Configuration.SecuritySection, Ensues.Security' />
             </configSections>
             <ensues.security>
                 <passwordAlgorithm hashFunction='SHA384' hashIterations='123456' compareInConstantTime='false' saltLength='321' />
                 <passwordGenerator length='100' symbols='abcdefghijklmnopqrstuvwxyz' />
             </ensues.security>
         </configuration>
     ";
     using (AppConfig.With(appConfig)) {
         var gen = new PasswordGenerator();
         SecurityConfiguration.Default.ConfigurePasswordGenerator(gen);
         Assert.AreEqual(100, gen.Length);
         Assert.AreEqual("abcdefghijklmnopqrstuvwxyz", gen.Symbols);
     }
 }
 public void Symbols_EmptyStringThrowsException() {
     var gen = new PasswordGenerator();
     var exception = default(ArgumentException);
     try {
         gen.Symbols = "";
     }
     catch (ArgumentException ex) {
         exception = ex;
     }
     Assert.IsNotNull(exception);
     Assert.AreEqual("Symbols", exception.ParamName);
 }
 public void Generate_GeneratesEmptyPassword() {
     var gen = new PasswordGenerator { Length = 0 };
     Assert.AreEqual("", gen.Generate());
 }
 public void Generate_GeneratesWithOneSymbol() {
     var gen = new PasswordGenerator();
     gen.Symbols = "1";
     gen.Length = 50;
     var pass = gen.Generate();
     var expected = new string(Enumerable.Range(0, 50).Select(_ => '1').ToArray());
     Assert.AreEqual(expected, pass);
 }
 public void Generate_GeneratesString() {
     var gen = new PasswordGenerator();
     var pass = gen.Generate();
     Assert.IsNotNull(pass);
     Assert.AreNotEqual("", pass);
 }
 public void Generate_Generates10CharacterPassword() {
     var gen = new PasswordGenerator();
     var pass = gen.Generate();
     Assert.AreEqual(10, pass.Length);
 }
 public void Constructor_PropertiesDefaultIfSectionDoesNotExistInAppConfig() {
     var appConfig = @"<?xml version='1.0'?>
         <configuration>
         </configuration>
     ";
     using (AppConfig.With(appConfig)) {
         var gen = new PasswordGenerator();
         Assert.AreEqual(10, gen.Length);
         Assert.AreEqual("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", gen.Symbols);
     }
 }
 public void Constructor_PropertiesDefaultIfNotSetInAppConfig() {
     var appConfig = @"<?xml version='1.0'?>
         <configuration>
             <configSections>
                 <section name='ensues.security' type='Ensues.Configuration.SecuritySection, Ensues.Security' />
             </configSections>
             <ensues.security>
                 <passwordGenerator />
             </ensues.security>
         </configuration>
     ";
     using (AppConfig.With(appConfig)) {
         var gen = new PasswordGenerator();
         Assert.AreEqual(10, gen.Length);
         Assert.AreEqual("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", gen.Symbols);
     }
 }
 public void Generate_GeneratesPasswordWithSymbols() {
     var gen = new PasswordGenerator();
     gen.Symbols = "?$%";
     var pass = gen.Generate();
     Assert.IsTrue(pass.All(c => "?$%".Contains(c)));
 }
 public void Generate_GeneratesRandomPassword() {
     var gen = new PasswordGenerator();
     var passwords = Enumerable.Range(0, 1000).Select(_ => gen.Generate()).ToList();
     Assert.AreEqual(1000, passwords.Distinct().Count());
 }
 public void ConfigurePasswordGenerator(PasswordGenerator passwordGenerator) {
     if (null == passwordGenerator) throw new ArgumentNullException("passwordGenerator");
     passwordGenerator.Length = Length;
     passwordGenerator.Symbols = Symbols;
 }
 public void Constructor_PropertiesSetViaAppConfig() {
     var appConfig = @"<?xml version='1.0'?>
         <configuration>
             <configSections>
                 <section name='ensues.security' type='Ensues.Configuration.SecuritySection, Ensues.Security' />
             </configSections>
             <ensues.security>
                 <passwordGenerator length='100' symbols='abcdefghijklmnopqrstuvwxyz' />
             </ensues.security>
         </configuration>
     ";
     using (AppConfig.With(appConfig)) {
         var gen = new PasswordGenerator();
         Assert.AreEqual(100, gen.Length);
         Assert.AreEqual("abcdefghijklmnopqrstuvwxyz", gen.Symbols);
     }
 }