public void Composition_Inheritance_Add_Derived_Child_To_Derived_Parent() { CompositionInheritanceScenarios ctxt = new CompositionInheritanceScenarios(CompositionInheritanceScenarios_Uri); CI_SpecialParent parent = null; SubmitOperation so = null; IEnumerable <Entity> expectedUpdates = null; LoadOperation lo = ctxt.Load(ctxt.GetParentsQuery(), false); EnqueueConditional(() => lo.IsComplete); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); parent = ctxt.CI_Parents.OfType <CI_SpecialParent>().First(); CI_AdoptedChild newChild = new CI_AdoptedChild() { Age = 5, }; parent.Children.Add(newChild); Assert.AreSame(parent, ((Entity)newChild).Parent); EntityChangeSet cs = ctxt.EntityContainer.GetChanges(); Assert.IsTrue(cs.ModifiedEntities.Count == 1, "wrong modified count"); Assert.IsTrue(cs.AddedEntities.Count == 1, "wrong added count"); Assert.IsTrue(cs.RemovedEntities.Count == 0, "wrong removed count"); Assert.IsTrue(cs.ModifiedEntities.Contains(parent)); Assert.IsTrue(cs.AddedEntities.Contains(newChild)); // verify that original associations are set up correctly IEnumerable <ChangeSetEntry> entityOps = ChangeSetBuilder.Build(cs); this.ValidateEntityOperationAssociations(entityOps); expectedUpdates = cs.Where(p => p.HasChildChanges || p.HasPropertyChanges).ToArray(); so = ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); EnqueueConditional(() => so.IsComplete); EnqueueCallback(delegate { this.VerifySuccess(ctxt, so, expectedUpdates); }); EnqueueTestComplete(); }
public void Composition_Inheritance_Update_Base_Child_On_Base_Parent() { CompositionInheritanceScenarios ctxt = new CompositionInheritanceScenarios(CompositionInheritanceScenarios_Uri); CI_Parent parent = null; SubmitOperation so = null; IEnumerable <Entity> expectedUpdates = null; LoadOperation lo = ctxt.Load(ctxt.GetParentsQuery(), false); this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); parent = ctxt.CI_Parents.First(p => p.GetType() == typeof(CI_Parent)); CI_Child existingChild = parent.Children.First(c => c.GetType() == typeof(CI_Child)); Assert.AreSame(parent, ((Entity)existingChild).Parent); // update derived comp child existingChild.Age++;; EntityChangeSet cs = ctxt.EntityContainer.GetChanges(); Assert.IsTrue(cs.ModifiedEntities.Count == 2, "wrong modified count"); Assert.IsTrue(cs.RemovedEntities.Count == 0, "wrong removed count"); Assert.IsTrue(cs.ModifiedEntities.Contains(parent)); Assert.IsTrue(cs.ModifiedEntities.Contains(existingChild)); // verify that original associations are set up correctly IEnumerable <ChangeSetEntry> entityOps = ChangeSetBuilder.Build(cs); this.ValidateEntityOperationAssociations(entityOps); expectedUpdates = cs.Where(p => p.HasChildChanges || p.HasPropertyChanges).ToArray(); so = ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); this.EnqueueCompletion(() => so); EnqueueCallback(delegate { this.VerifySuccess(ctxt, so, expectedUpdates); }); EnqueueTestComplete(); }