public void Compare_List_As_Deep_Compare_With_Default() { SutEngine.Configure <NestedListWithDefault>() .For(x => x.Children, x => x.MatchUsing(y => y.Id, -1)); var oldModel = new NestedListWithDefault() { Children = new List <GrandChildModel>() { new GrandChildModel() { Id = 100, Name = "Name 1", Value = 100 }, } }; var newModel = new NestedListWithDefault() { Children = new List <GrandChildModel>() { new GrandChildModel() { Id = 100, Name = "Name 1", Value = 100 }, new GrandChildModel() { Id = -1, Name = "Name 2", Value = 200 }, new GrandChildModel() { Id = -1, Name = "Name 3", Value = 300 }, new GrandChildModel() { Id = -1, Name = "Name 4", Value = 400 }, } }; var changes = SutEngine.Compare(oldModel, newModel); Assert.AreEqual(changes.Count(), 9); Assert.IsNotNull(changes.Count(x => x.Name == "Children.0.Id" && (long)x.NewValue == 0) == 3); }
public void When_I_Compare_Lists_Of_Objects_I_Can_Specify_A_Default_Key() { Comparer.Configure<NestedListWithDefault>() .Enumerable(x => x.Children, x => x.DeepCompare(y => y.Id, 0)); var oldModel = new NestedListWithDefault() { Children = new List<GrandChildModel>() { new GrandChildModel() { Id = 100, Name = "Name 1", Value = 100 }, } }; var newModel = new NestedListWithDefault() { Children = new List<GrandChildModel>() { new GrandChildModel() { Id = 100, Name = "Name 1", Value = 100 }, new GrandChildModel() { Id = 0, Name = "Name 2", Value = 200 }, new GrandChildModel() { Id = 0, Name = "Name 3", Value = 300 }, new GrandChildModel() { Id = 0, Name = "Name 4", Value = 400 }, } }; var changes = Comparer.Compare(oldModel, newModel); Assert.AreEqual(changes.Count(), 9); Assert.IsNotNull(changes.Count(x => x.Name == "Children.0.Id" && (long)x.NewValue == 0) == 3); }
public void Compare_List_As_Deep_Compare_With_Default() { SutEngine.Configure<NestedListWithDefault>() .For(x => x.Children, x => x.MatchUsing(y => y.Id, -1)); var oldModel = new NestedListWithDefault() { Children = new List<GrandChildModel>() { new GrandChildModel() { Id = 100, Name = "Name 1", Value = 100 }, } }; var newModel = new NestedListWithDefault() { Children = new List<GrandChildModel>() { new GrandChildModel() { Id = 100, Name = "Name 1", Value = 100 }, new GrandChildModel() { Id = -1, Name = "Name 2", Value = 200 }, new GrandChildModel() { Id = -1, Name = "Name 3", Value = 300 }, new GrandChildModel() { Id = -1, Name = "Name 4", Value = 400 }, } }; var changes = SutEngine.Compare(oldModel, newModel); Assert.AreEqual(changes.Count(), 9); Assert.IsNotNull(changes.Count(x => x.Name == "Children.0.Id" && (long)x.NewValue == 0) == 3); }