public void IsValid_EqualValue() { AttributesModel model = new AttributesModel(); ValidationContext context = new ValidationContext(model); Assert.Null(attribute.GetValidationResult(model.Sum, context)); }
public void GetValidationResult_EqualValue() { ValidationContext context = new ValidationContext(new AllTypesView { StringField = "Test" }); Assert.Null(attribute.GetValidationResult("Test", context)); }
public void GetValidationResult_EqualValue() { ValidationContext context = new ValidationContext(new AdaptersModel { EqualTo = "Test" }); Assert.Null(attribute.GetValidationResult("Test", context)); }
public void GetValidationResult_NoProperty_Error() { attribute = new EqualToAttribute("Temp"); ValidationContext context = new ValidationContext(new AllTypesView()); String actual = attribute.GetValidationResult("Test", context).ErrorMessage; String expected = Validation.For("EqualTo", context.DisplayName, "Temp"); Assert.Equal(expected, actual); }
public void GetValidationResult_NoProperty_Error() { attribute = new EqualToAttribute("Temp"); ValidationContext context = new ValidationContext(new AdaptersModel()); String actual = attribute.GetValidationResult("Test", context).ErrorMessage; String expected = String.Format(Validations.EqualTo, context.DisplayName, "Temp"); Assert.Equal(expected, actual); }
public void ErrorMessageTest() { var currentObject = new CompareObject("a"); object otherObject = new CompareObject("b"); var testContext = new ValidationContext(otherObject, null, null); testContext.DisplayName = "CurrentProperty"; var attribute = new EqualToAttribute("CompareProperty") { ErrorMessage = "SampleErrorMessage" }; var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null)); Assert.AreEqual("SampleErrorMessage", result.ErrorMessage); }
public void ErrorResourcesTest() { var currentObject = new CompareObject("a"); object otherObject = new CompareObject("b"); var testContext = new ValidationContext(otherObject, null, null); testContext.DisplayName = "CurrentProperty"; var attribute = new EqualToAttribute("CompareProperty") { ErrorMessageResourceName = "ErrorMessage", ErrorMessageResourceType = typeof(ErrorResources) }; var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null)); Assert.AreEqual(ErrorResources.ErrorMessage, result.ErrorMessage); }
public void GlobalizedErrorResourcesTest() { System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX"); var currentObject = new CompareObject("a"); object otherObject = new CompareObject("b"); var testContext = new ValidationContext(otherObject, null, null); testContext.DisplayName = "CurrentProperty"; var attribute = new EqualToAttribute("CompareProperty") { ErrorMessageResourceName = "ErrorMessage", ErrorMessageResourceType = typeof(ErrorResources) }; var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null)); Assert.AreEqual("mensaje de error", result.ErrorMessage); }