示例#1
0
            public void IsInvalidWhen_MatchesSamlEstablishment()
            {
                var validated = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var establishment = new Establishment
                {
                    IsMember     = true,
                    SamlSignOn   = new EstablishmentSamlSignOn(),
                    EmailDomains = new[] { new EstablishmentEmailDomain {
                                               Value = "@domain.tld"
                                           }, },
                };
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <Establishment>()).Returns(new[] { establishment }.AsQueryable);
                var validator = new ForgotPasswordValidator(entities.Object, null);

                var results = validator.Validate(validated);

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

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                                                   ForgotPasswordValidator.FailedBecauseEduPersonTargetedIdWasNotEmpty,
                                                   validated.EmailAddress.GetEmailDomain()));
                // ReSharper restore PossibleNullReferenceException
            }
示例#2
0
            public void IsInvalidWhen_MatchesPerson_WithNullUser()
            {
                var validated = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var establishment = new Establishment
                {
                    IsMember = true,
                };
                var person   = new Person();
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query <Person>()).Returns(new[] { person }.AsQueryable);
                var validator = new ForgotPasswordValidator(entities.Object, null);

                var results = validator.Validate(validated);

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

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                                                   ForgotPasswordValidator.FailedBecauseUserNameMatchedNoLocalMember,
                                                   validated.EmailAddress));
                // ReSharper restore PossibleNullReferenceException
            }
            public void HasPublicSetter()
            {
                var obj = new ForgotPasswordForm
                {
                    ReturnUrl = "/path/to/resource"
                };

                obj.ShouldNotBeNull();
            }
示例#4
0
            public void MapsIntent_UsingValue_EmailConfirmationIntent_ResetPassword()
            {
                var model = new ForgotPasswordForm();

                var command = Mapper.Map <SendConfirmEmailMessageCommand>(model);

                command.ShouldNotBeNull();
                command.Intent.ShouldEqual(EmailConfirmationIntent.ResetPassword);
            }
示例#5
0
            public void IgnoresConfirmationToken()
            {
                var model = new ForgotPasswordForm();

                var command = Mapper.Map <SendConfirmEmailMessageCommand>(model);

                command.ShouldNotBeNull();
                command.ConfirmationToken.ShouldEqual(Guid.Empty);
            }
示例#6
0
            public void MapsEmailAddress()
            {
                const string value = "*****@*****.**";
                var          model = new ForgotPasswordForm {
                    EmailAddress = value
                };

                var command = Mapper.Map <SendConfirmEmailMessageCommand>(model);

                command.ShouldNotBeNull();
                command.EmailAddress.ShouldNotBeNull();
                command.EmailAddress.ShouldEqual(model.EmailAddress);
            }
示例#7
0
            public void IsInvalidWhen_MatchesUnconfirmedEmailAddress()
            {
                var validated = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var person = new Person
                {
                    User = new User
                    {
                        Name = "*****@*****.**",
                    },
                    Emails = new[]
                    {
                        new EmailAddress
                        {
                            Value = validated.EmailAddress,
                        },
                    },
                };
                var establishment = new Establishment
                {
                    IsMember     = true,
                    EmailDomains = new[] { new EstablishmentEmailDomain {
                                               Value = "@domain.tld"
                                           }, },
                };
                var passwords = new Mock <IStorePasswords>(MockBehavior.Strict);

                passwords.Setup(m => m
                                .Exists(It.Is(IsSignedUpBasedOn(person))))
                .Returns(true);
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query <Person>()).Returns(new[] { person }.AsQueryable);
                var validator = new ForgotPasswordValidator(entities.Object, passwords.Object);

                var results = validator.Validate(validated);

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

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                                                   ValidateEmailAddress.FailedBecauseIsNotConfirmed,
                                                   validated.EmailAddress));
                // ReSharper restore PossibleNullReferenceException
            }
示例#8
0
            public void IsInvalidWhen_IsNull()
            {
                var validated = new ForgotPasswordForm();
                var validator = new ForgotPasswordValidator(null, null);

                var results = validator.Validate(validated);

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

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(
                    ForgotPasswordValidator.FailedBecauseEmailAddressWasEmpty);
                // ReSharper restore PossibleNullReferenceException
            }
示例#9
0
            public void IsValidWhen_MatchesPerson_WithNonSamlLocalUser_AndConfirmedEmailAddress()
            {
                var validated = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var person = new Person
                {
                    User = new User
                    {
                        Name = "*****@*****.**",
                    },
                    Emails = new[]
                    {
                        new EmailAddress
                        {
                            Value       = validated.EmailAddress,
                            IsConfirmed = true,
                        },
                    },
                };
                var establishment = new Establishment
                {
                    IsMember     = true,
                    EmailDomains = new[] { new EstablishmentEmailDomain {
                                               Value = "@domain.tld"
                                           }, },
                };
                var passwords = new Mock <IStorePasswords>(MockBehavior.Strict);

                passwords.Setup(m => m
                                .Exists(It.Is(IsSignedUpBasedOn(person))))
                .Returns(true);
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query <Person>()).Returns(new[] { person }.AsQueryable);
                var validator = new ForgotPasswordValidator(entities.Object, passwords.Object);

                var results = validator.Validate(validated);

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

                error.ShouldBeNull();
            }
            public void Implements_IReturnUrl()
            {
                var model = new ForgotPasswordForm();

                model.ShouldImplement <IReturnUrl>();
            }