public void TrackedObject_ЛоггируетсяСНеобходимымиСвойствами()
        {
            var exception = new InvalidOperationException("CycleDetected");
            var expected  = "\r\nTrackedObject.Current.TypeName = RootEntityWithInheritanceMapping\r\nTrackedObject.Current:\r\nCurrent.Id = 0\r\nTrackedObject.IsInteresting = False\r\nTrackedObject.IsDeleted = False\r\nTrackedObject.IsModified = False\r\nTrackedObject.IsDead = False\r\nTrackedObject.IsWeaklyTracked = False\r\n";

            var trackedObjectMock = new Mock <TrackedObject>(MockBehavior.Strict);

            trackedObjectMock.Setup(tom => tom.Current).Returns(new RootEntityWithInheritanceMapping());
            trackedObjectMock.Setup(tom => tom.IsInteresting).Returns(false);
            trackedObjectMock.Setup(tom => tom.IsDeleted).Returns(false);
            trackedObjectMock.Setup(tom => tom.IsModified).Returns(false);
            trackedObjectMock.Setup(tom => tom.IsDead).Returns(false);
            trackedObjectMock.Setup(tom => tom.IsWeaklyTracked).Returns(false);

            var trackedObjectLogFormatter = new TrackedObjectLogFormatter();
            var trackedObject             = trackedObjectMock.Object;

            trackedObjectLogFormatter.LogTrackedObject(trackedObject, "TrackedObject", exception);

            var data = exception.Data["TrackedObject"].ToString();

            Assert.AreEqual(expected, data);
        }
示例#2
0
        private void BuildDependencyOrderedList(TrackedObject item, List <TrackedObject> list, Dictionary <TrackedObject, VisitState> visited)
        {
            if (visited.TryGetValue(item, out VisitState state))
            {
                if (state == VisitState.Before)
                {
                    var cycleException = Error.CycleDetected();

                    var logFormatter = new TrackedObjectLogFormatter();

                    logFormatter.LogTrackedObject(item, "CurrentTrackedObject", cycleException);
                    logFormatter.LogTrackedList(list, "List<TrackedObject>", cycleException);
                    logFormatter.LogTrackedObjectVisitState(visited, "Dictionary<TrackedObject, VisitState> visited", cycleException);

                    throw cycleException;
                }
                return;
            }

            visited[item] = VisitState.Before;

            if (item.IsInteresting)
            {
                if (item.IsDeleted)
                {
                    // if 'item' is deleted
                    //    all objects that used to refer to 'item' must be ordered before item
                    foreach (TrackedObject other in this.originalChildReferences[item])
                    {
                        if (other != item)
                        {
                            this.BuildDependencyOrderedList(other, list, visited);
                        }
                    }
                }
                else
                {
                    // if 'item' is new or changed
                    //   for all objects 'other' that 'item' refers to along association 'assoc'
                    //      if 'other' is new then 'other' must be ordered before 'item'
                    //      if 'assoc' is pure one-to-one and some other item 'prevItem' used to refer to 'other'
                    //         then 'prevItem' must be ordered before 'item'
                    foreach (MetaAssociation assoc in item.Type.Associations)
                    {
                        if (assoc.IsForeignKey)
                        {
                            TrackedObject other = this.currentParentEdges[assoc, item];
                            if (other != null)
                            {
                                if (other.IsNew)
                                {
                                    // if other is new, visit other first (since item's FK depends on it)
                                    if (other != item || item.Type.DBGeneratedIdentityMember != null)
                                    {
                                        this.BuildDependencyOrderedList(other, list, visited);
                                    }
                                }
                                else if ((assoc.IsUnique || assoc.ThisKeyIsPrimaryKey))
                                {
                                    TrackedObject prevItem = this.originalChildEdges[assoc, other];
                                    if (prevItem != null && other != item)
                                    {
                                        this.BuildDependencyOrderedList(prevItem, list, visited);
                                    }
                                }
                            }
                        }
                    }
                }

                list.Add(item);
            }

            visited[item] = VisitState.After;
        }