public void IsInvalid_WhenPassword_IsNotVerified_AndUserExists() { const string userName = "******"; const string password = "******"; var queries = new Mock <IProcessQueries>(MockBehavior.Strict); var validator = new ValidateSignInCommand(queries.Object); var command = new SignIn { UserNameOrVerifiedEmail = userName, Password = password, }; Expression <Func <IsPasswordVerified, bool> > expectedQuery = x => x.UserNameOrVerifiedEmail == command.UserNameOrVerifiedEmail && x.Password == command.Password; queries.Setup(x => x.Execute(It.Is(expectedQuery))).Returns(Task.FromResult(false)); Expression <Func <UserByNameOrVerifiedEmail, bool> > userQuery = x => x.NameOrEmail == command.UserNameOrVerifiedEmail; queries.Setup(x => x.Execute(It.Is(userQuery))).Returns(Task.FromResult(new User())); var result = validator.Validate(command); result.IsValid.ShouldBeFalse(); Func <ValidationFailure, bool> targetError = x => x.PropertyName == command.PropertyName(y => y.Password); result.Errors.Count(targetError).ShouldEqual(1); result.Errors.Single(targetError).ErrorMessage.ShouldEqual(Resources.Validation_InvalidPassword); queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once); queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once); }
public void PasswordIsValid_WhenNoUserExists() { var userName = FakeData.String(); var password = FakeData.String(); var queries = new Mock <IProcessQueries>(MockBehavior.Strict); var validator = new ValidateSignInCommand(queries.Object); var command = new SignIn { UserNameOrVerifiedEmail = userName, Password = password, }; Expression <Func <IsPasswordVerified, bool> > expectedQuery = x => x.UserNameOrVerifiedEmail == command.UserNameOrVerifiedEmail && x.Password == command.Password; Expression <Func <UserByNameOrVerifiedEmail, bool> > userById = x => x.NameOrEmail == command.UserNameOrVerifiedEmail; queries.Setup(x => x.Execute(It.Is(expectedQuery))).Returns(Task.FromResult(false)); queries.Setup(x => x.Execute(It.Is(userById))).Returns(Task.FromResult(null as User)); var result = validator.Validate(command); result.IsValid.ShouldBeFalse(); Func <ValidationFailure, bool> targetError = x => x.PropertyName == command.PropertyName(y => y.Password); result.Errors.Count(targetError).ShouldEqual(0); queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Never); queries.Verify(x => x.Execute(It.Is(userById)), Times.Exactly(2)); }
public void IsInvalid_WhenPassword_IsEmpty(string password) { var queries = new Mock <IProcessQueries>(MockBehavior.Strict); var validator = new ValidateSignInCommand(queries.Object); var command = new SignIn { Password = password }; var result = validator.Validate(command); result.IsValid.ShouldBeFalse(); Func <ValidationFailure, bool> targetError = x => x.PropertyName == command.PropertyName(y => y.Password); result.Errors.Count(targetError).ShouldEqual(1); result.Errors.Single(targetError).ErrorMessage .ShouldEqual(Resources.notempty_error.Replace("{PropertyName}", LocalMembership.Constraints.PasswordLabel)); queries.Verify(x => x.Execute(It.IsAny <IsPasswordVerified>()), Times.Never); }
public void IsInvalid_WhenUserName_IsEmpty(string userName) { var queries = new Mock <IProcessQueries>(MockBehavior.Strict); var validator = new ValidateSignInCommand(queries.Object); var command = new SignIn { UserNameOrVerifiedEmail = userName }; var result = validator.Validate(command); result.IsValid.ShouldBeFalse(); Func <ValidationFailure, bool> targetError = x => x.PropertyName == command.PropertyName(y => y.UserNameOrVerifiedEmail); result.Errors.Count(targetError).ShouldEqual(1); result.Errors.Single(targetError).ErrorMessage .ShouldEqual(Resources.notempty_error.Replace("{PropertyName}", string.Format("{0} or {1}", User.Constraints.NameLabel, EmailAddress.Constraints.Label))); queries.Verify(x => x.Execute(It.IsAny <UserBy>()), Times.Never); }
public void IsInvalid_WhenUserName_MatchesNoUserOrEmail() { const string userName = "******"; var queries = new Mock <IProcessQueries>(MockBehavior.Strict); var validator = new ValidateSignInCommand(queries.Object); var command = new SignIn { UserNameOrVerifiedEmail = userName }; Expression <Func <UserByNameOrVerifiedEmail, bool> > userById = x => x.NameOrEmail == command.UserNameOrVerifiedEmail; queries.Setup(x => x.Execute(It.Is(userById))).Returns(Task.FromResult(null as User)); var result = validator.Validate(command); result.IsValid.ShouldBeFalse(); Func <ValidationFailure, bool> targetError = x => x.PropertyName == command.PropertyName(y => y.UserNameOrVerifiedEmail); result.Errors.Count(targetError).ShouldEqual(1); result.Errors.Single(targetError).ErrorMessage .ShouldEqual(Resources.Validation_CouldNotFind .Replace("{PropertyName}", string.Format("{0} or {1}", User.Constraints.NameLabel, EmailAddress.Constraints.Label).ToLower()) .Replace("{PropertyValue}", command.UserNameOrVerifiedEmail)); queries.Verify(x => x.Execute(It.Is(userById)), Times.Once); }