diff --git a/TestPlatform.sln b/TestPlatform.sln index d439f2f6da..eac26bc1ef 100644 --- a/TestPlatform.sln +++ b/TestPlatform.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26009.0 +VisualStudioVersion = 15.0.26005.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED0C35EB-7F31-4841-A24F-8EB708FFA959}" EndProject @@ -118,6 +118,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerfTestProject", "test\Tes EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleDataCollector", "test\TestAssets\SimpleDataCollector\SimpleDataCollector.csproj", "{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleTestProject3", "test\TestAssets\SimpleTestProject3\SimpleTestProject3.csproj", "{82E75225-FA92-4F87-909D-039D62F96BFF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -644,6 +646,18 @@ Global {D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Release|x64.Build.0 = Release|Any CPU {D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Release|x86.ActiveCfg = Release|Any CPU {D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Release|x86.Build.0 = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|Any CPU.Build.0 = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|x64.ActiveCfg = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|x64.Build.0 = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|x86.ActiveCfg = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|x86.Build.0 = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Release|Any CPU.Build.0 = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x64.ActiveCfg = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x64.Build.0 = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x86.ActiveCfg = Release|Any CPU + {82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -698,5 +712,6 @@ Global {A23E3408-D569-488E-A071-E1B3625C5F09} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A} {57B182B8-9014-4C6D-B966-B464DE3127D5} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A} {D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A} + {82E75225-FA92-4F87-909D-039D62F96BFF} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A} EndGlobalSection EndGlobal diff --git a/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortablePdbReader.cs b/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortablePdbReader.cs index e6f7648451..c47849e61e 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortablePdbReader.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortablePdbReader.cs @@ -92,16 +92,25 @@ internal static MethodDebugInformationHandle GetMethodDebugInformationHandle(Met return handle; } - private static void GetMethodStartAndEndLineNumber( + private static void GetMethodMinAndMaxLineNumber( MethodDebugInformation methodDebugDefinition, - out int startLineNumber, - out int endLineNumber) + out int minLineNumber, + out int maxLineNumber) { - var startPoint = methodDebugDefinition.GetSequencePoints().OrderBy(s => s.StartLine).FirstOrDefault(); - startLineNumber = startPoint.StartLine; - var endPoint = - methodDebugDefinition.GetSequencePoints().OrderByDescending(s => s.StartLine).FirstOrDefault(); - endLineNumber = endPoint.StartLine; + minLineNumber = int.MaxValue; + maxLineNumber = int.MinValue; + var orderedSequencePoints = methodDebugDefinition.GetSequencePoints(); + foreach (var sequencePoint in orderedSequencePoints) + { + if (sequencePoint.IsHidden) + { + // Special sequence point with startLine is Magic number 0xFEEFEE + // Magic number comes from Potable CodeGen source code + continue; + } + minLineNumber = Math.Min(minLineNumber, sequencePoint.StartLine); + maxLineNumber = Math.Max(maxLineNumber, sequencePoint.StartLine); + } } /// @@ -134,10 +143,10 @@ private DiaNavigationData GetDiaNavigationData(MethodDebugInformationHandle hand { var methodDebugDefinition = this.reader.GetMethodDebugInformation(handle); var fileName = this.GetMethodFileName(methodDebugDefinition); - int startLineNumber, endLineNumber; - GetMethodStartAndEndLineNumber(methodDebugDefinition, out startLineNumber, out endLineNumber); + int minLineNumber, maxLineNumber; + GetMethodMinAndMaxLineNumber(methodDebugDefinition, out minLineNumber, out maxLineNumber); - diaNavigationData = new DiaNavigationData(fileName, startLineNumber, endLineNumber); + diaNavigationData = new DiaNavigationData(fileName, minLineNumber, maxLineNumber); } catch (BadImageFormatException exception) { diff --git a/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortableSymbolReader.cs b/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortableSymbolReader.cs index b2fa9dc282..64f36eb7f6 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortableSymbolReader.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortableSymbolReader.cs @@ -96,37 +96,33 @@ private void PopulateCacheForTypeAndMethodSymbols(string binaryPath) // Load assembly var asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(binaryPath); - // Get all types to dict, fullname as key - var typesDict = asm.GetTypes().ToDictionary(type => type.FullName); - foreach (var typeEntry in typesDict) + foreach (var type in asm.GetTypes()) { - // Get method infos for all types in assembly - var methodInfoDict = typeEntry.Value.GetMethods().ToDictionary(methodInfo => methodInfo.Name); + // Get declared method infos + var methodInfoList = ((TypeInfo)type.GetTypeInfo()).DeclaredMethods; var methodsNavigationData = new Dictionary(); - this.methodsNavigationDataForType.Add(typeEntry.Key, methodsNavigationData); - foreach (var methodEntry in methodInfoDict) + foreach (var methodInfo in methodInfoList) { - if (string.CompareOrdinal(methodEntry.Value.Module.FullyQualifiedName, binaryPath) != 0) - { - // Ignore inherent methods - continue; - } - - var diaNavigationData = pdbReader.GetDiaNavigationData(methodEntry.Value); + var diaNavigationData = pdbReader.GetDiaNavigationData(methodInfo); if (diaNavigationData != null) { - methodsNavigationData.Add(methodEntry.Key, diaNavigationData); + methodsNavigationData[methodInfo.Name] = diaNavigationData; } else { EqtTrace.Error( string.Format( "Unable to find source information for method: {0} type: {1}", - methodEntry.Key, - typeEntry.Key)); + methodInfo.Name, + type.FullName)); } } + + if (methodsNavigationData.Count != 0) + { + this.methodsNavigationDataForType[type.FullName] = methodsNavigationData; + } } } } diff --git a/test/Microsoft.TestPlatform.Common.UnitTests/Microsoft.TestPlatform.Common.UnitTests.csproj b/test/Microsoft.TestPlatform.Common.UnitTests/Microsoft.TestPlatform.Common.UnitTests.csproj index 702177b810..e61506db0b 100644 --- a/test/Microsoft.TestPlatform.Common.UnitTests/Microsoft.TestPlatform.Common.UnitTests.csproj +++ b/test/Microsoft.TestPlatform.Common.UnitTests/Microsoft.TestPlatform.Common.UnitTests.csproj @@ -1,22 +1,18 @@ - + $(MSBuildThisFileDirectory)../../ true - - Exe netcoreapp1.0;net46 Microsoft.TestPlatform.Common.UnitTests $(PackageTargetFallback);dnxcore50;portable-net45+win8 - - @@ -31,26 +27,25 @@ - 1.0.0 - - + + + - - + \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/Microsoft.TestPlatform.CommunicationUtilities.UnitTests.csproj b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/Microsoft.TestPlatform.CommunicationUtilities.UnitTests.csproj index 765ce55e9e..9342224eae 100644 --- a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/Microsoft.TestPlatform.CommunicationUtilities.UnitTests.csproj +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/Microsoft.TestPlatform.CommunicationUtilities.UnitTests.csproj @@ -4,18 +4,15 @@ true - Exe netcoreapp1.0;net46 Microsoft.TestPlatform.CommunicationUtilities.UnitTests $(PackageTargetFallback);dnxcore50;portable-net45+win8 - - @@ -28,19 +25,19 @@ true - 1.0.0 - - + + + - + \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Microsoft.TestPlatform.CrossPlatEngine.UnitTests.csproj b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Microsoft.TestPlatform.CrossPlatEngine.UnitTests.csproj index cfddfa336d..c33a0cd024 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Microsoft.TestPlatform.CrossPlatEngine.UnitTests.csproj +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Microsoft.TestPlatform.CrossPlatEngine.UnitTests.csproj @@ -4,18 +4,15 @@ true - Exe netcoreapp1.0;net46 Microsoft.TestPlatform.CrossPlatEngine.UnitTests $(PackageTargetFallback);dnxcore50;portable-net45+win8 - - @@ -28,19 +25,19 @@ true - 1.0.0 - + - - + + + - + \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.ObjectModel.PlatformTests/DiaSessionTests.cs b/test/Microsoft.TestPlatform.ObjectModel.PlatformTests/DiaSessionTests.cs index 60edd776e0..e851f806b7 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.PlatformTests/DiaSessionTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.PlatformTests/DiaSessionTests.cs @@ -40,8 +40,44 @@ public void GetNavigationDataShouldReturnCorrectFileNameAndLineNumber() Assert.IsNotNull(diaNavigationData, "Failed to get navigation data"); StringAssert.EndsWith(diaNavigationData.FileName, @"\SimpleTestProject\UnitTest1.cs"); - Assert.AreEqual(diaNavigationData.MinLineNumber, 23); - Assert.AreEqual(diaNavigationData.MaxLineNumber, 25); + Assert.AreEqual(23, diaNavigationData.MinLineNumber, "Incorrect min line number"); + Assert.AreEqual(25, diaNavigationData.MaxLineNumber, "Incorrect max line number"); + + this.testEnvironment.TargetFramework = currentTargetFrameWork; + } + + [TestMethod] + public void GetNavigationDataShouldReturnCorrectDataForAsyncMethod() + { + var currentTargetFrameWork = GetAndSetTargetFrameWork(this.testEnvironment); + var assemblyPath = this.GetAssetFullPath("SimpleTestProject3.dll"); + + DiaSession diaSession = new DiaSession(assemblyPath); + DiaNavigationData diaNavigationData = diaSession.GetNavigationData("SampleUnitTestProject3.UnitTest1+d__1", "MoveNext"); + + Assert.IsNotNull(diaNavigationData, "Failed to get navigation data"); + StringAssert.EndsWith(diaNavigationData.FileName, @"\SimpleTestProject3\UnitTest1.cs"); + + Assert.AreEqual(20, diaNavigationData.MinLineNumber, "Incorrect min line number"); + Assert.AreEqual(22, diaNavigationData.MaxLineNumber, "Incorrect max line number"); + + this.testEnvironment.TargetFramework = currentTargetFrameWork; + } + + [TestMethod] + public void GetNavigationDataShouldReturnCorrectDataForOverLoadedMethod() + { + var currentTargetFrameWork = GetAndSetTargetFrameWork(this.testEnvironment); + var assemblyPath = this.GetAssetFullPath("SimpleTestProject3.dll"); + + DiaSession diaSession = new DiaSession(assemblyPath); + DiaNavigationData diaNavigationData = diaSession.GetNavigationData("SampleUnitTestProject3.Class1", "OverLoadededMethod"); + + Assert.IsNotNull(diaNavigationData, "Failed to get navigation data"); + StringAssert.EndsWith(diaNavigationData.FileName, @"\SimpleTestProject3\UnitTest1.cs"); + + Assert.AreEqual(32, diaNavigationData.MinLineNumber, "Incorrect min line number"); + Assert.AreEqual(33, diaNavigationData.MaxLineNumber, "Incorrect max line number"); this.testEnvironment.TargetFramework = currentTargetFrameWork; } diff --git a/test/TestAssets/PerfTestProject/PerfTestProject.csproj b/test/TestAssets/PerfTestProject/PerfTestProject.csproj index 53a3878a9a..3868ff5b66 100644 --- a/test/TestAssets/PerfTestProject/PerfTestProject.csproj +++ b/test/TestAssets/PerfTestProject/PerfTestProject.csproj @@ -1,6 +1,5 @@ - + - netcoreapp1.0;net46 PerfTestProject @@ -14,13 +13,11 @@ false false - - 1.0.0-alpha-20161104-2 @@ -33,26 +30,24 @@ 1.0.4-preview - 1.0.0 - - portable - + + full + $(DefineConstants);RELEASE - - + \ No newline at end of file diff --git a/test/TestAssets/SimpleTestProject/SimpleTestProject.csproj b/test/TestAssets/SimpleTestProject/SimpleTestProject.csproj index 2384dadc14..685445c6d1 100644 --- a/test/TestAssets/SimpleTestProject/SimpleTestProject.csproj +++ b/test/TestAssets/SimpleTestProject/SimpleTestProject.csproj @@ -1,4 +1,4 @@ - + netcoreapp1.0;net46;netcoreapp1.1 @@ -53,6 +53,9 @@ portable + + full + $(DefineConstants);RELEASE diff --git a/test/TestAssets/SimpleTestProject2/SimpleTestProject2.csproj b/test/TestAssets/SimpleTestProject2/SimpleTestProject2.csproj index 5f0383fa90..9b026d5420 100644 --- a/test/TestAssets/SimpleTestProject2/SimpleTestProject2.csproj +++ b/test/TestAssets/SimpleTestProject2/SimpleTestProject2.csproj @@ -1,4 +1,4 @@ - + netcoreapp1.0;net46;netcoreapp1.1 @@ -25,22 +25,20 @@ 1.1.6-preview - + 15.0.0-preview-20161123-03 1.0.1 - + - 1.1.0 - @@ -49,6 +47,12 @@ + + portable + + + full + $(DefineConstants);RELEASE diff --git a/test/TestAssets/SimpleTestProject3/SimpleTestProject3.csproj b/test/TestAssets/SimpleTestProject3/SimpleTestProject3.csproj new file mode 100644 index 0000000000..a656902bfe --- /dev/null +++ b/test/TestAssets/SimpleTestProject3/SimpleTestProject3.csproj @@ -0,0 +1,60 @@ + + + + netcoreapp1.0;net46;netcoreapp1.1 + SimpleTestProject3 + $(PackageTargetFallback);dnxcore50;portable-net45+win8 + Exe + + + + + + + + + 1.0.0-alpha-20161104-2 + All + + + 1.6.0 + + + 1.0.6-preview + + + 1.1.6-preview + + + 15.0.0-preview-20161123-03 + + + + + 1.0.1 + + + + + 1.1.0 + + + + + + + + + + + + portable + + + full + + + $(DefineConstants);RELEASE + + + \ No newline at end of file diff --git a/test/TestAssets/SimpleTestProject3/UnitTest1.cs b/test/TestAssets/SimpleTestProject3/UnitTest1.cs new file mode 100644 index 0000000000..5f9361306b --- /dev/null +++ b/test/TestAssets/SimpleTestProject3/UnitTest1.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System.Threading.Tasks; + +namespace SampleUnitTestProject3 +{ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void PassingTest() + { + Assert.AreEqual(2, 2); + } + + [TestMethod] + public async Task AsyncTestMethod() + { + await Task.CompletedTask; + } + } + + public class Class1 + { + public void OverLoadededMethod() + { + } + + public void OverLoadededMethod(string name) + { + } + } +} diff --git a/test/vstest.console.UnitTests/vstest.console.UnitTests.csproj b/test/vstest.console.UnitTests/vstest.console.UnitTests.csproj index 995ede1750..3551a02a31 100644 --- a/test/vstest.console.UnitTests/vstest.console.UnitTests.csproj +++ b/test/vstest.console.UnitTests/vstest.console.UnitTests.csproj @@ -4,18 +4,15 @@ true - Exe netcoreapp1.0;net46 vstest.console.UnitTests $(PackageTargetFallback);dnxcore50;portable-net45+win8 - - @@ -38,13 +35,11 @@ true - 1.0.0 - + - @@ -52,6 +47,8 @@ - + + + - + \ No newline at end of file