public void GetModelValidatorWithFailedPropertyValidatorsPreventsTypeValidatorFromRunning() { // Arrange ControllerContext context = new ControllerContext(); DataErrorInfo1 model = new DataErrorInfo1 { Error = "Some Type Error" }; model["SomeStringProperty"] = "Some Property Error"; model["SomeOtherStringProperty"] = "Some Other Property Error"; ModelMetadata metadata = ModelMetadataProviders.Current.GetMetadataForType( () => model, model.GetType() ); ModelValidator validator = ModelValidator.GetModelValidator(metadata, context); // Act List <ModelValidationResult> result = validator.Validate(null).ToList(); // Assert Assert.Equal(2, result.Count); Assert.Equal("SomeStringProperty", result[0].MemberName); Assert.Equal("Some Property Error", result[0].Message); Assert.Equal("SomeOtherStringProperty", result[1].MemberName); Assert.Equal("Some Other Property Error", result[1].Message); }
public void GetModelValidatorWithPropertyLevelValidator() { // Arrange ControllerContext context = new ControllerContext(); DataErrorInfo1 model = new DataErrorInfo1(); model["SomeStringProperty"] = "Some Property Error"; ModelMetadata metadata = ModelMetadataProviders.Current.GetMetadataForType( () => model, model.GetType() ); ModelValidator validator = ModelValidator.GetModelValidator(metadata, context); // Act ModelValidationResult result = validator.Validate(null).Single(); // Assert Assert.Equal("SomeStringProperty", result.MemberName); Assert.Equal("Some Property Error", result.Message); }
public void GetModelValidatorWithFailedPropertyValidatorsPreventsTypeValidatorFromRunning() { // Arrange ControllerContext context = new ControllerContext(); DataErrorInfo1 model = new DataErrorInfo1 { Error = "Some Type Error" }; model["SomeStringProperty"] = "Some Property Error"; model["SomeOtherStringProperty"] = "Some Other Property Error"; ModelMetadata metadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType()); ModelValidator validator = ModelValidator.GetModelValidator(metadata, context); // Act List<ModelValidationResult> result = validator.Validate(null).ToList(); // Assert Assert.Equal(2, result.Count); Assert.Equal("SomeStringProperty", result[0].MemberName); Assert.Equal("Some Property Error", result[0].Message); Assert.Equal("SomeOtherStringProperty", result[1].MemberName); Assert.Equal("Some Other Property Error", result[1].Message); }
public void GetModelValidatorWithPropertyLevelValidator() { // Arrange ControllerContext context = new ControllerContext(); DataErrorInfo1 model = new DataErrorInfo1(); model["SomeStringProperty"] = "Some Property Error"; ModelMetadata metadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType()); ModelValidator validator = ModelValidator.GetModelValidator(metadata, context); // Act ModelValidationResult result = validator.Validate(null).Single(); // Assert Assert.Equal("SomeStringProperty", result.MemberName); Assert.Equal("Some Property Error", result.Message); }