示例#1
0
        public TestCaseDTO[] DiscoverTests()
        {
            var conv = new DefaultConventions().Initialize();
            var finder = new SpecFinder(SandboxedAssembly.GetTypes(), "");
            var cb = new ContextBuilder(finder, new Tags());
            var dia = new DiaSession(SandboxedAssembly.Location);

            var examples = cb.Contexts()
                .Build()
                .AllContexts()
                .SelectMany(context => context.Examples);

            var result = from example in examples
                         let method = GetAction(example)
                         let location = dia.GetNavigationData(method.DeclaringType.FullName, method.Name)
                            ?? new DiaNavigationData(null, 0, 0)
                         select new TestCaseDTO
                         {
                             Name = example.FullName(),
                             FileName = location.FileName,
                             LineNumber = location.MinLineNumber,
                             Traits = example.Tags.ToArray()
                         };

            return result.ToArray();
        }
示例#2
0
        private IDiaEnumLineNumbers GetLineNumbers(uint addressSection, uint addressOffset, uint length)
        {
            IDiaEnumLineNumbers linenumbers;

            DiaSession.findLinesByAddr(addressSection, addressOffset, length, out linenumbers);
            return(linenumbers);
        }
示例#3
0
        public DebugInfoProvider(string binaryPath, ICrossDomainLogger logger)
        {
            this.binaryPath = binaryPath;
            this.logger     = logger;

            try
            {
                session = new DiaSession(binaryPath);
            }
            catch (Exception ex)
            {
                string message = String.Format("Cannot setup debug info for binary '{0}'", binaryPath);

                logger.Debug(new ExceptionLogInfo(ex), message);

                session = noSession;
            }

            try
            {
                asyncMethodHelper = new AsyncMethodHelper(binaryPath);
            }
            catch (Exception ex)
            {
                string message = String.Format("Cannot setup async debug info for binary '{0}'", binaryPath);

                logger.Debug(new ExceptionLogInfo(ex), message);

                asyncMethodHelper = noAsyncHelper;
            }
        }
示例#4
0
        // public for testing
        public DiaNavigationData GetNavigationData(string className, string methodName)
        {
            if (this.DiaSession == null)
            {
                return(null);
            }

            var navData = DiaSession.GetNavigationData(className, methodName);

            if (navData != null && navData.FileName != null)
            {
                return(navData);
            }

            // DiaSession.GetNavigationData returned null, see if it's an async method.
            if (AsyncMethodHelper != null)
            {
                string stateMachineClassName = AsyncMethodHelper.GetClassNameForAsyncMethod(className, methodName);
                if (stateMachineClassName != null)
                {
                    navData = diaSession.GetNavigationData(stateMachineClassName, "MoveNext");
                }
            }

            if (navData == null || navData.FileName == null)
            {
                logger.Warning(string.Format("No source data found for {0}.{1}", className, methodName));
            }

            return(navData);
        }
        public TestCaseDTO[] DiscoverTests()
        {
            var conv   = new DefaultConventions().Initialize();
            var finder = new SpecFinder(SandboxedAssembly.GetTypes(), "");
            var cb     = new ContextBuilder(finder, new Tags());
            var dia    = new DiaSession(SandboxedAssembly.Location);

            var examples = cb.Contexts()
                           .Build()
                           .AllContexts()
                           .SelectMany(context => context.Examples);

            var result = from example in examples
                         let method = GetAction(example)
                                      let location = dia.GetNavigationData(method.DeclaringType.FullName, method.Name)
                                                     ?? new DiaNavigationData(null, 0, 0)
                                                     select new TestCaseDTO
            {
                Name       = example.FullName(),
                FileName   = location.FileName,
                LineNumber = location.MinLineNumber,
                Traits     = example.Tags.ToArray()
            };

            return(result.ToArray());
        }
示例#6
0
        public void GetNavigationDataShouldReturnCorrectDataForAsyncMethod()
        {
            var currentTargetFrameWork = GetAndSetTargetFrameWork(this.testEnvironment);
            var assemblyPath           = this.GetAssetFullPath("SimpleClassLibrary.dll");

            DiaSession        diaSession        = new DiaSession(assemblyPath);
            DiaNavigationData diaNavigationData = diaSession.GetNavigationData("SimpleClassLibrary.Class1+<AsyncTestMethod>d__1", "MoveNext");

            Assert.IsNotNull(diaNavigationData, "Failed to get navigation data");
            StringAssert.EndsWith(diaNavigationData.FileName, @"\SimpleClassLibrary\Class1.cs");

            this.ValidateMinLineNumber(17, diaNavigationData.MinLineNumber);
            Assert.AreEqual(19, diaNavigationData.MaxLineNumber, "Incorrect max line number");

            this.testEnvironment.TargetFramework = currentTargetFrameWork;
        }
