Beispiel #1
0
        protected internal virtual void writeTree(StringWriter writer, string prefix, bool isTail)
        {
            writer.append(prefix);
            if (isTail)
            {
                writer.append("└── ");
            }
            else
            {
                writer.append("├── ");
            }

            writer.append(getActivityIds() + "\n");

            for (int i = 0; i < childTransitionInstances.Count; i++)
            {
                ExpectedTransitionInstance transitionInstance = childTransitionInstances[i];
                bool transitionIsTail = (i == (childTransitionInstances.Count - 1)) && (childActivityInstances.Count == 0);
                writeTransition(transitionInstance, writer, prefix + (isTail ? "    " : "│   "), transitionIsTail);
            }

            for (int i = 0; i < childActivityInstances.Count; i++)
            {
                ExpectedActivityInstance child = childActivityInstances[i];
                child.writeTree(writer, prefix + (isTail ? "    " : "│   "), (i == (childActivityInstances.Count - 1)));
            }
        }
Beispiel #2
0
            /// <summary>
            /// if anyone wants to improve this algorithm, feel welcome! </summary>
            protected internal virtual bool isTreeMatched(ExpectedActivityInstance expectedInstance, ActivityInstance actualInstance)
            {
                if (!expectedInstance.getActivityIds().Contains(actualInstance.ActivityId))
                {
                    return(false);
                }
                else
                {
                    if (expectedInstance.ChildActivityInstances.Count != actualInstance.ChildActivityInstances.Length)
                    {
                        return(false);
                    }
                    else
                    {
                        IList <ExpectedActivityInstance> unmatchedInstances = new List <ExpectedActivityInstance>(expectedInstance.ChildActivityInstances);
                        foreach (ActivityInstance child1 in actualInstance.ChildActivityInstances)
                        {
                            bool matchFound = false;
                            foreach (ExpectedActivityInstance child2 in new List <ExpectedActivityInstance>(unmatchedInstances))
                            {
                                if (isTreeMatched(child2, child1))
                                {
                                    unmatchedInstances.Remove(child2);
                                    matchFound = true;
                                    break;
                                }
                            }
                            if (!matchFound)
                            {
                                return(false);
                            }
                        }

                        IList <ExpectedTransitionInstance> unmatchedTransitionInstances = new List <ExpectedTransitionInstance>(expectedInstance.ChildTransitionInstances);
                        foreach (TransitionInstance child in actualInstance.ChildTransitionInstances)
                        {
                            IEnumerator <ExpectedTransitionInstance> expectedTransitionInstanceIt = unmatchedTransitionInstances.GetEnumerator();

                            bool matchFound = false;
                            while (expectedTransitionInstanceIt.MoveNext() && !matchFound)
                            {
                                ExpectedTransitionInstance expectedChild = expectedTransitionInstanceIt.Current;
                                if (expectedChild.ActivityId.Equals(child.ActivityId))
                                {
                                    matchFound = true;
//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                                    expectedTransitionInstanceIt.remove();
                                }
                            }

                            if (!matchFound)
                            {
                                return(false);
                            }
                        }
                    }
                    return(true);
                }
            }
Beispiel #3
0
            protected internal virtual void assertTreeMatch(ExpectedActivityInstance expected, ActivityInstance actual)
            {
                bool treesMatch = isTreeMatched(expected, actual);

                if (!treesMatch)
                {
                    Assert.fail("Could not match expected tree \n" + expected + " \n\n with actual tree \n\n " + actual);
                }
            }
Beispiel #4
0
            public virtual ActivityInstanceTreeBuilder transition(string activityId)
            {
                ExpectedTransitionInstance newInstance = new ExpectedTransitionInstance();

                newInstance.ActivityId = activityId;
                ExpectedActivityInstance parentInstance = activityInstanceStack.Peek();

                IList <ExpectedTransitionInstance> childInstances = new List <ExpectedTransitionInstance>(parentInstance.ChildTransitionInstances);

                childInstances.Add(newInstance);
                parentInstance.ChildTransitionInstances = childInstances;

                return(this);
            }
Beispiel #5
0
            public virtual ActivityInstanceTreeBuilder beginScope(params string[] activityIds)
            {
                ExpectedActivityInstance newInstance = new ExpectedActivityInstance();

                newInstance.setActivityIds(activityIds);

                ExpectedActivityInstance         parentInstance = activityInstanceStack.Peek();
                IList <ExpectedActivityInstance> childInstances = new List <ExpectedActivityInstance>(parentInstance.ChildActivityInstances);

                childInstances.Add(newInstance);
                parentInstance.ChildActivityInstances = childInstances;

                activityInstanceStack.Push(newInstance);

                return(this);
            }
Beispiel #6
0
 public virtual void hasStructure(ExpectedActivityInstance expected)
 {
     assertTreeMatch(expected, actual);
 }
Beispiel #7
0
 public ActivityInstanceTreeBuilder(string rootActivityId)
 {
     rootInstance            = new ExpectedActivityInstance();
     rootInstance.ActivityId = rootActivityId;
     activityInstanceStack.Push(rootInstance);
 }