コード例 #1
0
        public void Should_invoke_validate_on_instance()
        {
            // Given
            var instance = new ModelUnderTest();

            // When
            this.validator.Validate(instance, new NancyContext());

            // Then
            instance.ValidatedWasInvoked.ShouldBeTrue();
        }
コード例 #2
0
        public void Should_invoke_validate_with_instance()
        {
            // Given
            var instance = new ModelUnderTest();

            // When
            this.validator.Validate(instance, new NancyContext());

            // Then
            instance.InstanceBeingValidated.ShouldBeSameAs(instance);
        }
コード例 #3
0
        public void Should_invoke_validate_with_instance()
        {
            // Given
            var instance = new ModelUnderTest();

            // When
            this.validator.Validate(instance, new NancyContext());

            // Then
            instance.InstanceBeingValidated.ShouldBeSameAs(instance);
        }
コード例 #4
0
        public void Should_invoke_validatable_object_adapter_with_instance_being_validated()
        {
            // Given
            var instance = new ModelUnderTest();

            // When
            this.validator.Validate(instance);

            // Then
            A.CallTo(() => this.validatableObjectAdapter.Validate(instance)).MustHaveHappened();
        }
コード例 #5
0
        public void Should_invoke_validate_on_instance()
        {
            // Given
            var instance = new ModelUnderTest();

            // When
            this.validator.Validate(instance, new NancyContext());

            // Then
            instance.ValidatedWasInvoked.ShouldBeTrue();
        }
コード例 #6
0
        public void Should_get_property_validators_from_factory()
        {
            // Given
            var instance = new ModelUnderTest();

            // When
            this.validator.Validate(instance);

            // Then
            A.CallTo(() => this.validatorFactory.GetValidators(typeof(ModelUnderTest))).MustHaveHappened();
        }
コード例 #7
0
        public void Should_invoke_validatable_object_adapter_with_instance_being_validated()
        {
            // Given
            var instance = new ModelUnderTest();

            // When
            this.validator.Validate(instance, new NancyContext());

            // Then
            A.CallTo(() => this.validatableObjectAdapter.Validate(instance)).MustHaveHappened();
        }
コード例 #8
0
        public void Should_get_property_validators_from_factory()
        {
            // Given
            var instance = new ModelUnderTest();

            // When
            this.validator.Validate(instance, new NancyContext());

            // Then
            A.CallTo(() => this.validatorFactory.GetValidators(typeof(ModelUnderTest))).MustHaveHappened();
        }
コード例 #9
0
        public void Should_invoke_all_validators_returned_by_factory_with_instance_being_validated()
        {
            // Given
            var instance = new ModelUnderTest();

            // When
            this.validator.Validate(instance);

            // Then
            A.CallTo(() => this.propertyValidator1.Validate(instance)).MustHaveHappened();
            A.CallTo(() => this.propertyValidator2.Validate(instance)).MustHaveHappened();
        }
コード例 #10
0
        public void Should_invoke_all_validators_returned_by_factory_with_instance_being_validated()
        {
            // Given
            var instance = new ModelUnderTest();

            // When
            this.validator.Validate(instance, new NancyContext());

            // Then
            A.CallTo(() => this.propertyValidator1.Validate(instance)).MustHaveHappened();
            A.CallTo(() => this.propertyValidator2.Validate(instance)).MustHaveHappened();
        }
コード例 #11
0
        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();
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        public void Should_return_validation_error_for_all_validation_results()
        {
            // Given
            var result1 = new ValidationResult("Error1", new[] { "foo" });
            var result2 = new ValidationResult("Error2", new[] { "bar", "baz" });

            var instance = new ModelUnderTest
            {
                ExpectedResults = new[] { result1, result2 }
            };

            // When
            var results = this.validator.Validate(instance, new NancyContext());

            // Then
            results.Count().ShouldEqual(2);
        }
コード例 #14
0
        public void Should_return_validation_error_for_all_validation_results()
        {
            // Given
            var result1 = new ValidationResult("Error1", new[] { "foo" });
            var result2 = new ValidationResult("Error2", new[] { "bar", "baz" });

            var instance = new ModelUnderTest
            {
                ExpectedResults = new[] {result1, result2}
            };

            // When
            var results = this.validator.Validate(instance, new NancyContext());

            // Then
            results.Count().ShouldEqual(2);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }