コード例 #1
0
        public void Composition_Inheritance_HierarchyQuery()
        {
            CompositionInheritanceScenarios ctxt = new CompositionInheritanceScenarios(CompositionInheritanceScenarios_Uri);

            LoadOperation lo = ctxt.Load(ctxt.GetParentsQuery(), false);

            EnqueueConditional(() => lo.IsComplete);
            EnqueueCallback(delegate
            {
                TestHelperMethods.AssertOperationSuccess(lo);
                // 3 parents, each with 4 children
                Assert.AreEqual(15, lo.AllEntities.Count(), "Unexpected number of entities in hierarchy");

                Assert.AreEqual(3, ctxt.CI_Parents.Count, "Expected this many total parent entities");
                
                foreach (CI_Parent p in ctxt.CI_Parents)
                {
                    VerifyHierarchy(p);
                    IEnumerable<CI_Child> baseChildren = p.Children.Where(c => c.GetType() == typeof(CI_Child));
                    Assert.AreEqual(2, baseChildren.Count(), "Wrong number of child entities");
                    IEnumerable<CI_AdoptedChild> adoptedChildren = p.Children.OfType<CI_AdoptedChild>();
                    Assert.AreEqual(2, adoptedChildren.Count(), "Wrong number of adopted child entities");
                }
            });

            EnqueueTestComplete();
        }
コード例 #2
0
        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);

            EnqueueConditional(() => lo.IsComplete);
            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);
            });
            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                this.VerifySuccess(ctxt, so, expectedUpdates);
            });

            EnqueueTestComplete();
        }
コード例 #3
0
        /// <summary>
        /// Verify successful completion of an update operation
        /// </summary>
        private void VerifySuccess(CompositionInheritanceScenarios ctxt, SubmitOperation so, IEnumerable<Entity> expectedUpdates)
        {
            // verify operation completed successfully
            TestHelperMethods.AssertOperationSuccess(so);

            // verify that all operations were executed
            EntityChangeSet cs = so.ChangeSet;
            VerifyOperationResults(cs.AddedEntities, expectedUpdates);

            // verify that all changes have been accepted
            cs = ctxt.EntityContainer.GetChanges();
            Assert.IsTrue(cs.IsEmpty);
        }