public void CreateValidators_DoesNotAddDuplicateRequiredAttribute_ForIsRequiredTrue() { // Arrange var provider = new DataAnnotationsClientModelValidatorProvider( new ValidationAttributeAdapterProvider(), new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>(), stringLocalizerFactory: null); var metadata = _metadataProvider.GetMetadataForProperty( typeof(DummyRequiredAttributeHelperClass), nameof(DummyRequiredAttributeHelperClass.ValueTypeWithoutAttribute)); var items = GetValidatorItems(metadata); var expectedValidatorItem = new ClientValidatorItem { Validator = new RequiredAttributeAdapter(new RequiredAttribute(), stringLocalizer: null), IsReusable = true }; items.Add(expectedValidatorItem); var providerContext = new ClientValidatorProviderContext(metadata, items); // Act provider.CreateValidators(providerContext); // Assert var validatorItem = Assert.Single(providerContext.Results); Assert.Same(expectedValidatorItem.Validator, validatorItem.Validator); }
public void CreateValidators_DoesNotAddDuplicateValidators() { // Arrange var provider = new NumericClientModelValidatorProvider(); var metadata = _metadataProvider.GetMetadataForType(typeof(float)); var items = GetValidatorItems(metadata); var expectedValidatorItem = new ClientValidatorItem { Validator = new NumericClientModelValidator(), IsReusable = true }; items.Add(expectedValidatorItem); var providerContext = new ClientValidatorProviderContext(metadata, items); // Act provider.CreateValidators(providerContext); // Assert var validatorItem = Assert.Single(providerContext.Results); Assert.Same(expectedValidatorItem.Validator, validatorItem.Validator); }