public void WhenValidatingUserWithCountryAsUSAndFiveDigitNumericPostalCode_ThenValidationSucceeds() { var user = new FirebrickUserViewModel { DisplayName = "name", Country = "United States", PostalCode = "12345", Password = "******", UserName = "******" }; ValidateUser(user); }
public void WhenValidatingUserWithCountryAsUSAndLongNumericPostalCode_ThenValidationFails() { var user = new FirebrickUserViewModel { DisplayName = "name", Country = "United States", PostalCode = "123456", Password = "******", UserName = "******" }; var exception = Assert.Throws<ValidationException>(() => ValidateUser(user)); Assert.Contains("PostalCode", exception.ValidationResult.MemberNames); }
public void WhenValidatingUserWithLongCountry_ThenValidationFails() { var user = new FirebrickUserViewModel { DisplayName = "name", Country = "ThisIsAVeryVeryVeryVeryVeryLongStringThatShouldNotBeAllowed", PostalCode = "12345", Password = "******", UserName = "******" }; var exception = Assert.Throws<ValidationException>(() => ValidateUser(user)); Assert.Contains("Country", exception.ValidationResult.MemberNames); }
/// <summary> /// The validate user. /// </summary> /// <param name="user"> /// The user. /// </param> private static void ValidateUser(FirebrickUserViewModel user) { var context = new ValidationContext(user, null, null); Validator.ValidateObject(user, context, true); }