static void Main(string[] args) { PasswordCheckerService checker = new PasswordCheckerService(new SqlRepository()); System.Console.WriteLine(checker.VerifyPassword(string.Empty).Item2); System.Console.WriteLine(checker.VerifyPassword("").Item2); System.Console.WriteLine(checker.VerifyPassword("12345").Item2); System.Console.WriteLine(checker.VerifyPassword("fdrkjgrdiflgjdiojg").Item2); System.Console.WriteLine(checker.VerifyPassword("sjferio").Item2); System.Console.ReadKey(); }
static void Main(string[] args) { IRepository repository = new SqlRepository(); PasswordCheckerService passwordCheckerService = new PasswordCheckerService(repository); string result = passwordCheckerService.VerifyPassword("helloIloveU", PasswordCheckerService.DigitCharactersPassWordChecker, PasswordCheckerService.EmptyPassWordChecker).Item2; System.Console.WriteLine(result); result = passwordCheckerService.VerifyPassword("helloIloveU", PasswordCheckerService.AlphabeticCharactersPassWordChecker, PasswordCheckerService.EmptyPassWordChecker).Item2; System.Console.WriteLine(result); System.Console.ReadKey(); }
static void Main(string[] args) { var rep = new SqlRepository(); string s = "23"; List <IRules> a = new List <IRules>(); a.Add(new ShortPassRule()); a.Add(new NullPassRule()); a.Add(new HasLetterPassRule()); System.Console.WriteLine(PasswordCheckerService.VerifyPassword(s, rep, a)); }
public void VerifyPasswordTests(string password, bool expected) { var repository = new SqlRepository(); var passwordCheckerService = new PasswordCheckerService(repository); var verifier = new PasswordVerifierBuilder().WithNoEmpty().WithMinLength(5).WithMaxLength(12).WithOneDigit().WithOneLetter().Build(); var result = passwordCheckerService.CheckPassword(password, verifier); Assert.AreEqual(expected, result.success); }
public bool VerifyPassword_ValidInput_ValidResult(string password) { List <IPasswordChecker> checkers = new List <IPasswordChecker>(2); checkers.Add(new LengthPasswordValidator(4)); checkers.Add(new NumberPasswordValidator()); SqlRepository repository = new SqlRepository(); var service = new PasswordCheckerService(repository); return(service.VerifyPassword(password, checkers).Item1); }
public void VerifyPassword_LengthFifteenValidator() { // Arrange PasswordCheckerService passwordCheckerService = new PasswordCheckerService(new SqlRepository(), new LengthFifteenValidator()); // Act (bool, string)result = passwordCheckerService.VerifyPassword("qwertyuiopasdfghjkqw"); //Assert Assert.AreEqual(false, result.Item1); Assert.AreEqual("password length too long", result.Item2); }
public void VerifyPassword_EmptyValidator() { // Arrange PasswordCheckerService passwordCheckerService = new PasswordCheckerService(new SqlRepository(), new DefaultEmptyValidator()); // Act (bool, string)result = passwordCheckerService.VerifyPassword(""); //Assert Assert.AreEqual(false, result.Item1); Assert.AreEqual("password is empty", result.Item2); }
public void TestDefaultValidator() { IRepository repository = new SqlRepository(); var pcs = new PasswordCheckerService(repository); Assert.That(pcs.VerifyPassword("pa55word").Item2, Is.EqualTo("Password is Ok. User was created")); Assert.That(pcs.VerifyPassword(string.Empty).Item2, Is.EqualTo("password is empty")); Assert.That(pcs.VerifyPassword("a1").Item2, Is.EqualTo("a1 length too short")); Assert.That(pcs.VerifyPassword("abcdef012345").Item2, Is.EqualTo("abcdef012345 length too long")); Assert.That(pcs.VerifyPassword("abcdefgh").Item2, Is.EqualTo("abcdefgh hasn't digits")); Assert.That(pcs.VerifyPassword("01234567").Item2, Is.EqualTo("01234567 hasn't alphanumerical chars")); }
public void Verify() { var checker = new Mock <IRepository>(); var verify = new VerifyPassword(); var passwordChecker = new PasswordCheckerService(checker.Object, verify); var(success, message) = passwordChecker.VerifyPassword(""); Assert.AreEqual((false, " is empty "), (success, message)); }
public void TestCustomValidator() { IRepository repository = new SqlRepository(); var pcs = new PasswordCheckerService(repository); Assert.That(pcs.VerifyPassword("pa55word", CustomValidator.Validate).Item2, Is.EqualTo("Password is Ok. User was created")); Assert.That(pcs.VerifyPassword(string.Empty, CustomValidator.Validate).Item2, Is.EqualTo("password is empty")); Assert.That(pcs.VerifyPassword("a1", CustomValidator.Validate).Item2, Is.EqualTo("a1 length too short")); Assert.That(pcs.VerifyPassword("abcdefgh0123456", CustomValidator.Validate).Item2, Is.EqualTo("abcdefgh0123456 length too long")); Assert.That(pcs.VerifyPassword("admin0", CustomValidator.Validate).Item2, Is.EqualTo("admin0 can't contain admin word")); Assert.That(pcs.VerifyPassword("abc123!", CustomValidator.Validate).Item2, Is.EqualTo("abc123! contains unavailable symbols")); }
public void VerifyPassword_ContainsCatDog_False_Test() { PasswordValidator validators = new PasswordValidator(PasswordContainsCat); validators += PasswordContainsDog; IRepository rep = new SqlRepository(); PasswordCheckerService service = new PasswordCheckerService(rep); Assert.False(service.VerifyPassword("catdg", validators).Item1); }
public string VerifyPassword_Result(string password) { var verifiers = new IVerifier[] { new MinLengthPasswordVerifier(), new DigitPasswordVerifier(), new LetterPasswordVerifier() }; PasswordCheckerService service = new PasswordCheckerService(new SqlRepository(), verifiers); return(service.VerifyPassword(password).ToString()); }
public void Mock_Test_Repository(string password) { rules.Add(new ShortPassRule()); rules.Add(new NullPassRule()); rules.Add(new HasLetterPassRule()); var repositoryMock = new Mock <IRepository>(); PasswordCheckerService.VerifyPassword(password, repositoryMock.Object, rules).ToString(); repositoryMock.Verify(repository => repository.Create(It.Is <string>(str => string.Equals(str, password, StringComparison.Ordinal))), Times.AtMostOnce()); }
public string VerifyPassword_Result(string password) { List <IVerifier> verifiers = new List <IVerifier>(); verifiers.Add(new MinLengthPasswordVerifier()); verifiers.Add(new MaxLengthPasswordVerifier()); verifiers.Add(new NumbersPasswordVerifier()); verifiers.Add(new LetterPasswordVerifier()); PasswordCheckerService service = new PasswordCheckerService(new SqlRepository(), verifiers); return(service.VerifyPassword(password).ToString()); }
static void Main(string[] args) { IRepository repository = new SqlRepository(); PasswordCheckerService service = new PasswordCheckerService(repository); List <ICheck> check = new List <ICheck>(); check.Add(new DefaultCheck()); //string password = "******"; string password = string.Empty; service.VerifyPassword(password, check); System.Console.WriteLine(service.VerifyPassword(password, check)); }
public void PasswordCheckerService_False(string password) { IChecker[] checker = { new CheckLogicEmpty(), new CheckLogicMinLength(7), new CheckLogicMaxLength(15), new CheckLogicContainLetter(), new CheckLogicContainNumber() }; var service = new PasswordCheckerService(new SqlRepository(), new CheckerAdapter(checker)); var expected = (false, ""); var actual = service.VerifyPassword(password); Assert.AreEqual(expected.Item1, actual.Item1); }
public void MainTest() { PasswordCheckerService checker = new PasswordCheckerService(); Assert.IsTrue(checker.VerifyPassword("Roman1998", new PasswordDefaultValidator(), new SqlRepository()).Item1); Console.WriteLine(checker.VerifyPassword("Roman1998", new PasswordDefaultValidator(), new SqlRepository()).Item2); Assert.IsFalse(checker.VerifyPassword("Roman", new PasswordDefaultValidator(), new SqlRepository()).Item1); Console.WriteLine(checker.VerifyPassword("Roman", new PasswordDefaultValidator(), new DefaultRepository()).Item2); }
public void PasswordCheckerService_Success() { IChecker[] checker = { new CheckLogicEmpty(), new CheckLogicMinLength(6), new CheckLogicMaxLength(15), new CheckLogicContainLetter(), new CheckLogicContainNumber() }; var service = new PasswordCheckerService(new SqlRepository(), new CheckerAdapter(checker)); var expected = (true, "Password is Ok. User was created"); var actual = service.VerifyPassword("password1"); Assert.AreEqual(expected.Item1, actual.Item1); Assert.AreEqual(expected.Item2, actual.Item2); }
public void Test2() { PasswordCheckerService pcService = new PasswordCheckerService(_repository); Tuple <bool, string> expTuple = DefaultVerify("Hello777r"); List <Tuple <bool, string> > list = new List <Tuple <bool, string> >(); list.Add(expTuple); var tuple = pcService.VerifyPassword("Hello777r", list); Assert.IsTrue(tuple); }
public Tuple <bool, string> VerifyPasswordCustomTest(string password) { var repository = new SqlRepository(); var verifyPassword = new PasswordCheckerService(repository); verifyPassword.AddChecker(pswd => { if (pswd == "qwerty1234") { return(Tuple.Create(false, $"{password} is very easy. For amebs")); } ; return(Tuple.Create(true, "Password is Ok. User was created")); }); return(verifyPassword.VerifyPassword(password)); }
public void VerifyPassword_OldCheckers_PasswordIsWrong() { string testPassword = "******"; IChecker[] checkers = { new EmptyChecker(), new AdminLengthChecker(), new CharacterChecker(), new DigitChecker(), new LengthChecker() }; var repMock = new Mock <IRepository>(); var passwordChecker = new PasswordCheckerService(repMock.Object, checkers); bool isRight; string message; (isRight, message) = passwordChecker.VerifyPassword(testPassword); Assert.IsFalse(isRight); }
public void VerifyPassword_CompositeValidator() { // Arrange IEnumerable <IValidator> validators = new List <IValidator>() { new LengthFifteenValidator() }; PasswordCheckerService passwordCheckerService = new PasswordCheckerService(new SqlRepository(), new CompositeValidator(validators)); // Act (bool, string)result = passwordCheckerService.VerifyPassword("qwertyuiopasdfghjkqw"); //Assert Assert.AreEqual(false, result.Item1); }
public string VerifyPassword_Result(string password) { List <IPasswordChecker> checkers = new List <IPasswordChecker> { new CheckerForNullOrEmpty(), new CheckerForMaxLength(), new CheckerForMinLength(), new CheckerForLetter(), new CheckerForDigits() }; PasswordCheckerService service = new PasswordCheckerService(new SqlRepository(), checkers); return(service.VerifyPassword(password).ToString()); }
static void Main(string[] args) { IRepository reposirory = new SqlRepository(); PasswordCheckerService checker = new PasswordCheckerService(reposirory); string password = System.Console.ReadLine(); List <IVerifier> verifiers = new List <IVerifier>() { new VerifierNumOfChars(), new VerifyCharacters() }; System.Console.WriteLine(checker.VerifyPassword(password, verifiers)); System.Console.ReadKey(); }
public void Initialization() { _filePath = "./Passwords.txt"; _passwordCheckService = new PasswordCheckerService(); _conditions = new Func <string, Tuple <bool, string> >[6] { (password) => (new Tuple <bool, string>(password == string.Empty, $"{password} is empty")), (password) => (new Tuple <bool, string>(password.Length <= 7, $"{password} length too short")), (password) => (new Tuple <bool, string>(password.Length >= 15, $"{password} length too long")), (password) => (new Tuple <bool, string>(!password.Any(char.IsLetter), $"{password} hasn't alphanumerical chars")), (password) => (new Tuple <bool, string>(!password.Any(char.IsNumber), $"{password} hasn't digits")), (password) => (new Tuple <bool, string>(!char.IsUpper(password[0]), $"{password} must starts with upper letter")) }; }
public void ValidatePassword_InvalidPasswordPassed_RepositoryCreateIsNotCalled() { var password = "******"; var repositoryMock = new Mock <IRepository>(); var passwordValidator = new Mock <IPasswordValidator>(); repositoryMock.Setup(repository => repository.Create(It.IsAny <string>())); passwordValidator.Setup(validator => validator.Validate(It.IsAny <string>())) .Returns(Tuple.Create(false, "")); var service = new PasswordCheckerService(repositoryMock.Object); service.ValidatePassword(password, passwordValidator.Object); repositoryMock.Verify(repository => repository.Create(It.IsAny <string>()), Times.Never()); }
public void VerifyPassword_IEnumerable_ContainsCatDog_False_Test() { List <IPasswordValidator> validators = new List <IPasswordValidator>() { new PasswordShouldContainCat(), new PasswordShouldContainDog() }; IRepository rep = new SqlRepository(); PasswordCheckerService service = new PasswordCheckerService(rep); var result = service.VerifyPassword("catdg", validators); Assert.False(result.Item1, result.Item2); }
public void DifferentConditionalTets() { string password = "******"; List <IVerify> conditions = new List <IVerify> { new CheckEmpty(), new CheckContainsDigit(), new CheckLengthTooBig() }; var combination = new CompositeConditions(conditions); PasswordCheckerService service = new PasswordCheckerService(new SqlRepository(), combination); Assert.IsFalse(service.VerifyPassword(password).Item1); }
public void VerifyPassword_SomeChecker_PasswordIsWrong() { string testPassword = "******"; var checkerMock = new Mock <IChecker>(); checkerMock.Setup(m => m.Check(testPassword)).Returns((false, "")); var repMock = new Mock <IRepository>(); var passwordChecker = new PasswordCheckerService(repMock.Object, new IChecker[] { checkerMock.Object }); bool isRight; string message; (isRight, message) = passwordChecker.VerifyPassword(testPassword); Assert.IsFalse(isRight); checkerMock.Verify(m => m.Check(testPassword)); }
static void Main(string[] args) { var repository = new SqlRepository(); var verifier = new Verifier { new PasswordVerification() }; var checkerService = new PasswordCheckerService(repository); Console.WriteLine(checkerService.VerifyPassword("", verifier).Item2); Console.WriteLine(checkerService.VerifyPassword("abc", verifier).Item2); Console.WriteLine(checkerService.VerifyPassword("abcabcabcabcabcabc", verifier).Item2); Console.WriteLine(checkerService.VerifyPassword("awdwadawdawd", verifier).Item2); Console.WriteLine(checkerService.VerifyPassword("qwerty123", verifier).Item2); Console.ReadKey(); }