Esempio n. 1
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
            }
Esempio n. 2
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
            }
Esempio n. 3
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
            }
Esempio n. 4
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
            }
Esempio n. 5
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();
            }