public void Can_attach_graph_using_custom_delegate() { var tracker = new MyTracker(updateExistingEntities: false); using (var context = new EarlyLearningCenter()) { var category = new Category { Id = 77, Products = new List <Product> { new Product { Id = 77 }, new Product { Id = 0 }, new Product { Id = 78 } } }; context.ChangeTracker.TrackGraph(category, tracker.TrackEntity); Assert.Equal(4, context.ChangeTracker.Entries().Count()); Assert.Equal(EntityState.Unchanged, context.Entry(category).State); Assert.Equal(EntityState.Unchanged, context.Entry(category.Products[0]).State); Assert.Equal(EntityState.Added, context.Entry(category.Products[1]).State); Assert.Equal(EntityState.Unchanged, context.Entry(category.Products[2]).State); Assert.Equal(77, category.Products[0].Id); Assert.Equal(777, category.Products[1].Id); Assert.Equal(78, category.Products[2].Id); Assert.Same(category, category.Products[0].Category); Assert.Same(category, category.Products[1].Category); Assert.Same(category, category.Products[2].Category); Assert.Equal(category.Id, category.Products[0].CategoryId); Assert.Equal(category.Id, category.Products[1].CategoryId); Assert.Equal(category.Id, category.Products[2].CategoryId); } }
public void Can_attach_graph_using_custom_delegate() { var tracker = new MyTracker(updateExistingEntities: false); using (var context = new EarlyLearningCenter()) { var category = new Category { Id = 77, Products = new List<Product> { new Product { Id = 77 }, new Product { Id = 0 }, new Product { Id = 78 } } }; context.ChangeTracker.TrackGraph(category, tracker.TrackEntity); Assert.Equal(4, context.ChangeTracker.Entries().Count()); Assert.Equal(EntityState.Unchanged, context.Entry(category).State); Assert.Equal(EntityState.Unchanged, context.Entry(category.Products[0]).State); Assert.Equal(EntityState.Added, context.Entry(category.Products[1]).State); Assert.Equal(EntityState.Unchanged, context.Entry(category.Products[2]).State); Assert.Equal(77, category.Products[0].Id); Assert.Equal(777, category.Products[1].Id); Assert.Equal(78, category.Products[2].Id); Assert.Same(category, category.Products[0].Category); Assert.Same(category, category.Products[1].Category); Assert.Same(category, category.Products[2].Category); Assert.Equal(category.Id, category.Products[0].CategoryId); Assert.Equal(category.Id, category.Products[1].CategoryId); Assert.Equal(category.Id, category.Products[2].CategoryId); } }