public void ClientRulesWithMaxLengthAttribute() { // Arrange var provider = TestModelMetadataProvider.CreateDefaultProvider(); var metadata = provider.GetMetadataForProperty(typeof(string), "Length"); var attribute = new MaxLengthAttribute(10); var adapter = new MaxLengthAttributeAdapter(attribute); var serviceCollection = new ServiceCollection(); var requestServices = serviceCollection.BuildServiceProvider(); var context = new ClientModelValidationContext(metadata, provider, requestServices); // Act var rules = adapter.GetClientValidationRules(context); // Assert var rule = Assert.Single(rules); Assert.Equal("maxlength", rule.ValidationType); Assert.Equal(1, rule.ValidationParameters.Count); Assert.Equal(10, rule.ValidationParameters["max"]); Assert.Equal(attribute.FormatErrorMessage("Length"), rule.ErrorMessage); }