Esempio n. 1
0
        public void Database_DefaultConstructor_AssignsPasswordsList()
        {
            var sut = new sut.Database();

            Assert.NotNull(sut.Passwords);
            Assert.Empty(sut.Passwords);
        }
Esempio n. 2
0
        public void ImportFile_GoodStrings_AddsPasswords()
        {
            var list    = new List <IPassword>();
            var reader  = new Mock <IFileReader>();
            var factory = new CharacterPositionPasswordPolicyFactory();

            reader.Setup(r => r.ReadFileByLines(It.IsAny <string>())).Returns(new string[]
            {
                "1-3 a: abcde",
                "1-3 b: cdefg",
                "2-9 c: ccccccccc"
            });

            var sut = new sut.Database(list, reader.Object, factory);

            Assert.Empty(sut.Passwords);

            sut.Import(string.Empty);

            Assert.NotEmpty(sut.Passwords);
            Assert.Equal(3, sut.Passwords.Count);
            Assert.Contains(new Password("1-3 a: abcde", factory), sut.Passwords);
            Assert.Contains(new Password("1-3 b: cdefg", factory), sut.Passwords);
            Assert.Contains(new Password("2-9 c: ccccccccc", factory), sut.Passwords);
        }
Esempio n. 3
0
        public void ImportStrings_GoodStrings_AddsPasswords()
        {
            var sut = new sut.Database();

            Assert.Empty(sut.Passwords);

            sut.Import(new string[]
            {
                "1-3 a: abcde",
                "1-3 b: cdefg",
                "2-9 c: ccccccccc"
            });

            Assert.NotEmpty(sut.Passwords);
            Assert.Equal(3, sut.Passwords.Count);
            Assert.Contains(new Password("1-3 a: abcde"), sut.Passwords);
            Assert.Contains(new Password("1-3 b: cdefg"), sut.Passwords);
            Assert.Contains(new Password("2-9 c: ccccccccc"), sut.Passwords);

            var factory = new CharacterPositionPasswordPolicyFactory();

            Assert.DoesNotContain(new Password("1-3 a: abcde", factory), sut.Passwords);
            Assert.DoesNotContain(new Password("1-3 b: cdefg", factory), sut.Passwords);
            Assert.DoesNotContain(new Password("2-9 c: ccccccccc", factory), sut.Passwords);
        }
Esempio n. 4
0
        public void Add_BadString_ThrowsExceptionAndDoesNotAdd()
        {
            var passwordString = "asdf";
            var sut            = new sut.Database();

            Assert.Empty(sut.Passwords);

            Assert.Throws <ArgumentException>(() => { sut.Add(passwordString); });

            Assert.Empty(sut.Passwords);
        }
Esempio n. 5
0
        public void Add_Password_AddsPassword()
        {
            var password = new Password("4-5 d: lkjlkddddoiuoiuou");
            var sut      = new sut.Database();

            Assert.Empty(sut.Passwords);

            sut.Add(password);

            Assert.Contains(password, sut.Passwords);
        }
Esempio n. 6
0
        public void Add_GoodString_AddsPassword()
        {
            var passwordString = "4-5 d: lkjlkddddoiuoiuou";
            var password       = new Password(passwordString);
            var sut            = new sut.Database();

            Assert.Empty(sut.Passwords);

            sut.Add(passwordString);

            Assert.Contains(password, sut.Passwords);
        }
Esempio n. 7
0
        public void Database_SpecificConstructor_ContainsProvidedList()
        {
            var passwordList = new List <IPassword>();

            passwordList.Add(new Password("1-2 a: aabuiyoiuy"));

            var sut = new sut.Database(
                passwordList,
                new FileReader(),
                new CharacterFrequencyPasswordPolicyFactory()
                );

            foreach (var password in passwordList)
            {
                Assert.Contains(password, sut.Passwords);
            }

            foreach (var password in sut.Passwords)
            {
                Assert.Contains(password, passwordList);
            }
        }
Esempio n. 8
0
        public void ImportStrings_BadStrings_AddsNoPasswords()
        {
            var sut = new sut.Database();

            Assert.Empty(sut.Passwords);

            Assert.Throws <ArgumentException>(
                () => {
                sut.Import(
                    new string[]
                {
                    "1-3 a: abcde",
                    "1-3 b: cdefg",
                    "2-9 c: ccccccccc",
                    "asdasfgasfasdfas"
                }
                    );
            }
                );

            Assert.Empty(sut.Passwords);
        }
Esempio n. 9
0
        public void ImportFile_BadStrings_AddsNoPasswords()
        {
            var list    = new List <IPassword>();
            var reader  = new Mock <IFileReader>();
            var factory = new CharacterFrequencyPasswordPolicyFactory();

            reader.Setup(r => r.ReadFileByLines(It.IsAny <string>())).Returns(new string[]
            {
                "1-3 a: abcde",
                "1-3 b: cdefg",
                "2-9 c: ccccccccc",
                "asdasfgasfasdfas"
            });

            var sut = new sut.Database(list, reader.Object, factory);

            Assert.Empty(sut.Passwords);

            Assert.Throws <ArgumentException>(() => { sut.Import(string.Empty); });

            Assert.Empty(sut.Passwords);
        }