示例#7
0
        public void GetNavigationDataShouldReturnCorrectFileNameAndLineNumber()
        {
            var currentTargetFrameWork = GetAndSetTargetFrameWork(this.testEnvironment);
            var assemblyPath           = GetAssetFullPath("SimpleClassLibrary.dll");

            DiaSession        diaSession        = new DiaSession(assemblyPath);
            DiaNavigationData diaNavigationData = diaSession.GetNavigationData("SimpleClassLibrary.Class1", "PassingTest");

            Assert.IsNotNull(diaNavigationData, "Failed to get navigation data");
            StringAssert.EndsWith(diaNavigationData.FileName, @"\SimpleClassLibrary\Class1.cs");

            Assert.AreEqual(12, diaNavigationData.MinLineNumber, "Incorrect min line number");
            Assert.AreEqual(14, diaNavigationData.MaxLineNumber, "Incorrect max line number");

            this.testEnvironment.TargetFramework = currentTargetFrameWork;
        }
示例#8
0
        public void GetNavigationDataShouldReturnCorrectDataForOverLoadedMethod()
        {
            var currentTargetFrameWork = GetAndSetTargetFrameWork(this.testEnvironment);
            var assemblyPath           = this.GetAssetFullPath("SimpleClassLibrary.dll");

            DiaSession        diaSession        = new DiaSession(assemblyPath);
            DiaNavigationData diaNavigationData = diaSession.GetNavigationData("SimpleClassLibrary.Class1", "OverLoadedMethod");

            Assert.IsNotNull(diaNavigationData, "Failed to get navigation data");
            StringAssert.EndsWith(diaNavigationData.FileName, @"\SimpleClassLibrary\Class1.cs");

            // Weird why DiaSession is now returning the first overloaded method
            // as compared to before when it used to return second method
            this.ValidateLineNumbers(diaNavigationData.MinLineNumber, diaNavigationData.MaxLineNumber);

            this.testEnvironment.TargetFramework = currentTargetFrameWork;
        }
示例#9
0
        public void GetNavigationDataShouldReturnNullForNotExistMethodNameOrNotExistTypeName()
        {
            var currentTargetFrameWork = GetAndSetTargetFrameWork(this.testEnvironment);
            var assemblyPath           = GetAssetFullPath("SimpleClassLibrary.dll");

            DiaSession diaSession = new DiaSession(assemblyPath);

            // Not exist method name
            DiaNavigationData diaNavigationData = diaSession.GetNavigationData("SimpleClassLibrary.Class1", "NotExistMethod");

            Assert.IsNull(diaNavigationData);

            // Not Exist Type name
            diaNavigationData = diaSession.GetNavigationData("SimpleClassLibrary.NotExistType", "PassingTest");
            Assert.IsNull(diaNavigationData);

            this.testEnvironment.TargetFramework = currentTargetFrameWork;
        }
示例#10
0
        static void Main(string[] args)
        {
            var testAssemblyPath = @"C:\src\qata\src\tests\external\SomethingProject.Tests\bin\Debug\net461\SomethingProject.Tests.dll";
            var package          = new TestPackage(testAssemblyPath);
            var testEngine       = new TestEngine();
            var runner           = testEngine.GetRunner(package);
            var nUnitXml         = runner.Explore(TestFilter.Empty);
            var session          = new DiaSession(testAssemblyPath);

            foreach (XmlNode testNode in nUnitXml.SelectNodes("//test-case"))
            {
                var testName       = testNode.Attributes["fullname"]?.Value;
                var className      = testNode.Attributes["classname"]?.Value;
                var methodName     = testNode.Attributes["methodname"]?.Value;
                var navigationData = session.GetNavigationData(className, methodName);
                Console.WriteLine($"{testName} - {navigationData.FileName} - {navigationData.MinLineNumber}.");
            }
        }
示例#11
0
        public DiaNavigationData GetNavigationData(string typeName, string methodName)
        {
            if (!sessionHasErrors)
                try
                {
                    if (session == null)
                    {
                        session = new DiaSession(assemblyFilename);
                    }

                    return session.GetNavigationData(typeName, methodName);
                }
                catch
                {
                    sessionHasErrors = true;
                }

            return null;
        }
