private static void AssertProductAndDetailsFixedUp( DbContext context, ProductDetailsTagDetails tagDetails1, ProductDetailsTagDetails tagDetails2) { Assert.Equal(8, context.ChangeTracker.Entries().Count()); Assert.Equal(EntityState.Added, context.Entry(tagDetails1).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails1.Tag).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails1.Tag.Details).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails1.Tag.Details.Product).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails2).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails2.Tag).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails2.Tag.Details).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails2.Tag.Details.Product).State); Assert.Equal(tagDetails1.Id, tagDetails1.Tag.Id); Assert.Equal(tagDetails1.Id, tagDetails1.Tag.Details.Id); Assert.Equal(tagDetails1.Id, tagDetails1.Tag.Details.Product.Id); Assert.True(tagDetails1.Id > 0); Assert.Equal(tagDetails2.Id, tagDetails2.Tag.Id); Assert.Equal(tagDetails2.Id, tagDetails2.Tag.Details.Id); Assert.Equal(tagDetails2.Id, tagDetails2.Tag.Details.Product.Id); Assert.True(tagDetails2.Id > 0); Assert.Same(tagDetails1, tagDetails1.Tag.TagDetails); Assert.Same(tagDetails1.Tag, tagDetails1.Tag.Details.Tag); Assert.Same(tagDetails1.Tag.Details, tagDetails1.Tag.Details.Product.Details); Assert.Same(tagDetails2, tagDetails2.Tag.TagDetails); Assert.Same(tagDetails2.Tag, tagDetails2.Tag.Details.Tag); Assert.Same(tagDetails2.Tag.Details, tagDetails2.Tag.Details.Product.Details); var product1 = tagDetails1.Tag.Details.Product; Assert.Same(product1, product1.Details.Product); Assert.Same(product1.Details, product1.Details.Tag.Details); Assert.Same(product1.Details.Tag, product1.Details.Tag.TagDetails.Tag); var product2 = tagDetails2.Tag.Details.Product; Assert.Same(product2, product2.Details.Product); Assert.Same(product2.Details, product2.Details.Tag.Details); Assert.Same(product2.Details.Tag, product2.Details.Tag.TagDetails.Tag); }
[Fact] // Issue #1207 public void Can_add_identifying_dependents_and_principal_starting_in_the_middle_with_key_generation() { using (var context = new EarlyLearningCenter()) { var tagDetails1 = new ProductDetailsTagDetails { Tag = new ProductDetailsTag { Details = new ProductDetails { Product = new Product() } } }; var tagDetails2 = new ProductDetailsTagDetails { Tag = new ProductDetailsTag { Details = new ProductDetails { Product = new Product() } } }; context.Add(tagDetails1.Tag); context.Add(tagDetails2.Tag); context.Add(tagDetails1); context.Add(tagDetails2); context.Add(tagDetails2.Tag.Details); context.Add(tagDetails1.Tag.Details); context.Add(tagDetails1.Tag.Details.Product); context.Add(tagDetails2.Tag.Details.Product); AssertProductAndDetailsFixedUp(context, tagDetails1, tagDetails2); } }
[Fact] // Issue #1207 public void Can_add_identifying_dependents_and_principal_with_reverse_post_nav_fixup_with_key_generation() { using (var context = new EarlyLearningCenter()) { var product1 = new Product(); var details1 = new ProductDetails(); var tag1 = new ProductDetailsTag(); var tagDetails1 = new ProductDetailsTagDetails(); var product2 = new Product(); var details2 = new ProductDetails(); var tag2 = new ProductDetailsTag(); var tagDetails2 = new ProductDetailsTagDetails(); context.Add(product1); context.Add(tagDetails2); context.Add(details1); context.Add(tag2); context.Add(details2); context.Add(tag1); context.Add(tagDetails1); context.Add(product2); tagDetails1.Tag = tag1; tag1.Details = details1; details1.Product = product1; tagDetails2.Tag = tag2; tag2.Details = details2; details2.Product = product2; context.ChangeTracker.DetectChanges(); AssertProductAndDetailsFixedUp(context, product1.Details.Tag.TagDetails, product2.Details.Tag.TagDetails); } }
private static void AssertProductAndDetailsFixedUp( DbContext context, ProductDetailsTagDetails tagDetails1, ProductDetailsTagDetails tagDetails2) { Assert.Equal(8, context.ChangeTracker.Entries().Count()); Assert.Equal(EntityState.Added, context.Entry(tagDetails1).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails1.Tag).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails1.Tag.Details).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails1.Tag.Details.Product).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails2).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails2.Tag).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails2.Tag.Details).State); Assert.Equal(EntityState.Added, context.Entry(tagDetails2.Tag.Details.Product).State); Assert.Equal(tagDetails1.Id, tagDetails1.Tag.Id); Assert.Equal(tagDetails1.Id, tagDetails1.Tag.Details.Id); Assert.Equal(tagDetails1.Id, tagDetails1.Tag.Details.Product.Id); Assert.True(tagDetails1.Id > 0); Assert.Equal(tagDetails2.Id, tagDetails2.Tag.Id); Assert.Equal(tagDetails2.Id, tagDetails2.Tag.Details.Id); Assert.Equal(tagDetails2.Id, tagDetails2.Tag.Details.Product.Id); Assert.True(tagDetails2.Id > 0); Assert.Same(tagDetails1, tagDetails1.Tag.TagDetails); Assert.Same(tagDetails1.Tag, tagDetails1.Tag.Details.Tag); Assert.Same(tagDetails1.Tag.Details, tagDetails1.Tag.Details.Product.Details); Assert.Same(tagDetails2, tagDetails2.Tag.TagDetails); Assert.Same(tagDetails2.Tag, tagDetails2.Tag.Details.Tag); Assert.Same(tagDetails2.Tag.Details, tagDetails2.Tag.Details.Product.Details); var product1 = tagDetails1.Tag.Details.Product; Assert.Same(product1, product1.Details.Product); Assert.Same(product1.Details, product1.Details.Tag.Details); Assert.Same(product1.Details.Tag, product1.Details.Tag.TagDetails.Tag); var product2 = tagDetails2.Tag.Details.Product; Assert.Same(product2, product2.Details.Product); Assert.Same(product2.Details, product2.Details.Tag.Details); Assert.Same(product2.Details.Tag, product2.Details.Tag.TagDetails.Tag); }
[Fact] // Issue #1207 public void Can_add_identifying_dependents_and_principal_with_reverse_post_nav_fixup_with_key_generation() { using (var context = new EarlyLearningCenter()) { var product1 = new Product(); var details1 = new ProductDetails(); var tag1 = new ProductDetailsTag(); var tagDetails1 = new ProductDetailsTagDetails(); var product2 = new Product(); var details2 = new ProductDetails(); var tag2 = new ProductDetailsTag(); var tagDetails2 = new ProductDetailsTagDetails(); context.Add(product1); context.Add(tagDetails2); context.Add(details1); context.Add(tag2); context.Add(details2); context.Add(tag1); context.Add(tagDetails1); context.Add(product2); tagDetails1.Tag = tag1; tag1.Details = details1; details1.Product = product1; tagDetails2.Tag = tag2; tag2.Details = details2; details2.Product = product2; context.ChangeTracker.DetectChanges(); AssertProductAndDetailsFixedUp(context, product1.Details.Tag.TagDetails, product2.Details.Tag.TagDetails); } }
[Fact] // Issue #1207 public void Can_add_identifying_dependents_and_principal_starting_in_the_middle_with_key_generation() { using (var context = new EarlyLearningCenter()) { var tagDetails1 = new ProductDetailsTagDetails { Tag = new ProductDetailsTag { Details = new ProductDetails { Product = new Product() } } }; var tagDetails2 = new ProductDetailsTagDetails { Tag = new ProductDetailsTag { Details = new ProductDetails { Product = new Product() } } }; context.Add(tagDetails1.Tag); context.Add(tagDetails2.Tag); context.Add(tagDetails1); context.Add(tagDetails2); context.Add(tagDetails2.Tag.Details); context.Add(tagDetails1.Tag.Details); context.Add(tagDetails1.Tag.Details.Product); context.Add(tagDetails2.Tag.Details.Product); AssertProductAndDetailsFixedUp(context, tagDetails1, tagDetails2); } }