public void RegisterDefaultAdapterFactoryGuardClauses()
        {
            var provider = new DataAnnotationsModelValidatorProvider();

            // Factory cannot be null
            Assert.ThrowsArgumentNull(
                () => provider.RegisterDefaultAdapterFactory(null),
                "factory");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NinjectDefaultModelValidatorProvider"/> class.
 /// </summary>
 /// <param name="kernel">The kernel.</param>
 /// <param name="defaultModelValidatorProviders">The default model validator providers.</param>
 public NinjectDefaultModelValidatorProvider(IKernel kernel, IEnumerable<ModelValidatorProvider> defaultModelValidatorProviders)
 {
     this.kernel = kernel;
     this.defaultModelValidatorProviders = defaultModelValidatorProviders.ToList();
     var dataAnnotationsModelValidatorProvider = new DataAnnotationsModelValidatorProvider();
     dataAnnotationsModelValidatorProvider.RegisterDefaultAdapterFactory(
         ((modelValidatorProviders, attribute) =>
         {
             this.kernel.Inject(attribute);
             return (ModelValidator)new DataAnnotationsModelValidator(modelValidatorProviders, attribute);
         }));
 }
        public void RegisterDefaultAdapterFactory()
        {
            // Arrange
            var            provider  = new DataAnnotationsModelValidatorProvider();
            var            metadata  = _metadataProvider.GetMetadataForType(() => null, typeof(MyValidatedClass));
            ModelValidator validator = new Mock <ModelValidator>(metadata, _noValidatorProviders).Object;
            DataAnnotationsModelValidationFactory factory = delegate { return(validator); };

            provider.RegisterDefaultAdapterFactory(factory);

            // Act
            var result = provider.GetValidators(metadata, _noValidatorProviders).Single();

            // Assert
            Assert.Same(validator, result);
        }
        public void RegisterDefaultAdapterFactoryGuardClauses()
        {
            var provider = new DataAnnotationsModelValidatorProvider();

            // Factory cannot be null
            Assert.ThrowsArgumentNull(
                () => provider.RegisterDefaultAdapterFactory(null),
                "factory");
        }
        public void RegisterDefaultAdapterFactory()
        {
            // Arrange
            var provider = new DataAnnotationsModelValidatorProvider();
            var metadata = _metadataProvider.GetMetadataForType(() => null, typeof(MyValidatedClass));
            ModelValidator validator = new Mock<ModelValidator>(_noValidatorProviders).Object;
            DataAnnotationsModelValidationFactory factory = delegate { return validator; };
            provider.RegisterDefaultAdapterFactory(factory);

            // Act
            var result = provider.GetValidators(metadata, _noValidatorProviders).Single();

            // Assert
            Assert.Same(validator, result);
        }