示例#12
0
        private static TestCase CreateTestCase(MemberInfo member, string source, IMessageLogger logger)
        {
            Debug.Assert(member.DeclaringType != null, "member.DeclaringType != null");

            var fullyQualifiedName = $"{member.DeclaringType.FullName}.{member.Name}";

            logger?.SendMessage(TestMessageLevel.Informational, $"Creating test case for {fullyQualifiedName}");

            using var session = new DiaSession(source);
            var data = session.GetNavigationData(member.DeclaringType.FullName, member.Name);

            var test = new TestCase(fullyQualifiedName, new Uri(TestKitchenTestExecutor.ExecutorUri, UriKind.Absolute), source)
            {
                CodeFilePath = data.FileName,
                LineNumber   = data.MinLineNumber + 1,
                DisplayName  = member.Name.Replace("_", " ")
            };

            return(test);
        }
示例#13
0
        public void DiaSessionPerfTest()
        {
            var currentTargetFrameWork = GetAndSetTargetFrameWork(this.testEnvironment);
            var assemblyPath           = this.GetAssetFullPath("SimpleClassLibrary.dll");

            var               watch             = Stopwatch.StartNew();
            DiaSession        diaSession        = new DiaSession(assemblyPath);
            DiaNavigationData diaNavigationData = diaSession.GetNavigationData("SimpleClassLibrary.HugeMethodSet", "MSTest_D1_01");

            watch.Stop();

            Assert.IsNotNull(diaNavigationData, "Failed to get navigation data");
            StringAssert.EndsWith(diaNavigationData.FileName, @"\SimpleClassLibrary\HugeMethodSet.cs");
            this.ValidateMinLineNumber(9, diaNavigationData.MinLineNumber);
            Assert.AreEqual(10, diaNavigationData.MaxLineNumber);
            var expectedTime = 150;

            Assert.IsTrue(watch.Elapsed.Milliseconds < expectedTime, string.Format("DiaSession Perf test Actual time:{0} ms Expected time:{1} ms", watch.Elapsed.Milliseconds, expectedTime));

            this.testEnvironment.TargetFramework = currentTargetFrameWork;
        }
示例#14
0
        static TestCase GetTestCase(string source, XmlNode methodNode)
        {
            string typeName           = methodNode.Attributes["type"].Value;
            string methodName         = methodNode.Attributes["method"].Value;
            string displayName        = methodNode.Attributes["name"].Value;
            string fullyQualifiedName = typeName + "." + methodName;

            TestCase testCase = new TestCase(fullyQualifiedName, uri)
            {
                DisplayName = GetDisplayName(displayName, methodName, fullyQualifiedName),
                Source      = source,
            };

            try {
                using (DiaSession diaSession = new DiaSession(source)) {
                    DiaNavigationData navigationData = diaSession.GetNavigationData(typeName, methodName);
                    testCase.CodeFilePath = navigationData.FileName;
                    testCase.LineNumber   = navigationData.MinLineNumber;
                }
            }
            catch { } // DiaSession throws if the PDB file is missing or corrupt

            return(testCase);
        }
示例#15
0
        /// <summary>
        /// Populate cache with <paramref name="source"/>.
        /// </summary>
        /// <param name="source"> Source to cache. </param>
        public static void PopulateCache(string source)
        {
            ValidateArg.NotNullOrEmpty(source, nameof(source));

            _cache[source] = new DiaSession(source);
        }
 /// <summary>
 /// Creates the discovery information access session.
 /// </summary>
 /// <param name="assemblyPath">The assembly path.</param>
 internal void CreateDiaSession(string assemblyPath)
 {
     this.diaSession = new DiaSession(assemblyPath);
 }
示例#17
0
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (this.diaSession != null) this.diaSession.Dispose();
         if (this.asyncMethodHelperDomain != null) AppDomain.Unload(this.asyncMethodHelperDomain);
     }
     diaSession = null;
     asyncMethodHelperDomain = null;
 }
示例#18
0
        static TestCase GetTestCase(string source, XmlNode methodNode)
        {
            string typeName = methodNode.Attributes["type"].Value;
            string methodName = methodNode.Attributes["method"].Value;
            string displayName = methodNode.Attributes["name"].Value;
            string fullyQualifiedName = typeName + "." + methodName;

            TestCase testCase = new TestCase(fullyQualifiedName, uri) {
                DisplayName = GetDisplayName(displayName, methodName, fullyQualifiedName),
                Source = source,
            };

            try {
                using (DiaSession diaSession = new DiaSession(source)) {
                    DiaNavigationData navigationData = diaSession.GetNavigationData(typeName, methodName);
                    testCase.CodeFilePath = navigationData.FileName;
                    testCase.LineNumber = navigationData.MinLineNumber;
                }
            }
            catch { } // DiaSession throws if the PDB file is missing or corrupt

            return testCase;
        }