Example #1
0
        /// <summary>
        /// Gets Navigation data from caches
        /// </summary>
        /// <param name="declaringTypeName">
        /// Type name Ex: MyNameSpace.MyType
        /// </param>
        /// <param name="methodName">
        /// Method name in declaringTypeName Ex: Method1
        /// </param>
        /// <returns>
        /// <see cref="INavigationData"/>.
        /// Returns INavigationData which contains filename and line number.
        /// </returns>
        public INavigationData GetNavigationData(string declaringTypeName, string methodName)
        {
            INavigationData navigationData = null;
            IDiaSymbol      methodSymbol   = null;

            IDiaSymbol typeSymbol = this.GetTypeSymbol(declaringTypeName, SymTagEnum.SymTagCompiland);

            if (typeSymbol != null)
            {
                methodSymbol = this.GetMethodSymbol(typeSymbol, methodName);
            }
            else
            {
                // May be a managed C++ test assembly...
                string fullMethodName = declaringTypeName.Replace(".", "::");
                fullMethodName = fullMethodName + "::" + methodName;

                methodSymbol = this.GetTypeSymbol(fullMethodName, SymTagEnum.SymTagFunction);
            }

            if (methodSymbol != null)
            {
                navigationData = this.GetSymbolNavigationData(methodSymbol);
            }

            return(navigationData);
        }
Example #2
0
        public void DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
        {
            try
            {
                ValidateArg.NotNull(sources, nameof(sources));
                ValidateArg.NotNull(discoveryContext, nameof(discoveryContext));
                ValidateArg.NotNull(logger, nameof(logger));
                ValidateArg.NotNull(discoverySink, nameof(discoverySink));

                _vsLogger = logger;
                _engine.Logger.MessageEvent += MessageEventHandler;
                TestCycleCollection tests = _engine.DiscoverTests(sources);
                _engine.Logger.MessageEvent -= MessageEventHandler;

                foreach (string source in sources)
                {
                    DiaSessionCache.PopulateCache(source);
                }

                foreach (MUF.ITestMethodContext context in tests.TestContextLookup.Values)
                {
                    TestCase        testCase = AdpaterUtilites.ConvertToTestCase(context);
                    INavigationData nav      = DiaSessionCache.GetNavDataForMethod(testCase.Source, context.DeclaringType.FullName, context.MethodInfo.Name);
                    testCase.CodeFilePath = nav.FileName ?? string.Empty;
                    testCase.LineNumber   = nav.MinLineNumber;

                    discoverySink.SendTestCase(testCase);
                }
            }
            catch (Exception e)
            {
                _engine.Logger.RecordMessage(MUF.MessageLevel.Error, e.ToString());
            }
        }
        /// <summary>
        /// The get navigation data.
        /// </summary>
        /// <param name="declaringTypeName">
        /// The declaring type name.
        /// </param>
        /// <param name="methodName">
        /// The method name.
        /// </param>
        /// <returns>
        /// The <see cref="INavigationData"/>.
        /// </returns>
        public INavigationData GetNavigationData(string declaringTypeName, string methodName)
        {
            INavigationData navigationData = null;

            if (this.methodsNavigationDataForType.ContainsKey(declaringTypeName))
            {
                var methodDict = this.methodsNavigationDataForType[declaringTypeName];
                if (methodDict.ContainsKey(methodName))
                {
                    navigationData = methodDict[methodName];
                }
            }

            return(navigationData);
        }