public void AnnotationWithValidationExternalValidatorOnPersonWithCustomValidationInStubReturnsValidationError() { var person = new PersonWithCustomValidationInStub(); person.Name = "Edgar"; person.Description = "some description"; person.Age = 42; person.AnnotationWithValidationStub = "en"; person.Iso3166CountryCode = "en"; // property under test person.AnnotationWithValidationExternal = "non-iso3166-country-code-that-will-fail"; var validationResults = new List <ValidationResult>(); var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(person); var result = false; result = Validator.TryValidateObject(person, validationContext, validationResults, true); Assert.IsFalse(result); Assert.AreEqual(1, validationResults.Count()); var validationResult = validationResults[0]; Assert.AreEqual(1, validationResult.MemberNames.Count()); var memberName = validationResult.MemberNames.First(); Assert.AreEqual("AnnotationWithValidationExternal", memberName); Assert.IsTrue(validationResult.ErrorMessage.Contains("e")); }
public void AnnotationWithValidationExternalValidatorOnPersonWithCustomValidationInStubReturnsTrue() { var person = new PersonWithCustomValidationInStub(); person.Name = "Edgar"; person.Description = "some description"; person.Age = 42; person.AnnotationWithValidationStub = "en"; person.Iso3166CountryCode = "en"; // property under test person.AnnotationWithValidationExternal = "en"; var validationResults = new List <ValidationResult>(); var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(person); var result = false; result = Validator.TryValidateObject(person, validationContext, validationResults, true); Assert.IsTrue(result); }
public void AnnotationWithValidationExternalValidatorOnPersonWithCustomValidationInStubReturnsValidationError() { var person = new PersonWithCustomValidationInStub(); person.Name = "Edgar"; person.Description = "some description"; person.Age = 42; person.AnnotationWithValidationStub = "en"; person.Iso3166CountryCode = "en"; // property under test person.AnnotationWithValidationExternal = "non-iso3166-country-code-that-will-fail"; var validationResults = new List<ValidationResult>(); var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(person); var result = false; result = Validator.TryValidateObject(person, validationContext, validationResults, true); Assert.IsFalse(result); Assert.AreEqual(1, validationResults.Count()); var validationResult = validationResults[0]; Assert.AreEqual(1, validationResult.MemberNames.Count()); var memberName = validationResult.MemberNames.First(); Assert.AreEqual("AnnotationWithValidationExternal", memberName); Assert.IsTrue(validationResult.ErrorMessage.Contains("e")); }
public void AnnotationWithValidationExternalValidatorOnPersonWithCustomValidationInStubReturnsTrue() { var person = new PersonWithCustomValidationInStub(); person.Name = "Edgar"; person.Description = "some description"; person.Age = 42; person.AnnotationWithValidationStub = "en"; person.Iso3166CountryCode = "en"; // property under test person.AnnotationWithValidationExternal = "en"; var validationResults = new List<ValidationResult>(); var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(person); var result = false; result = Validator.TryValidateObject(person, validationContext, validationResults, true); Assert.IsTrue(result); }