public void SetUp() { PropertyInfo = typeof(SomeEntity).GetProperties().First(e => e.Name == "SomeEnumPropertyWithAttribute"); ControllerContext = Substitute.For<ControllerContext>(); Model = new SomeEntity(); Metadata = new ModelMetadata(Substitute.For<ModelMetadataProvider>(), typeof(SomeEntity), () => Model, typeof(SomeEntity), "SomeEnumPropertyWithAttribute"); EnumValidationAttribute = new EnumValidationAttribute(); Target = new EnumModelValidator(Metadata, ControllerContext, PropertyInfo, EnumValidationAttribute); }
public EnumModelValidator(ModelMetadata modelMetadata, ControllerContext controllerContext, PropertyInfo targetProperty, EnumValidationAttribute enumValidationAttribute) : base(modelMetadata, controllerContext) { if (targetProperty == null) throw new ArgumentNullException("targetProperty"); if (!targetProperty.PropertyType.IsEnum) throw new ArgumentException(); if (enumValidationAttribute == null) throw new ArgumentNullException("enumValidationAttribute"); _targetProperty = targetProperty; _enumValidationAttribute = enumValidationAttribute; }