Ejemplo n.º 1
0
 public void CustomerValidationRule_ShouldPassWhenNameIsNotNull()
 {
     _validator.ShouldNotHaveValidationErrorFor(
         customer => customer.Name,
         new Customer()
     {
         Name = "Test"
     }
         );
 }
Ejemplo n.º 2
0
        public void Validate__EmailAddress_is_correct__Should_be_valid([Values(
                                                                            "*****@*****.**",
                                                                            "*****@*****.**",
                                                                            "*****@*****.**",
                                                                            "*****@*****.**",
                                                                            "*****@*****.**",
                                                                            "*****@*****.**",
                                                                            "*****@*****.**",
                                                                            "*****@*****.**",
                                                                            "admin@mailserver1",
                                                                            "*****@*****.**",
                                                                            "\" \"@example.org",
                                                                            "\"john..doe\"@example.org")] string email)
        {
            var validCustomer = new Customer {
                EmailAddress = email
            };

            _validator.ShouldNotHaveValidationErrorFor(x => x.EmailAddress, validCustomer);
        }
Ejemplo n.º 3
0
        public void UnlessAppliesToAllContraintsForSamePropertyUpToUnless()
        {
            var badCustomer = new Customer {
                Age = -5
            };

            var validator = new CustomerValidator();

            validator.ShouldHaveValidationErrorFor(c => c.Age, badCustomer);
            validator.ShouldNotHaveValidationErrorFor(c => c.Address.HouseNumber, badCustomer);
            badCustomer.Address = new Address {
                HouseNumber = -1
            };
            validator.ShouldHaveValidationErrorFor(c => c.Address.HouseNumber, badCustomer);

            var goodCustomer = new Customer {
                Age = -5, Name = "Christian", Address = new Address {
                    HouseNumber = -1
                }
            };

            validator.ShouldNotHaveValidationErrorFor(c => c.Age, goodCustomer);
            validator.ShouldNotHaveValidationErrorFor(c => c.Address.HouseNumber, goodCustomer);
        }
Ejemplo n.º 4
0
        public void WhenAppliesToAllContraintsForSamePropertyUpToUnless()
        {
            var badCustomer = new Customer {
                Address = new Address {
                    Postcode = "BR6"
                }
            };

            var validator = new CustomerValidator();

            validator.ShouldHaveValidationErrorFor(c => c.Address.Postcode, badCustomer);

            var goodCustomer = new Customer();

            validator.ShouldNotHaveValidationErrorFor(c => c.Address.Postcode, goodCustomer);
        }
Ejemplo n.º 5
0
        public void UnlessDoesNotApplyToContraintsAfterUnless()
        {
            var badCustomer = new Customer {
                Name = "", Address = new Address()
            };

            var validator = new CustomerValidator();

            validator.ShouldHaveValidationErrorFor(c => c.Name, badCustomer);

            badCustomer = new Customer {
                Name = "Therese"
            };
            validator.ShouldHaveValidationErrorFor(c => c.Name, badCustomer);

            var goodCustomer = new Customer {
                Name = ""
            };

            validator.ShouldNotHaveValidationErrorFor(c => c.Name, goodCustomer);
        }
Ejemplo n.º 6
0
 public void Should_not_have_error_when_date_of_birth_is_specified()
 {
     validator = new CustomerValidator();
     validator.ShouldNotHaveValidationErrorFor(customer => customer.DateOfBirth, DateTime.Parse("20-12-2000"));
 }
Ejemplo n.º 7
0
 public void Should_not_have_error_when_middle_name_is_specified()
 {
     validator = new CustomerValidator();
     validator.ShouldNotHaveValidationErrorFor(customer => customer.MiddleName, "Matt");
 }
Ejemplo n.º 8
0
 public void Should_not_have_error_when_middle_name_is_null_or_empty()
 {
     validator = new CustomerValidator();
     validator.ShouldNotHaveValidationErrorFor(customer => customer.MiddleName, null as string);
     validator.ShouldHaveValidationErrorFor(customer => customer.FirstName, String.Empty);
 }
Ejemplo n.º 9
0
 public void Should_not_have_error_when_first_name_is_specified()
 {
     validator = new CustomerValidator();
     validator.ShouldNotHaveValidationErrorFor(customer => customer.LastName, "Jeremy");
 }
Ejemplo n.º 10
0
        public void ShouldNotHaveValidationErrorFor_WithRuleSetAndContext_ShouldNotThrowException()
        {
            var sut = new CustomerValidator();

            sut.ShouldNotHaveValidationErrorFor(new Customer() { Name = "Name", Age = 22 }, "GreaterThan21", new { }); 
        }
Ejemplo n.º 11
0
        public void ShouldNotHaveValidationErrorFor_WithRuleSetAnContext_ShouldThrowException()
        {
            var sut = new CustomerValidator();

            Should.Throw<ValidationException>(() => { sut.ShouldNotHaveValidationErrorFor(new Customer(), "GreaterThan21", new { }); });
        }
Ejemplo n.º 12
0
        public void ShouldNotHaveValidationErrorFor_WithContext_ShouldNotThrowException()
        {
            var sut = new CustomerValidator();

            sut.ShouldNotHaveValidationErrorFor(new Customer() { Name = "Name", Age = 20 }, new { }); 
        }
Ejemplo n.º 13
0
        public void ShouldNotHaveValidationErrorFor_With_ShouldThrowException()
        {
            var sut = new CustomerValidator();

            Should.Throw<ValidationException>(() => { sut.ShouldNotHaveValidationErrorFor(new Customer() ); });
        }
Ejemplo n.º 14
0
 public void CustomerValidator_WhenUsernameIsNotNull_ShouldNotHaveError()
 {
     validator
     .ShouldNotHaveValidationErrorFor(customer => customer.Username, "Grazyna");
 }