Пример #1
0
            public void IsInvalidWhen_IsIncorrectMatch()
            {
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword)
                {
                    Ticket = "ticket1",
                };
                var command = new ResetPasswordCommand
                {
                    Token  = confirmation.Token,
                    Ticket = "ticket2",
                };
                var scenarioOptions = new ScenarioOptions
                {
                    EmailConfirmation = confirmation,
                    Command           = command,
                };
                var validator = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Ticket");

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                                                   ValidateEmailConfirmation.FailedBecauseTicketWasIncorrect,
                                                   command.Ticket, confirmation.Token));
                // ReSharper restore PossibleNullReferenceException
            }
Пример #2
0
            public void IsInvalidWhen_MatchesExpiredEntity()
            {
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword)
                {
                    ExpiresOnUtc = DateTime.UtcNow.AddMinutes(-1),
                };
                var command = new ResetPasswordCommand
                {
                    Token = confirmation.Token,
                };
                var scenarioOptions = new ScenarioOptions
                {
                    EmailConfirmation = confirmation,
                    Command           = command,
                };
                var validator = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Token");

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                                                   ValidateEmailConfirmation.FailedBecauseIsExpired,
                                                   confirmation.Token, confirmation.ExpiresOnUtc));
                // ReSharper restore PossibleNullReferenceException
            }
Пример #3
0
            public void IsInvalidWhen_MatchesNoEntity()
            {
                var command = new ResetPasswordCommand
                {
                    Token = Guid.NewGuid()
                };
                var scenarioOptions = new ScenarioOptions
                {
                    Command           = command,
                    EmailConfirmation = new EmailConfirmation(EmailConfirmationIntent.CreatePassword),
                };
                var validator = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Token");

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                                                   ValidateEmailConfirmation.FailedBecauseTokenMatchedNoEntity,
                                                   command.Token));
                // ReSharper restore PossibleNullReferenceException
            }
Пример #4
0
            public void IsValidWhen_Length_IsSixCharactersOrMore()
            {
                var command = new ResetPasswordCommand {
                    Password = "******"
                };
                var scenarioOptions = new ScenarioOptions();
                var validator       = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Password");

                error.ShouldBeNull();
            }
Пример #5
0
            public void IsValidWhen_IsNotEmpty_AndConfirmationWasNull()
            {
                var command = new ResetPasswordCommand {
                    Ticket = "test"
                };
                var scenarioOptions = new ScenarioOptions();
                var validator       = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Ticket");

                error.ShouldBeNull();
            }
Пример #6
0
            public void IsValidWhen_EqualsPassword_AndPasswordIsValid()
            {
                var command = new ResetPasswordCommand
                {
                    Password             = "******",
                    PasswordConfirmation = "123456",
                };
                var scenarioOptions = new ScenarioOptions();
                var validator       = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "PasswordConfirmation");

                error.ShouldBeNull();
            }
Пример #7
0
            public void IsInvalidWhen_IsNull()
            {
                var command         = new ResetPasswordCommand();
                var scenarioOptions = new ScenarioOptions();
                var validator       = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "PasswordConfirmation");

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(
                    ValidatePassword.FailedBecausePasswordConfirmationWasEmpty);
                // ReSharper restore PossibleNullReferenceException
            }
Пример #8
0
            public void IsInvalidWhen_MatchesUser_WithNoLocalAccount()
            {
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword)
                {
                    RedeemedOnUtc = DateTime.UtcNow,
                    ExpiresOnUtc  = DateTime.UtcNow.AddMinutes(1),
                    EmailAddress  = new EmailAddress
                    {
                        IsConfirmed = true,
                        Person      = new Person
                        {
                            User = new User
                            {
                                Name = "something",
                            }
                        }
                    }
                };
                var command = new ResetPasswordCommand
                {
                    Token = confirmation.Token,
                };
                var scenarioOptions = new ScenarioOptions
                {
                    EmailConfirmation = confirmation,
                    Command           = command,
                };
                var validator = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Token");

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                                                   ValidateUser.FailedBecauseNameMatchedNoLocalMember,
                                                   confirmation.EmailAddress.Person.User.Name));
                // ReSharper restore PossibleNullReferenceException
            }
Пример #9
0
            public void IsInvalidWhen_Length_IsLessThanSixCharacters()
            {
                var command = new ResetPasswordCommand {
                    Password = "******"
                };
                var scenarioOptions = new ScenarioOptions
                {
                    MinimumPasswordLength = 6,
                };
                var validator = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Password");

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(
                    ValidatePassword.FailedBecausePasswordWasTooShort(6));
                // ReSharper restore PossibleNullReferenceException
            }
Пример #10
0
            public void IsValidWhen_IsNotEmpty_AndIsCorrectMatch()
            {
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword)
                {
                    Ticket = "tomato",
                };
                var command = new ResetPasswordCommand
                {
                    Token  = confirmation.Token,
                    Ticket = "tomato"
                };
                var scenarioOptions = new ScenarioOptions
                {
                    EmailConfirmation = confirmation,
                    Command           = command,
                };
                var validator = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Ticket");

                error.ShouldBeNull();
            }
Пример #11
0
            public void IsValidWhen_MatchesEntity_Intended_Unexpired_Unretired_Redeemed_WithNonSamlLocalUser()
            {
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword)
                {
                    ExpiresOnUtc  = DateTime.UtcNow.AddMinutes(1),
                    RedeemedOnUtc = DateTime.UtcNow,
                    EmailAddress  = new EmailAddress
                    {
                        IsConfirmed = true,
                        Person      = new Person
                        {
                            User = new User
                            {
                                Name = "local"
                            }
                        }
                    }
                };
                var command = new ResetPasswordCommand
                {
                    Token = confirmation.Token,
                };
                var scenarioOptions = new ScenarioOptions
                {
                    Command           = command,
                    EmailConfirmation = confirmation,
                    LocalMemberExists = true,
                };
                var validator = CreateValidator(scenarioOptions);

                var results = validator.Validate(command);

                var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Token");

                error.ShouldBeNull();
            }