/// <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); } }
/// <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)) { } }