Exemple #1
0
            public void IsValidWhen_MatchesEmail_ForPrincipal()
            {
                const string principalIdentityName = "*****@*****.**";
                var          principal             = principalIdentityName.AsPrincipal();
                var          command = new UpdateMyEmailValueCommand
                {
                    Principal = principal,
                    Number    = 1,
                    NewValue  = principalIdentityName.ToUpper(),
                };
                var emailAddress = new EmailAddress
                {
                    Number = command.Number,
                    Value  = command.NewValue,
                    Person = new Person
                    {
                        User = new User
                        {
                            Name = principal.Identity.Name,
                        },
                    },
                };
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <EmailAddress>()).Returns(new[] { emailAddress }.AsQueryable);
                entities.Setup(m => m.Query <User>()).Returns(new User[] { }.AsQueryable);
                var validator = new UpdateMyEmailValueValidator(entities.Object);

                var results = validator.Validate(command);

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

                error.ShouldBeNull();
            }
Exemple #2
0
            public void IsInvalidWhen_DoesNotMatchEmail_ForPrincipal()
            {
                const string principalIdentityName = "*****@*****.**";
                var          principal             = principalIdentityName.AsPrincipal();
                var          command = new UpdateMyEmailValueCommand
                {
                    Principal = principal,
                    Number    = 11,
                };
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <User>()).Returns(new User[] { }.AsQueryable);
                entities.Setup(m => m.Query <EmailAddress>()).Returns(new EmailAddress[] { }.AsQueryable);
                var validator = new UpdateMyEmailValueValidator(entities.Object);

                var results = validator.Validate(command);

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

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                                                   ValidateEmailAddress.FailedBecauseNumberAndPrincipalMatchedNoEntity,
                                                   command.Number, command.Principal.Identity.Name));
                // ReSharper restore PossibleNullReferenceException
            }
Exemple #3
0
            public void IsValidWhen_EmailAddressWasNull()
            {
                var command = new UpdateMyEmailValueCommand {
                    NewValue = "*****@*****.**",
                };
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <EmailAddress>()).Returns(new EmailAddress[] { }.AsQueryable);
                var validator = new UpdateMyEmailValueValidator(entities.Object);

                var results = validator.Validate(command);

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

                error.ShouldBeNull();
            }
Exemple #4
0
            public void IsInvalidWhen_IsWhiteSpace()
            {
                var command = new UpdateMyEmailValueCommand {
                    NewValue = "\t"
                };
                var validator = new UpdateMyEmailValueValidator(null);

                var results = validator.Validate(command);

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

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(ValidateEmailAddress.FailedBecauseValueWasEmpty);
                // ReSharper restore PossibleNullReferenceException
            }
Exemple #5
0
            public void IsInvalidWhen_IsNull()
            {
                var command = new UpdateMyEmailValueCommand {
                    Principal = null
                };
                var validator = new UpdateMyEmailValueValidator(null);

                var results = validator.Validate(command);

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

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(ValidatePrincipal.FailedBecausePrincipalWasNull);
                // ReSharper restore PossibleNullReferenceException
            }
Exemple #6
0
            public void IsValidWhen_MatchesPreviousSpelling_CaseInsensitively()
            {
                var command = new UpdateMyEmailValueCommand {
                    NewValue = "*****@*****.**",
                };
                var emailAddress = new EmailAddress {
                    Value = "*****@*****.**"
                };
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <EmailAddress>()).Returns(new[] { emailAddress }.AsQueryable);
                var validator = new UpdateMyEmailValueValidator(entities.Object);

                var results = validator.Validate(command);

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

                error.ShouldBeNull();
            }
Exemple #7
0
            public void IsInvalidWhen_DoesNotMatchPreviousSpelling_CaseInsensitively()
            {
                const string principalIdentityName = "*****@*****.**";
                var          principal             = principalIdentityName.AsPrincipal();
                var          command = new UpdateMyEmailValueCommand
                {
                    Principal = principal,
                    NewValue  = "*****@*****.**",
                };
                var emailAddress = new EmailAddress
                {
                    Value  = "*****@*****.**",
                    Person = new Person
                    {
                        User = new User
                        {
                            Name = principal.Identity.Name,
                        },
                    },
                };
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <User>()).Returns(new User[] { }.AsQueryable);
                entities.Setup(m => m.Query <EmailAddress>()).Returns(new[] { emailAddress }.AsQueryable);
                var validator = new UpdateMyEmailValueValidator(entities.Object);

                var results = validator.Validate(command);

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

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                                                   ValidateEmailAddress.FailedBecauseNewValueDidNotMatchCurrentValueCaseInvsensitively,
                                                   command.NewValue));
                // ReSharper restore PossibleNullReferenceException
            }
Exemple #8
0
            public void IsInvalidWhen_FailsEmailAddressRegex()
            {
                var command = new UpdateMyEmailValueCommand {
                    NewValue = "user@domain.",
                };
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <EmailAddress>()).Returns(new EmailAddress[] { }.AsQueryable);
                var validator = new UpdateMyEmailValueValidator(entities.Object);

                var results = validator.Validate(command);

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

                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                                                   ValidateEmailAddress.FailedBecauseValueWasNotValidEmailAddress,
                                                   command.NewValue));
                // ReSharper restore PossibleNullReferenceException
            }
Exemple #9
0
            public void IsValidWhen_IdentityName_IsNotEmpty_AndMatchesUser()
            {
                const string principalIdentityName = "*****@*****.**";
                var          principal             = principalIdentityName.AsPrincipal();
                var          command = new UpdateMyEmailValueCommand {
                    Principal = principal
                };
                var user = new User {
                    Name = principal.Identity.Name
                };
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <User>()).Returns(new[] { user }.AsQueryable);
                entities.Setup(m => m.Query <EmailAddress>()).Returns(new EmailAddress[] { }.AsQueryable);
                var validator = new UpdateMyEmailValueValidator(entities.Object);

                var results = validator.Validate(command);

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

                error.ShouldBeNull();
            }