public void GetClientValidationRules_ReturnsEqualToValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "EqualTo"); EqualToAdapter adapter = new EqualToAdapter(metadata, new ControllerContext(), new EqualToAttribute("StringLength")); String expectedMessage = new EqualToAttribute("StringLength").FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal("*.StringLength", actual.ValidationParameters["other"]); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("equalto", actual.ValidationType); Assert.Single(actual.ValidationParameters); }
public void GetClientValidationRules_ReturnsEqualToValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "EqualTo"); EqualToAdapter adapter = new EqualToAdapter(metadata, new ControllerContext(), new EqualToAttribute("StringLength")); String expectedMessage = new EqualToAttribute("StringLength").FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal("*.StringLength", actual.ValidationParameters["other"]); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("equalto", actual.ValidationType); Assert.Single(actual.ValidationParameters); }
public void GetClientValidationRules_ReturnsEqualToValidationRule() { IServiceProvider services = Substitute.For <IServiceProvider>(); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "EqualTo"); EqualToAdapter adapter = new EqualToAdapter(new EqualToAttribute("StringLength")); ClientModelValidationContext context = new ClientModelValidationContext(metadata, provider, services); String expectedMessage = new EqualToAttribute("StringLength").FormatErrorMessage("EqualTo"); ModelClientValidationRule actual = adapter.GetClientValidationRules(context).Single(); Assert.Equal("*.StringLength", actual.ValidationParameters["other"]); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("equalto", actual.ValidationType); Assert.Single(actual.ValidationParameters); }