Пример #1
0
        /// <summary>
        /// Compares two trees and verifies if the scope nodes are equal
        /// </summary>
        /// <param name="root1"></param>
        /// <param name="root2"></param>
        /// <returns></returns>
        private static bool AreScopesEqual(ScopeNodeDto root1, ScopeNodeDto root2)
        {
            if (root1 == null && root2 == null)
            {
                return(true);
            }

            if (root1 == null || root2 == null)
            {
                return(false);
            }

            if (!string.Equals(root1.State?.ToString(), root2.State?.ToString(), StringComparison.OrdinalIgnoreCase) ||
                root1.Children.Count != root2.Children.Count)
            {
                return(false);
            }

            bool isChildScopeEqual = true;

            for (int i = 0; i < root1.Children.Count; i++)
            {
                isChildScopeEqual = AreScopesEqual(root1.Children[i], root2.Children[i]);

                if (!isChildScopeEqual)
                {
                    break;
                }
            }

            return(isChildScopeEqual);
        }
Пример #2
0
        /// <summary>
        /// Gets a scope node with the given name
        /// </summary>
        /// <param name="activities"></param>
        /// <param name="scopeName"></param>
        /// <returns>A scope node if found, else null</returns>
        public static ScopeNodeDto FindScope(this IEnumerable <ActivityContextDto> activities,
                                             string scopeName)
        {
            ScopeNodeDto node = null;

            foreach (var activity in activities)
            {
                if (activity.RepresentsScope)
                {
                    node = GetScope(activity.Root, scopeName);

                    // Ideally we do not expect multiple scopes with the same name
                    // to exist in the logs, so we break on the first found scope node.
                    // Note: The logs can contain multiple scopes with the same name across
                    // different requests, but the tests are expected to filter the logs by request
                    // (ex: using request trace id) and then find the scope by name.
                    if (node != null)
                    {
                        return(node);
                    }
                }
            }

            return(node);
        }
Пример #3
0
        /// <summary>
        /// Traverses through the log node tree and gets the log messages whose StateType
        /// matches the supplied data type.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="logInfoDtos"></param>
        private static void GetLogsByDataType <T>(ScopeNodeDto node, IList <LogInfoDto> logInfoDtos)
        {
            foreach (var logInfo in node.Messages.OfDataType <T>())
            {
                logInfoDtos.Add(logInfo);
            }

            foreach (var scopeNode in node.Children)
            {
                GetLogsByDataType <T>(scopeNode, logInfoDtos);
            }
        }
Пример #4
0
        /// <summary>
        /// Traverses the scope node sub-tree and collects the list scopes
        /// </summary>
        /// <param name="root"></param>
        /// <param name="scopes"></param>
        private static void TraverseScopeTree(ScopeNodeDto root, List <string> scopes)
        {
            if (root == null)
            {
                return;
            }

            scopes.Add(root.State?.ToString());

            foreach (var childScope in root.Children)
            {
                TraverseScopeTree(childScope, scopes);
            }
        }
Пример #5
0
        /// <summary>
        /// Compares two trees and verifies if the scope nodes are equal
        /// </summary>
        /// <param name="expected"></param>
        /// <param name="actual"></param>
        /// <returns></returns>
        public static bool ScopesEqual(ScopeNodeDto expected, ScopeNodeDto actual)
        {
            // To enable diagnosis, here a flat-list(pe-order traversal based) of
            // these trees is provided.
            if (!AreScopesEqual(expected, actual))
            {
                var expectedScopes = new List <string>();
                var actualScopes   = new List <string>();

                TraverseScopeTree(expected, expectedScopes);
                TraverseScopeTree(actual, actualScopes);

                throw new EqualException(expected: string.Join(", ", expectedScopes),
                                         actual: string.Join(", ", actualScopes));
            }

            return(true);
        }
Пример #6
0
        private static ScopeNodeDto GetScope(ScopeNodeDto root, string scopeName)
        {
            if (string.Equals(root.State?.ToString(),
                              scopeName,
                              StringComparison.OrdinalIgnoreCase))
            {
                return(root);
            }

            foreach (var childNode in root.Children)
            {
                var foundNode = GetScope(childNode, scopeName);

                if (foundNode != null)
                {
                    return(foundNode);
                }
            }

            return(null);
        }