public void Add_principal_then_dependent_one_to_one_dep_uni_FK_not_set_dependent_nav_set(EntityState entityState) { using (var context = new FixupContext()) { var principal = new ParentDN { Id = 77 }; var dependent = new ChildDN { Id = 78, Parent = principal }; context.Entry(principal).State = entityState; context.Entry(dependent).State = entityState; Assert.Equal(principal.Id, dependent.ParentId); Assert.Same(principal, dependent.Parent); Assert.Equal(entityState, context.Entry(principal).State); Assert.Equal(entityState, context.Entry(dependent).State); } }
public void Add_principal_but_not_dependent_one_to_one_dep_uni_FK_not_set_dependent_nav_set(EntityState entityState) { using (var context = new FixupContext()) { var principal = new ParentDN { Id = 77 }; var dependent = new ChildDN { Id = 78 }; context.Entry(principal).State = entityState; dependent.Parent = principal; context.ChangeTracker.DetectChanges(); AssertFixup( context, () => { Assert.Equal(0, dependent.ParentId); Assert.Same(principal, dependent.Parent); Assert.Equal(entityState, context.Entry(principal).State); Assert.Equal(EntityState.Detached, context.Entry(dependent).State); }); } }
public void Add_principal_then_dependent_one_to_one_dep_uni_FK_set_no_navs_set(EntityState entityState) { using (var context = new FixupContext()) { var principal = new ParentDN { Id = 77 }; var dependent = new ChildDN { Id = 78 }; context.Entry(dependent).Property("ParentId").CurrentValue = principal.Id; context.Entry(principal).State = entityState; context.Entry(dependent).State = entityState; AssertFixup( context, () => { Assert.Equal(principal.Id, context.Entry(dependent).Property("ParentId").CurrentValue); Assert.Same(principal, dependent.Parent); Assert.Equal(entityState, context.Entry(principal).State); Assert.Equal(entityState, context.Entry(dependent).State); }); } }
public void Add_dependent_but_not_principal_one_to_one_dep_uni_FK_set_no_navs_set(EntityState entityState) { using (var context = new FixupContext()) { var principal = new ParentDN { Id = 77 }; var dependent = new ChildDN { Id = 78 }; context.Entry(dependent).State = entityState; dependent.ParentId = principal.Id; context.ChangeTracker.DetectChanges(); AssertFixup( context, () => { Assert.Equal(principal.Id, dependent.ParentId); Assert.Null(dependent.Parent); Assert.Equal(EntityState.Detached, context.Entry(principal).State); Assert.Equal(entityState == EntityState.Added ? EntityState.Added : EntityState.Modified, context.Entry(dependent).State); }); } }