public PropertyValidatorFixture() { this.adapter1 = A.Fake<IDataAnnotationsValidatorAdapter>(); this.error1 = new ModelValidationError("error1", x => string.Empty); A.CallTo(() => this.adapter1.Validate(A<object>._, A<ValidationAttribute>._, A<PropertyDescriptor>._)) .Returns(new[] {this.error1}); this.adapter2 = A.Fake<IDataAnnotationsValidatorAdapter>(); this.error2 = new ModelValidationError("error2", x => string.Empty); A.CallTo(() => this.adapter2.Validate(A<object>._, A<ValidationAttribute>._, A<PropertyDescriptor>._)) .Returns(new[] { this.error2 }); this.mappings = new Dictionary<ValidationAttribute, IEnumerable<IDataAnnotationsValidatorAdapter>> { {new RangeAttribute(1, 10), new[] {this.adapter1}}, {new RequiredAttribute(), new[] {this.adapter2}} }; var type = typeof(Model); this.descriptor = new AssociatedMetadataTypeTypeDescriptionProvider(type) .GetTypeDescriptor(type) .GetProperties()[0]; this.validator = new PropertyValidator { AttributeAdaptors = this.mappings, Descriptor =this.descriptor }; }
public PropertyValidatorFixture() { this.adapter1 = A.Fake <IDataAnnotationsValidatorAdapter>(); this.error1 = new ModelValidationError("error1", string.Empty); A.CallTo(() => this.adapter1.Validate(A <object> ._, A <ValidationAttribute> ._, A <PropertyDescriptor> ._, A <NancyContext> ._)) .Returns(new[] { this.error1 }); this.adapter2 = A.Fake <IDataAnnotationsValidatorAdapter>(); this.error2 = new ModelValidationError("error2", string.Empty); A.CallTo(() => this.adapter2.Validate(A <object> ._, A <ValidationAttribute> ._, A <PropertyDescriptor> ._, A <NancyContext> ._)) .Returns(new[] { this.error2 }); this.mappings = new Dictionary <ValidationAttribute, IEnumerable <IDataAnnotationsValidatorAdapter> > { { new RangeAttribute(1, 10), new[] { this.adapter1 } }, { new RequiredAttribute(), new[] { this.adapter2 } } }; var type = typeof(Model); this.descriptor = new AssociatedMetadataTypeTypeDescriptionProvider(type) .GetTypeDescriptor(type) .GetProperties()[0]; this.validator = new PropertyValidator { AttributeAdaptors = this.mappings, Descriptor = this.descriptor }; }