Beispiel #1
0
        private static bool IsMethodUsedByAnyTestMethods(
            MethodInfo method,
            Tuple <MethodInfo, MethodDeclaration>[] testMethodsWithDeclaration)
        {
            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var tuple in testMethodsWithDeclaration)
            {
                var astNodeForTestMethod = DecompilerMethodHelper.GetAstNodeForMethod(method, tuple.Item2);
                if (astNodeForTestMethod == null)
                {
                    continue;
                }

                if (IsMethodUsedByTestMethod(method, astNodeForTestMethod, testMethodsWithDeclaration))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        private static bool IsMethodUsedByTestMethod(
            MethodInfo method,
            Tuple <AstNode, List <AstNode> > astNodeForTestMethodAndParameters,
            Tuple <MethodInfo, MethodDeclaration>[] testMethodsWithDeclaration)
        {
            if (method.DeclaringType == null)
            {
                throw new Exception("method.DeclaringType is null...");
            }

            var parameters = method.GetParameters();

            if (parameters.Any())
            {
                if (method.IsDefined(typeof(ExtensionAttribute)))
                {
                    return(ParametersNamingMatchHelper.Extension(parameters, astNodeForTestMethodAndParameters));
                }

                if (method.DeclaringType != null && method.DeclaringType.IsGenericType)
                {
                    return(ParametersNamingMatchHelper.Generic(parameters, astNodeForTestMethodAndParameters));
                }

                return(ParametersNamingMatchHelper.Regular(parameters, astNodeForTestMethodAndParameters));
            }

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var tuple in testMethodsWithDeclaration)
            {
                var astNodeForMethod = DecompilerMethodHelper.GetAstNodeForMethod(tuple.Item2.Body, method.Name);
                if (astNodeForMethod != null)
                {
                    return(true);
                }
            }

            return(false);
        }