Esempio n. 1
0
        public void collecting_TryValidate_has_guard_clause_against_null_validationResultCollector()
        {
            object instance = "foo";
            Action action   = () => ObjectValidator.TryValidate(instance, validationResultCollector: null);

            action.Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be("validationResultCollector");
        }
Esempio n. 2
0
        public void given_null_argument_then_TryValidate_succeeds()
        {
            object instance = null;

            bool successful = ObjectValidator.TryValidate(instance, out ValidationResult validationResult);

            successful.Should().BeTrue();
            validationResult.Should().Be(ValidationResult.Success);
        }
Esempio n. 3
0
        public void given_valid_object_then_TryValidate_succeeds()
        {
            var instance = new RootObject();

            bool successful = ObjectValidator.TryValidate(instance, out ValidationResult validationResult);

            successful.Should().BeTrue();
            validationResult.Should().Be(ValidationResult.Success);
        }
Esempio n. 4
0
        public void given_null_argument_then_collecting_TryValidate_succeeds()
        {
            object     instance  = null;
            ICollector collector = Mock.Of <ICollector>();

            bool successful = ObjectValidator.TryValidate(instance, collector.Collect);

            successful.Should().BeTrue();
            Mock.Get(collector)
            .Verify(x => x.Collect(It.IsAny <ValidationResult>()), Times.Never());
        }
Esempio n. 5
0
        public void given_root_has_invalid_property_then_collecting_TryValidate_fails()
        {
            var instance = new RootObject
            {
                Int32Property = -1,
            };
            var validationResults = new List <ValidationResult>();

            bool successful = ObjectValidator.TryValidate(instance, validationResults.Add);

            successful.Should().BeFalse();
            validationResults.Should().ContainSingle().Which.MemberNames.Should().BeEquivalentTo("Int32Property");
        }
Esempio n. 6
0
        public void given_root_has_invalid_property_then_TryValidate_fails()
        {
            var instance = new RootObject
            {
                Int32Property = -1,
            };

            bool successful = ObjectValidator.TryValidate(instance, out ValidationResult validationResult);

            successful.Should().BeFalse();
            validationResult.Should().NotBe(ValidationResult.Success);
            validationResult.MemberNames.Should().BeEquivalentTo("Int32Property");
        }