public void RegisterValidatableObjectAdapterFactoryGuardClauses() { var provider = new DataAnnotationsModelValidatorProvider(); DataAnnotationsValidatableObjectAdapterFactory factory = (context) => null; // Attribute type cannot be null Assert.ThrowsArgumentNull( () => provider.RegisterValidatableObjectAdapterFactory(null, factory), "modelType"); // Factory cannot be null Assert.ThrowsArgumentNull( () => provider.RegisterValidatableObjectAdapterFactory(typeof(MyValidatableClass), null), "factory"); // Validation attribute must derive from ValidationAttribute Assert.ThrowsArgument( () => provider.RegisterValidatableObjectAdapterFactory(typeof(object), factory), "modelType", "The type Object must derive from IValidatableObject"); }
public void RegisterValidatableObjectAdapterFactory() { // Arrange var provider = new DataAnnotationsModelValidatorProvider(); provider.ValidatableFactories = new Dictionary<Type, DataAnnotationsValidatableObjectAdapterFactory>(); DataAnnotationsValidatableObjectAdapterFactory factory = delegate { return null; }; // Act provider.RegisterValidatableObjectAdapterFactory(typeof(MyValidatableClass), factory); // Assert var type = provider.ValidatableFactories.Keys.Single(); Assert.Equal(typeof(MyValidatableClass), type); Assert.Same(factory, provider.ValidatableFactories.Values.Single()); }