示例#1
0
        public void GetClientValidationRules_WithIClientModelValidator_CallsAttribute()
        {
            // Arrange
            var attribute = new TestableAttribute();
            var validator = new DataAnnotationsModelValidator <TestableAttribute>(attribute);

            var metadata = _metadataProvider.GetMetadataForProperty(
                containerType: typeof(string),
                propertyName: nameof(string.Length));

            var serviceCollection = new ServiceCollection();
            var requestServices   = serviceCollection.BuildServiceProvider();

            var context = new ClientModelValidationContext(metadata, _metadataProvider, requestServices);

            // Act
            var results = validator.GetClientValidationRules(context);

            // Assert
            var rule = Assert.Single(results);

            Assert.Equal("an error", rule.ErrorMessage);
            Assert.Empty(rule.ValidationParameters);
            Assert.Equal("testable", rule.ValidationType);
        }
示例#2
0
        public void GetClientValidationRules_ReturnsEmptyRuleSet()
        {
            // Arrange
            var attribute = new FileExtensionsAttribute();
            var validator = new DataAnnotationsModelValidator <FileExtensionsAttribute>(attribute);

            var metadata = _metadataProvider.GetMetadataForProperty(
                containerType: typeof(string),
                propertyName: nameof(string.Length));

            var serviceCollection = new ServiceCollection();
            var requestServices   = serviceCollection.BuildServiceProvider();

            var context = new ClientModelValidationContext(metadata, _metadataProvider, requestServices);

            // Act
            var results = validator.GetClientValidationRules(context);

            // Assert
            Assert.Empty(results);
        }
        public void GetClientValidationRules_WithIClientModelValidator_CallsAttribute()
        {
            // Arrange
            var attribute = new TestableAttribute();
            var validator = new DataAnnotationsModelValidator<TestableAttribute>(attribute);

            var metadata = _metadataProvider.GetMetadataForProperty(
                containerType: typeof(string),
                propertyName: nameof(string.Length));

            var serviceCollection = new ServiceCollection();
            var requestServices = serviceCollection.BuildServiceProvider();

            var context = new ClientModelValidationContext(metadata, _metadataProvider, requestServices);

            // Act
            var results = validator.GetClientValidationRules(context);

            // Assert
            var rule = Assert.Single(results);
            Assert.Equal("an error", rule.ErrorMessage);
            Assert.Empty(rule.ValidationParameters);
            Assert.Equal("testable", rule.ValidationType);
        }
        public void GetClientValidationRules_ReturnsEmptyRuleSet()
        {
            // Arrange
            var attribute = new FileExtensionsAttribute();
            var validator = new DataAnnotationsModelValidator<FileExtensionsAttribute>(attribute);

            var metadata = _metadataProvider.GetMetadataForProperty(
                containerType: typeof(string),
                propertyName: nameof(string.Length));

            var serviceCollection = new ServiceCollection();
            var requestServices = serviceCollection.BuildServiceProvider();

            var context = new ClientModelValidationContext(metadata, _metadataProvider, requestServices);

            // Act
            var results = validator.GetClientValidationRules(context);

            // Assert
            Assert.Empty(results);
        }