public void Add_principal_then_dependent_one_to_many_prin_uni_FK_not_set_principal_nav_set(EntityState entityState) { using (var context = new FixupContext()) { var principal = new CategoryPN { Id = 77 }; var dependent = new ProductPN { Id = 78 }; principal.Products.Add(dependent); context.Entry(principal).State = entityState; context.Entry(dependent).State = entityState; Assert.Equal(principal.Id, dependent.CategoryId); Assert.Equal(new[] { dependent }.ToList(), principal.Products); Assert.Equal(entityState, context.Entry(principal).State); Assert.Equal(entityState, context.Entry(dependent).State); } }
public void Add_dependent_then_principal_one_to_many_prin_uni_FK_set_principal_nav_set(EntityState entityState) { using (var context = new FixupContext()) { var principal = new CategoryPN { Id = 77 }; var dependent = new ProductPN { Id = 78 }; principal.Products.Add(dependent); context.Entry(dependent).Property("CategoryId").CurrentValue = principal.Id; context.Entry(dependent).State = entityState; context.Entry(principal).State = entityState; AssertFixup( context, () => { Assert.Equal(principal.Id, context.Entry(dependent).Property("CategoryId").CurrentValue); Assert.Equal(new[] { dependent }.ToList(), principal.Products); Assert.Equal(entityState, context.Entry(principal).State); Assert.Equal(entityState, context.Entry(dependent).State); }); } }
public void Add_principal_but_not_dependent_one_to_many_prin_uni_FK_not_set_principal_nav_set(EntityState entityState) { using (var context = new FixupContext()) { var principal = new CategoryPN { Id = 77 }; var dependent = new ProductPN { Id = 78 }; context.Entry(principal).State = entityState; principal.Products.Add(dependent); context.ChangeTracker.DetectChanges(); AssertFixup( context, () => { Assert.Equal(principal.Id, dependent.CategoryId); Assert.Equal(new[] { dependent }.ToList(), principal.Products); Assert.Equal(entityState, context.Entry(principal).State); Assert.Equal(EntityState.Added, context.Entry(dependent).State); }); } }
public void Add_dependent_then_principal_one_to_many_prin_uni_FK_set_no_navs_set(EntityState entityState) { using (var context = new FixupContext()) { var principal = new CategoryPN { Id = 77 }; var dependent = new ProductPN { Id = 78, CategoryId = principal.Id }; context.Entry(dependent).State = entityState; context.Entry(principal).State = entityState; AssertFixup( context, () => { Assert.Equal(principal.Id, dependent.CategoryId); Assert.Equal(new[] { dependent }.ToList(), principal.Products); Assert.Equal(entityState, context.Entry(principal).State); Assert.Equal(entityState, context.Entry(dependent).State); }); } }
public void Add_dependent_but_not_principal_one_to_many_prin_uni_FK_set_no_navs_set(EntityState entityState) { using (var context = new FixupContext()) { var principal = new CategoryPN { Id = 77 }; var dependent = new ProductPN { Id = 78 }; context.Entry(dependent).State = entityState; dependent.CategoryId = principal.Id; context.ChangeTracker.DetectChanges(); AssertFixup( context, () => { Assert.Equal(principal.Id, dependent.CategoryId); Assert.Empty(principal.Products); Assert.Equal(EntityState.Detached, context.Entry(principal).State); Assert.Equal(entityState == EntityState.Added ? EntityState.Added : EntityState.Modified, context.Entry(dependent).State); }); } }