public void RegisterAdapterFactoryGuardClauses()
        {
            var provider = new DataAnnotationsModelValidatorProvider();
            DataAnnotationsModelValidationFactory factory = (metadata, validatorProviders, attribute) => null;

            // Attribute type cannot be null
            Assert.ThrowsArgumentNull(
                () => provider.RegisterAdapterFactory(null, factory),
                "attributeType");

            // Factory cannot be null
            Assert.ThrowsArgumentNull(
                () => provider.RegisterAdapterFactory(typeof(MyValidationAttribute), null),
                "factory");

            // Validation attribute must derive from ValidationAttribute
            Assert.ThrowsArgument(
                () => provider.RegisterAdapterFactory(typeof(object), factory),
                "attributeType",
                "The type Object must derive from ValidationAttribute");
        }
        public void RegisterAdapterFactory()
        {
            // Arrange
            var provider = new DataAnnotationsModelValidatorProvider();

            provider.AttributeFactories = new Dictionary <Type, DataAnnotationsModelValidationFactory>();
            DataAnnotationsModelValidationFactory factory = delegate { return(null); };

            // Act
            provider.RegisterAdapterFactory(typeof(MyValidationAttribute), factory);

            // Assert
            var type = provider.AttributeFactories.Keys.Single();

            Assert.Equal(typeof(MyValidationAttribute), type);
            Assert.Same(factory, provider.AttributeFactories.Values.Single());
        }
        public void RegisterAdapterFactoryGuardClauses()
        {
            var provider = new DataAnnotationsModelValidatorProvider();
            DataAnnotationsModelValidationFactory factory = (validatorProviders, attribute) => null;

            // Attribute type cannot be null
            Assert.ThrowsArgumentNull(
                () => provider.RegisterAdapterFactory(null, factory),
                "attributeType");

            // Factory cannot be null
            Assert.ThrowsArgumentNull(
                () => provider.RegisterAdapterFactory(typeof(MyValidationAttribute), null),
                "factory");

            // Validation attribute must derive from ValidationAttribute
            Assert.ThrowsArgument(
                () => provider.RegisterAdapterFactory(typeof(object), factory),
                "attributeType",
                "The type Object must derive from ValidationAttribute");
        }
        public void RegisterAdapterFactory()
        {
            // Arrange
            var provider = new DataAnnotationsModelValidatorProvider();
            provider.AttributeFactories = new Dictionary<Type, DataAnnotationsModelValidationFactory>();
            DataAnnotationsModelValidationFactory factory = delegate { return null; };

            // Act
            provider.RegisterAdapterFactory(typeof(MyValidationAttribute), factory);

            // Assert
            var type = provider.AttributeFactories.Keys.Single();
            Assert.Equal(typeof(MyValidationAttribute), type);
            Assert.Same(factory, provider.AttributeFactories.Values.Single());
        }