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); }
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); }
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); }
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); }
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"); }
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"); }
public void ValidateWhenBothCollectionPropertyAreNull() { var expected = new Parent {Id = 1, Name = "A"}; var candidate = new Parent {Id = 1, Name = "A"}; Check(expected, candidate); }
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); }
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"); }
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"); }
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); }
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); }
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"); }
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); }
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); }
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); }
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); }
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); }