Esempio n. 1
0
        public void VerifyValigatorModelWrapperOnTypeWithSetterWrappedInValigatorModel()
        {
            var typeWithSetter = new Stuff();

            var anonymousObject = ValigatorModel.Create(typeWithSetter);

            var result = Model.Verify(anonymousObject);

            var failure = result.AssertFailure();

            failure.Should().HaveCount(1);
            failure.First().ValueDescriptor.Should().BeOfType <Valigator.Core.ValueDescriptors.RangeDescriptor>();
            (failure.First().ValueDescriptor as Valigator.Core.ValueDescriptors.RangeDescriptor).LessThanValue.AssertSome().Should().Be(0);
        }
Esempio n. 2
0
        public void VerifyNestedAnonymousObjects_AlwaysSuccessfulBecauseNestedObjectDoesNotValidateContents(int value, bool success)
        {
            var stuff = new Stuff();

            stuff.A = stuff.A.WithValue(value);

            var anonymousObject = ValigatorModel.Create(new { AnonymousOuter = ValigatorModel.Create(new { AnonymousInner = stuff }), Other = 1 });

            var result = Model.Verify(anonymousObject);

            if (success)
            {
                result.AssertSuccess();
            }
            else
            {
                var failure = result.AssertFailure();
                failure.Should().HaveCount(1);
                failure.First().ValueDescriptor.Should().BeOfType <Valigator.Core.ValueDescriptors.RangeDescriptor>();
                (failure.First().ValueDescriptor as Valigator.Core.ValueDescriptors.RangeDescriptor).LessThanValue.AssertSome().Should().Be(0);
            }
        }
 public static ValigatorModel <T> ToValigatorModel <T>(this T obj)
 => ValigatorModel.Create(obj);