/// <summary>
 /// Invokes the 'CustomOp_AdoptedChild' method of the specified <see cref="CI_AdoptedChild"/> entity.
 /// </summary>
 /// <param name="child">The <see cref="CI_AdoptedChild"/> entity instance.</param>
 public void CustomOp_AdoptedChild(CI_AdoptedChild child)
 {
     child.CustomOp_AdoptedChild();
 }
        public void UpdateAdoptedChild(CI_AdoptedChild child)
        {
            SetOperationInvoked(child);

            child.OperationResult = "Update";
        }
        public void InsertAdoptedChild(CI_AdoptedChild car)
        {
            SetOperationInvoked(car);

            car.OperationResult = "Insert";
        }
        //public static void Validate(Parent parent)
        //{
        //    // Simulate a validation pass that enumerates all children.
        //    foreach (Child child in parent.Children)
        //    {
        //        foreach (GrandChild grandChild in child.Children)
        //        {
        //            GreatGrandChild greatGrandChild = grandChild.Child;
        //        }
        //    }
        //}

        /// <summary>
        /// Create  compositional hierarchy that includes both
        /// collection and singleton compositions
        /// </summary>
        public static List<CI_Parent> CreateCompositionHierarchy()
        {
            int parentKey = 1;
            int childKey = 1;

            // Create 3 Parents with children.
            List<CI_Parent> parents = new List<CI_Parent>();
            for (int i = 0; i < 3; i++)
            {
                // one of these is a derived parent type
                CI_Parent p = i == 1 ? new CI_SpecialParent() : new CI_Parent();
                
                p.ID = parentKey++;
                parents.Add(p);

                // Create 2 natural children and 2 adopted children
                // It is critical for these scenarios to have the potential
                // for both modified and unmodified derived composition children
                // in a changeset
                for (int j = 0; j < 2; j++)
                {
                    CI_Child c = new CI_Child
                    {
                        ID = childKey++,
                        ParentID = p.ID,
                        Parent = p
                    };
                    p.Children.Add(c);
                }
                for (int j = 0; j < 2; j++)
                {
                    CI_AdoptedChild c = new CI_AdoptedChild
                    {
                        ID = childKey++,
                        ParentID = p.ID,
                        Parent = p
                    };
                    p.Children.Add(c);
                }
            }

            return parents;
        }
 public void CustomOp_AdoptedChild(CI_AdoptedChild child)
 {
     this.SetOperationInvoked(child, "CustomOp_AdoptedChild");
     child.OperationResult += ",CustomOp_AdoptedChild";
 }
        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();
        }