public void Should_contain_validation_result_from_validatable_object_adapter() { // Given var instance = new ModelUnderTest(); var result = new ModelValidationError(string.Empty, x => string.Empty); A.CallTo(() => this.validatableObjectAdapter.Validate(instance)).Returns(new[] { result }); // When var results = this.validator.Validate(instance); // Then results.Errors.Count().ShouldEqual(1); results.Errors.Contains(result).ShouldBeTrue(); }
public void Should_contain_validation_result_from_validatable_object_adapter() { // Given var instance = new ModelUnderTest(); var result = new ModelValidationError(string.Empty, x => string.Empty); A.CallTo(() => this.validatableObjectAdapter.Validate(instance)).Returns(new[] { result }); // When var results = this.validator.Validate(instance, new NancyContext()); // Then results.Errors.Count().ShouldEqual(1); results.Errors.Contains(result).ShouldBeTrue(); }
public void Should_contain_validation_results_from_all_validators() { // Given var instance = new ModelUnderTest(); var result1 = new ModelValidationError("Foo", string.Empty); var result2 = new ModelValidationError("Bar", string.Empty); var result3 = new ModelValidationError("Baz", string.Empty); A.CallTo(() => this.propertyValidator1.Validate(instance)).Returns(new[] { result1 }); A.CallTo(() => this.propertyValidator2.Validate(instance)).Returns(new[] { result2, result3 }); // When var results = this.validator.Validate(instance, new NancyContext()); // Then results.Errors.Count().ShouldEqual(3); }
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 }; }