public void Validate__EmailAddress_is_null_or_empty__Should_be_invalid([Values(null, "")] string email) { var invalidCustomer = new Customer { EmailAddress = email }; _validator.ShouldHaveValidationErrorFor(x => x.EmailAddress, invalidCustomer); }
public void CustomerValidationRule_ShouldFailWhenNameIsNull() { _validator.ShouldHaveValidationErrorFor( customer => customer.Name, new Customer() { Name = null } ).WithErrorMessage(CustomerValidator.InvalidCustomerName); }
public void Should_have_error_when_date_of_birth_is_null_or_empty() { validator = new CustomerValidator(); if (DateTime.TryParse(null, out var dateOfBirth)) { validator.ShouldHaveValidationErrorFor(customer => customer.DateOfBirth, dateOfBirth); } if (DateTime.TryParse(String.Empty, out var dateOfBirth2)) { validator.ShouldHaveValidationErrorFor(customer => customer.DateOfBirth, dateOfBirth2); } }
public void when_post_request_arrives_SystemSource_cannot_be_empty() { var expectedMessage = "System Source cannot be empty."; var output = _customerValidator.ShouldHaveValidationErrorFor(x => x.SystemSource, _customer); var actualMessage = output.Select(x => x.ErrorMessage).ToList()[0]; Assert.AreSame(expectedMessage, actualMessage); }
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); }
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); }
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); }
public void Should_have_error_when_Name_is_null() { validator.ShouldHaveValidationErrorFor(customer => customer.Name, null as string); }
public void Should_have_error_when_date_of_birth_is_in_the_future() { validator = new CustomerValidator(); validator.ShouldHaveValidationErrorFor(customer => customer.DateOfBirth, DateTime.Today.AddDays(1)); }
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); }
public void Should_have_error_when_first_name_is_null() { validator = new CustomerValidator(); validator.ShouldHaveValidationErrorFor(customer => customer.LastName, null as string); validator.ShouldHaveValidationErrorFor(customer => customer.FirstName, String.Empty); }
public void ShouldHaveValidationErrorFor_WithRuleSet_ShouldNotThrowException() { var sut = new CustomerValidator(); sut.ShouldHaveValidationErrorFor(new Customer(), "GreaterThan21"); }
public void ShouldHaveValidationErrorFor_WithContext_ShouldThrowException() { var sut = new CustomerValidator(); Should.Throw<ValidationException>(() => { sut.ShouldHaveValidationErrorFor(new Customer() { Name = "Name", Age = 20 }, new {}); }); }
public void ShouldHaveValidationErrorFor_WithContext_ShouldNotThrowException() { var sut = new CustomerValidator(); sut.ShouldHaveValidationErrorFor(new Customer(),new {}); }
public void ShouldHaveValidationErrorFor_WithRuleSetAndContext_ShouldThrowException() { var sut = new CustomerValidator(); Should.Throw<ValidationException>(() => { sut.ShouldHaveValidationErrorFor(new Customer() { Name = "Name", Age = 22 }, "GreaterThan21", new {}); }); }
public void CustomerValidator_WhenUsernameIsNull_ShouldHaveError() { validator .ShouldHaveValidationErrorFor(customer => customer.Username, null as string); }