Exemple #1
0
        public void Check_NestedLinq_ReturnsCorrectValidationMessage()
        {
            //Arrange
            var obj = new ParentObject()
            {
                Nesteds = new NestedObject[] {
                    new NestedObject()
                    {
                        Id = 1, Name = "One"
                    },
                    new NestedObject()
                    {
                        Id = 2, Name = "Two"
                    },
                    new NestedObject()
                    {
                        Id = 3, Name = "Three"
                    },
                }
            };

            _sut = new ValidationBuilder <ParentObject>(obj);

            //Act
            var messages = _sut.Check(o => o.Nesteds.All(n => n.Name == "nope"))
                           .Build();

            //Assert
            AssertHelper.MessageCount(messages, 1);
            AssertHelper.Paths(messages.First().Paths, "/Nesteds/Name");
        }
Exemple #2
0
        public void Check_BinaryExpression_ReturnsCorrectValidationMessage()
        {
            var obj = new ParentObject()
            {
                Name = "test"
            };

            _sut = new ValidationBuilder <ParentObject>(obj);

            var messages = _sut.Check(o => o.Name != "test")
                           .Build();

            AssertHelper.MessageCount(messages, 1);
            AssertHelper.Paths(messages.First().Paths, "/Name");
        }
Exemple #3
0
        public void Check_MultipleMembers_ReturnsCorrectValidationMessage()
        {
            var obj = new ParentObject()
            {
                Amount = 10, Ints = new[] { 0, 1, 2, 3, 4, 5 }
            };

            _sut = new ValidationBuilder <ParentObject>(obj);

            var messages = _sut.Check(o => o.Ints.Count() == o.Amount)
                           .Build();

            AssertHelper.MessageCount(messages, 1);
            AssertHelper.Paths(messages.First().Paths, "/Amount", "/Ints");
        }
Exemple #4
0
        public void Check_CombinedLinqExpression_ReturnsCorrectValidationMessage()
        {
            var obj = new ParentObject()
            {
                Ints = new[] { 0, 2, 4, 5, 8, 10 }
            };

            _sut = new ValidationBuilder <ParentObject>(obj);

            var messages = _sut.Check(o => o.Ints.Count(i => i % 2 == 0) > 10)
                           .Build();

            AssertHelper.MessageCount(messages, 1);
            AssertHelper.Paths(messages.First().Paths, "/Ints");
        }
Exemple #5
0
        public void Check_NestedMember_ReturnsCorrectValidationMessage()
        {
            //Arrange
            var obj = new ParentObject()
            {
                Nested = new NestedObject()
                {
                    Name = "test"
                }
            };

            _sut = new ValidationBuilder <ParentObject>(obj);

            //Act
            var messages = _sut.Check(o => o.Nested.Name == "nope")
                           .Build();

            //Assert
            AssertHelper.MessageCount(messages, 1);
            AssertHelper.Paths(messages.First().Paths, "/Nested/Name");
        }