Example #1
0
        public void DefaultComparer()
        {
            var candidate = new Parent { Id = 1, Name = "A", Another = 1 };
            var expected = new Parent { Id = 1, Name = "A", Another = 2, };

            Check(expected, candidate);
        }
Example #2
0
        public void IncludeAnotherPropertyComparisonFails()
        {
            var expected = new Parent { Id = 1, Name = "A", Another = 1, };
            var candidate = new Parent { Id = 1, Name = "A", Another = 2, };

            Compare<Parent>(x => x.Another).Value();
            CheckFault(expected, candidate, "Parent.Another", 1, 2);
        }
Example #3
0
        public void IncludeAnotherProperty()
        {
            var expected = new Parent { Id = 1, Name = "A", Another = 1, };
            var candidate = new Parent { Id = 1, Name = "A", Another = 1, };

            Compare<Parent>(x => x.Another).Value();
            Check(expected, candidate);
        }
Example #4
0
        public void ExcludeNameProperty()
        {
            var expected = new Parent { Id = 1, Name = "B", Another = 2 };
            var candidate = new Parent { Id = 1, Name = "A", Another = 1, };

            Compare<Parent>(x => x.Name).Ignore();
            Check(expected, candidate);
        }
Example #5
0
        public void NoIIdentifiableCheckerRegistered()
        {
            var cf = (CheckerFactory) CheckerFactory;
            cf.Clear();
            PropertyCheck.IdentityChecker = null;

            var p1 = new Parent {Id = 1, Name = "A"};
            var expected = new Child {Id = 1, Name = "Child", Parent = p1};
            var candidate = new Child {Id = 2, Name = "Child", Parent = p1};

            CheckFault(expected, candidate, "No IdentityChecker assigned, cannot perform Id check");
        }
Example #6
0
        public void NullBuilderMeansNoAutoRegistration()
        {
            var cf = (CheckerFactory) CheckerFactory;
            cf.Clear();
            cf.Builder = new NullCheckerBuilder();

            var p1 = new Parent {Id = 1, Name = "A"};
            var expected = new Child {Id = 1, Name = "Child", Parent = p1};
            var candidate = new Child {Id = 2, Name = "Child", Parent = p1};

            CheckFault(expected, candidate, "No checker registered for NCheck.Test.Child");
        }
Example #7
0
        public void ValidateWhenBothCollectionPropertyAreNull()
        {
            var expected = new Parent {Id = 1, Name = "A"};
            var candidate = new Parent {Id = 1, Name = "A"};

            Check(expected, candidate);
        }
Example #8
0
        public void ValidatePropertyMessageInChildEntity()
        {
            var expected = new Parent {Id = 1, Name = "A"};
            var c1 = new Child {Id = 1, Name = "Child", Parent = expected};
            expected.Favourite = c1;

            var candidate = new Parent {Id = 1, Name = "A"};
            var c2 = new Child {Id = 2, Name = "Child", Parent = candidate};
            candidate.Favourite = c2;

            CheckFault(expected, candidate, "Parent.Favourite.Id", 1, 2);
        }
Example #9
0
        public void ValidateMessageWhenExpectedCollectionPropertyIsNull()
        {
            var expected = new Parent {Id = 1, Name = "A"};
            var candidate = new Parent {Id = 1, Name = "A", Children = new List<Child>()};

            CheckFault(expected, candidate, "Parent.Children", "null", "not null");
        }
Example #10
0
        public void ValidateCompareByIdWithNullIdentityChecker()
        {
            var p1 = new Parent {Id = 1, Name = "A"};
            var expected = new Child {Id = 1, Name = "Child", Parent = p1};
            p1.Favourite = expected;

            var p2 = new Parent {Id = 1, Name = "A"};
            var candidate = new Child {Id = 1, Name = "Child", Parent = p2};
            p2.Favourite = candidate;

            // NB Need to initialize the checker factory
            var x = CheckerFactory;
            PropertyCheck.IdentityChecker = null;

            CheckFault(expected, candidate, "No IdentityChecker assigned, cannot perform Id check");
        }
Example #11
0
        public void ValidateMessageCollectionElementIsDifferent()
        {
            var expected = new Parent {Id = 1, Name = "A", Children = new List<Child>()};
            var candidate = new Parent {Id = 1, Name = "A", Children = new List<Child>()};

            var c1 = new Child {Id = 1};
            expected.Children.Add(c1);
            var c2 = new Child {Id = 2};
            candidate.Children.Add(c2);

            CheckFault(expected, candidate, "Parent.Children[0].Id", 1, 2);
        }
Example #12
0
        public void ValidateListExplicitly()
        {
            var c1 = new Child();
            var expected = new Parent {Id = 1, Name = "A", Children = new List<Child>()};
            var candidate = new Parent {Id = 1, Name = "A", Children = new List<Child>()};

            expected.Children.Add(c1);
            candidate.Children.Add(c1);

            Check<Child>(expected.Children, candidate.Children);
        }
Example #13
0
        public void ValidateInvalidCast()
        {
            var expected = new Parent { Id = 1, Name = "A", Castable = 10 };
            var candidate = new Parent { Id = 1, Name = "A", Castable = 10M, };

            CheckFault(expected, candidate, "Parent.Castable: Could not cast candidate value 10 (Decimal) to Int32");
        }
Example #14
0
        public void ValidateExcludeProperty()
        {
            var expected = new Parent {Id = 1, Name = "A", Ignore = "A", Another = 1};
            var candidate = new Parent {Id = 1, Name = "A", Ignore = "B", Another = 2};

            Check(expected, candidate);
        }
Example #15
0
        public void ValidateEntityWithList()
        {
            var c1 = new Child();
            var expected = new Parent {Id = 1, Name = "A", Children = new List<Child>()};
            var candidate = new Parent {Id = 1, Name = "A", Children = new List<Child>()};

            expected.Children.Add(c1);
            candidate.Children.Add(c1);

            Check(expected, candidate);
        }
Example #16
0
        public void ValidateMessageWhenExpectedCollectionCountIsDifferent()
        {
            var c1 = new Child();
            var expected = new Parent {Id = 1, Name = "A", Children = new List<Child>()};
            var candidate = new Parent {Id = 1, Name = "A", Children = new List<Child>()};

            candidate.Children.Add(c1);

            CheckFault(expected, candidate, "Parent.Children.Count", 0, 1);
        }
Example #17
0
        public void ValidateCompareById()
        {
            var p1 = new Parent {Id = 1, Name = "A"};
            var expected = new Child {Id = 1, Name = "Child", Parent = p1};
            p1.Favourite = expected;

            var p2 = new Parent {Id = 1, Name = "A"};
            var candidate = new Child {Id = 1, Name = "Child", Parent = p2};
            p2.Favourite = candidate;

            Check(expected, candidate);
        }
Example #18
0
        public void ValidateCompareByIdMessage()
        {
            var p1 = new Parent {Id = 1, Name = "A"};
            var expected = new Child {Id = 1, Name = "Child", Parent = p1};
            p1.Favourite = expected;

            var p2 = new Parent {Id = 2, Name = "A"};
            var candidate = new Child {Id = 1, Name = "Child", Parent = p2};
            p2.Favourite = candidate;

            CheckFault(expected, candidate, "Child.Parent.Id", 1, 2);
        }