Пример #1
0
        public void DeleteParent(Parent parent)
        {
            CompositionHelper.Validate(parent);
            SetOperationInvoked(parent);

            ((CompositionEntityBase)parent).OperationResult = "Delete";
        }
Пример #2
0
        public void CustomOp_Parent(Parent parent)
        {
            // first validate the hierarchy
            CompositionHelper.Validate(parent);

            ((CompositionEntityBase)parent).OperationResult += ",CustomOp_Parent";
        }
Пример #3
0
        public void DeleteParent(Parent parent)
        {
            // normally you wouldn't validate a deleted hierarchy,
            // but we do it here for test validation
            CompositionHelper.Validate(parent);

            ((CompositionEntityBase)parent).OperationResult = "Delete";

            // Delete all children in the hierarchy.
            foreach (Child child in parent.Children)
            {
                foreach (GrandChild grandChild in child.Children)
                {
                    GreatGrandChild greatGrandChild = grandChild.Child;
                    if (greatGrandChild != null)
                    {
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// For the specified entity, recursively verifies that all parent operations
        /// have been completed
        /// </summary>
        private void VerifyOperationOrdering(object entity, bool isCustomMethod)
        {
            // determine the parent
            object parent = null;

            if (entity is Child)
            {
                parent = ((Child)entity).Parent;
            }
            else if (entity is GrandChild)
            {
                parent = ((GrandChild)entity).Parent;
            }
            else if (entity is GreatGrandChild)
            {
                parent = ((GreatGrandChild)entity).Parent;
            }

            // search the changeset for parent operations
            IEnumerable <ChangeSetEntry> parentOperations = this.ChangeSet.ChangeSetEntries.Where(p => p.Entity == parent);

            foreach (ChangeSetEntry parentOperation in parentOperations)
            {
                if (!isCustomMethod)
                {
                    CompositionHelper.Assert(this._invokedOperations.Contains(parentOperation), "Child operation executed before parent!");
                }
                else
                {
                    if (parentOperation.EntityActions != null && parentOperation.EntityActions.Any())
                    {
                        var entityAction = parentOperation.EntityActions.Single();
                        CompositionHelper.Assert(this.invokedCustomMethods.Contains(entityAction.Key), "Child custom method executed before parent!");
                    }
                }

                // now recursively verify
                this.VerifyOperationOrdering(parentOperation.Entity, isCustomMethod);
            }
        }
Пример #5
0
        public void InsertParent(Parent parent)
        {
            // first validate the hierarchy
            CompositionHelper.Validate(parent);

            ((CompositionEntityBase)parent).OperationResult = "Insert";

            // for a new parent, all children will also be new
            // so we enumerate all and "add" them
            foreach (Child child in parent.Children)
            {
                ((CompositionEntityBase)child).OperationResult = "Insert";
                foreach (GrandChild grandChild in child.Children)
                {
                    ((CompositionEntityBase)grandChild).OperationResult = "Insert";
                    GreatGrandChild greatGrandChild = grandChild.Child;
                    if (greatGrandChild != null)
                    {
                        ((CompositionEntityBase)greatGrandChild).OperationResult = "Insert";
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Use the changeset composition APIs to navigate all child updates
        /// </summary>
        /// <param name="parent"></param>
        private void NavigateChildChanges(CI_Parent parent)
        {
            // if the parent has had property modifications, original will
            // be non-null
            if (this.ChangeSet.GetChangeOperation(parent) != ChangeOperation.Insert)
            {
                CI_Parent originalParent = this.ChangeSet.GetOriginal(parent);
            }

            // navigate all child changes w/o specifying operation type
            Dictionary <object, ChangeOperation> changeOperationMap = new Dictionary <object, ChangeOperation>();

            foreach (CI_Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children))
            {
                ChangeOperation op = this.ChangeSet.GetChangeOperation(child);
                changeOperationMap[child] = op;

                if (this.ChangeSet.GetChangeOperation(child) != ChangeOperation.Insert)
                {
                    CI_Child originalChild = this.ChangeSet.GetOriginal(child);
                }

                if (op == ChangeOperation.None)
                {
                }
                else if (op == ChangeOperation.Insert)
                {
                    CompositionInheritanceHelper.Assert(this.ChangeSet.ChangeSetEntries.SingleOrDefault(p => p.Entity == child && p.Operation == DomainOperation.Insert) != null,
                                                        "Expected corresponding insert operation not found.");
                }
                else if (op == ChangeOperation.Update)
                {
                    CompositionInheritanceHelper.Assert(this.ChangeSet.ChangeSetEntries.SingleOrDefault(p => p.Entity == child && p.Operation == DomainOperation.Update) != null,
                                                        "Expected corresponding update operation not found.");
                }
                else if (op == ChangeOperation.Delete)
                {
                    CompositionInheritanceHelper.Assert(this.ChangeSet.ChangeSetEntries.SingleOrDefault(p => p.Entity == child && p.Operation == DomainOperation.Delete) != null,
                                                        "Expected corresponding delete operation not found.");
                }
            }

            // verify all child operations against the map we built up during enumeration
            // of associated changes to ensure all operations were returned
            foreach (ChangeSetEntry operation in this.ChangeSet.ChangeSetEntries.Where(p => p.Entity.GetType() != typeof(CI_Parent)))
            {
                switch (operation.Operation)
                {
                case DomainOperation.Insert:
                    CompositionHelper.Assert(changeOperationMap.ContainsKey(operation.Entity) &&
                                             changeOperationMap[operation.Entity] == ChangeOperation.Insert,
                                             "Expected insert operation was not returned from GetAssociatedChanges.");
                    break;

                case DomainOperation.Update:
                    CompositionHelper.Assert(changeOperationMap.ContainsKey(operation.Entity) &&
                                             changeOperationMap[operation.Entity] == ChangeOperation.Update,
                                             "Expected update operation was not returned from GetAssociatedChanges.");
                    break;

                case DomainOperation.Delete:
                    CompositionHelper.Assert(
                        changeOperationMap.ContainsKey(operation.Entity) &&
                        changeOperationMap[operation.Entity] == ChangeOperation.Delete,
                        "Expected delete operation was not returned from GetAssociatedChanges.");
                    break;
                }
            }

            // navigate all child changes specifying operation type
            foreach (CI_Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children, ChangeOperation.None))
            {
            }
            foreach (CI_Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children, ChangeOperation.Insert))
            {
            }
            foreach (CI_Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children, ChangeOperation.Update))
            {
            }
            foreach (CI_Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children, ChangeOperation.Delete))
            {
            }
        }
Пример #7
0
 public void CustomOp_Parent(Parent parent)
 {
     CompositionHelper.Validate(parent);
     this.SetOperationInvoked(parent, "CustomOp_Parent");
     ((CompositionEntityBase)parent).OperationResult += ",CustomOp_Parent";
 }
Пример #8
0
        public void UpdateParent(Parent parent)
        {
            // first validate the hierarchy
            CompositionHelper.Validate(parent);

            ((CompositionEntityBase)parent).OperationResult = "Update";

            // for an updated, children might be added, updated
            // or deleted. We need to enumerate all and act appropriately
            foreach (Child child in this.ChangeSet.GetAssociatedChanges(parent, p => p.Children))
            {
                ChangeOperation changeOp = this.ChangeSet.GetChangeOperation(child);
                if (changeOp == ChangeOperation.Insert)
                {
                    ((CompositionEntityBase)child).OperationResult = "Insert";
                }
                else if (changeOp == ChangeOperation.Update)
                {
                    ((CompositionEntityBase)child).OperationResult = "Update";
                }
                else if (changeOp == ChangeOperation.Delete)
                {
                    ((CompositionEntityBase)child).OperationResult = "Delete";
                }

                // now process child updates for the child
                foreach (GrandChild grandChild in this.ChangeSet.GetAssociatedChanges(child, p => p.Children))
                {
                    changeOp = this.ChangeSet.GetChangeOperation(grandChild);
                    if (changeOp == ChangeOperation.Insert)
                    {
                        ((CompositionEntityBase)grandChild).OperationResult = "Insert";
                    }
                    else if (changeOp == ChangeOperation.Update)
                    {
                        ((CompositionEntityBase)grandChild).OperationResult = "Update";
                    }
                    else if (changeOp == ChangeOperation.Delete)
                    {
                        ((CompositionEntityBase)grandChild).OperationResult = "Delete";
                    }

                    // finally, process any great grand child updates
                    GreatGrandChild updatedGreateGrandChild = this.ChangeSet.GetAssociatedChanges(grandChild, p => p.Child).Cast <GreatGrandChild>().SingleOrDefault();
                    if (updatedGreateGrandChild != null)
                    {
                        changeOp = this.ChangeSet.GetChangeOperation(updatedGreateGrandChild);
                        if (changeOp == ChangeOperation.Insert)
                        {
                            ((CompositionEntityBase)updatedGreateGrandChild).OperationResult = "Insert";
                        }
                        else if (changeOp == ChangeOperation.Update)
                        {
                            ((CompositionEntityBase)updatedGreateGrandChild).OperationResult = "Update";
                        }
                        else if (changeOp == ChangeOperation.Delete)
                        {
                            ((CompositionEntityBase)updatedGreateGrandChild).OperationResult = "Delete";
                        }
                    }
                }
            }
        }
Пример #9
0
 public IQueryable <Parent> GetParents()
 {
     return(CompositionHelper.CreateCompositionHierarchy().AsQueryable());
 }