Removed the DIA classes and the cod associated with it. Introduced a PdbReaderFactory that decides with PdbReader to use (full or portable). Introduced a PdbReader interface that abstracts the differences between full pdb (Uses ISymUnmanaged classes to read the pdb) and portable pdb (uses Reflection MetadataReader).
This commit is contained in:
parent
811db45cf3
commit
85884c5e9a
54 changed files with 998 additions and 2555 deletions
|
@ -0,0 +1,85 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using TestAppWithFullPdbs;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Extensions.Testing.Abstractions.Tests
|
||||
{
|
||||
public class GivenThatIWantToUseFullPdbsToFindMethodInformation
|
||||
{
|
||||
public FullPdbReader _pdbReader;
|
||||
|
||||
public GivenThatIWantToUseFullPdbsToFindMethodInformation()
|
||||
{
|
||||
var stream = new FileStream(
|
||||
Path.Combine(AppContext.BaseDirectory, "TestAppWithFullPdbs.pdb"),
|
||||
FileMode.Open,
|
||||
FileAccess.Read);
|
||||
_pdbReader = new FullPdbReader(stream);
|
||||
}
|
||||
|
||||
[WindowsOnlyFact]
|
||||
public void It_returns_the_right_file_and_the_right_file_number_when_the_method_exists_in_the_pdb()
|
||||
{
|
||||
var type = typeof(ClassForFullPdbs);
|
||||
var methodInfo = type.GetMethod("TestMethodForFullPdbs");
|
||||
|
||||
var sourceInformation = _pdbReader.GetSourceInformation(methodInfo);
|
||||
|
||||
sourceInformation.Should().NotBeNull();
|
||||
sourceInformation.Filename.Should().Contain("ClassForFullPdbs.cs");
|
||||
sourceInformation.LineNumber.Should().Be(6);
|
||||
}
|
||||
|
||||
[WindowsOnlyFact]
|
||||
public void It_returns_null_when_MethodInfo_is_null()
|
||||
{
|
||||
var type = typeof(ClassForFullPdbs);
|
||||
var methodInfo = type.GetMethod("Name_of_a_test_that_does_not_exist");
|
||||
|
||||
var sourceInformation = _pdbReader.GetSourceInformation(methodInfo);
|
||||
|
||||
sourceInformation.Should().BeNull();
|
||||
}
|
||||
|
||||
[WindowsOnlyFact]
|
||||
public void It_returns_null_when_the_method_does_not_exist_in_the_pdb()
|
||||
{
|
||||
var type = typeof(PortablePdbReader);
|
||||
var methodInfo = type.GetMethod("GetSourceInformation");
|
||||
|
||||
var sourceInformation = _pdbReader.GetSourceInformation(methodInfo);
|
||||
|
||||
sourceInformation.Should().BeNull();
|
||||
}
|
||||
|
||||
[WindowsOnlyFact]
|
||||
public void It_allows_us_to_invoke_GetSourceInformation_multiple_times()
|
||||
{
|
||||
var type = typeof(ClassForFullPdbs);
|
||||
var firstMethodInfo = type.GetMethod("TestMethodForFullPdbs");
|
||||
var secondMethodInfo = type.GetMethod("AnotherTestMethodForFullPdbs");
|
||||
|
||||
var sourceInformation = _pdbReader.GetSourceInformation(secondMethodInfo);
|
||||
sourceInformation.Should().NotBeNull();
|
||||
sourceInformation.Filename.Should().Contain("ClassForFullPdbs.cs");
|
||||
sourceInformation.LineNumber.Should().Be(10);
|
||||
|
||||
sourceInformation = _pdbReader.GetSourceInformation(firstMethodInfo);
|
||||
sourceInformation.Should().NotBeNull();
|
||||
sourceInformation.Filename.Should().Contain("ClassForFullPdbs.cs");
|
||||
sourceInformation.LineNumber.Should().Be(6);
|
||||
|
||||
sourceInformation = _pdbReader.GetSourceInformation(secondMethodInfo);
|
||||
sourceInformation.Should().NotBeNull();
|
||||
sourceInformation.Filename.Should().Contain("ClassForFullPdbs.cs");
|
||||
sourceInformation.LineNumber.Should().Be(10);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using System.Reflection;
|
||||
using FluentAssertions;
|
||||
using TestAppWithPortablePdbs;
|
||||
|
||||
namespace Microsoft.Extensions.Testing.Abstractions.Tests
|
||||
{
|
||||
public class GivenThatIWantToUsePortablePdbsToFindMethodInformation
|
||||
{
|
||||
private PortablePdbReader _pdbReader;
|
||||
|
||||
public GivenThatIWantToUsePortablePdbsToFindMethodInformation()
|
||||
{
|
||||
var stream = new FileStream(
|
||||
Path.Combine(AppContext.BaseDirectory, "TestAppWithPortablePdbs.pdb"),
|
||||
FileMode.Open,
|
||||
FileAccess.Read);
|
||||
_pdbReader = new PortablePdbReader(stream);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_the_right_file_and_the_right_file_number_when_the_method_exists_in_the_pdb()
|
||||
{
|
||||
var type = typeof (ClassForPortablePdbs);
|
||||
var methodInfo = type.GetMethod("TestMethodForPortablePdbs");
|
||||
|
||||
var sourceInformation = _pdbReader.GetSourceInformation(methodInfo);
|
||||
|
||||
sourceInformation.Should().NotBeNull();
|
||||
sourceInformation.Filename.Should().Contain("ClassForPortablePdbs.cs");
|
||||
sourceInformation.LineNumber.Should().Be(6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_null_when_MethodInfo_is_null()
|
||||
{
|
||||
var type = typeof(ClassForPortablePdbs);
|
||||
var methodInfo = type.GetMethod("Name_of_a_test_that_does_not_exist");
|
||||
|
||||
var sourceInformation = _pdbReader.GetSourceInformation(methodInfo);
|
||||
|
||||
sourceInformation.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_null_when_the_method_does_not_exist_in_the_pdb()
|
||||
{
|
||||
var type = typeof(PortablePdbReader);
|
||||
var methodInfo = type.GetMethod("GetSourceInformation");
|
||||
|
||||
var sourceInformation = _pdbReader.GetSourceInformation(methodInfo);
|
||||
|
||||
sourceInformation.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_allows_us_to_invoke_GetSourceInformation_multiple_times()
|
||||
{
|
||||
var type = typeof(ClassForPortablePdbs);
|
||||
var firstMethodInfo = type.GetMethod("TestMethodForPortablePdbs");
|
||||
var secondMethodInfo = type.GetMethod("AnotherTestMethodForPortablePdbs");
|
||||
|
||||
var sourceInformation = _pdbReader.GetSourceInformation(secondMethodInfo);
|
||||
sourceInformation.Should().NotBeNull();
|
||||
sourceInformation.Filename.Should().Contain("ClassForPortablePdbs.cs");
|
||||
sourceInformation.LineNumber.Should().Be(10);
|
||||
|
||||
sourceInformation = _pdbReader.GetSourceInformation(firstMethodInfo);
|
||||
sourceInformation.Should().NotBeNull();
|
||||
sourceInformation.Filename.Should().Contain("ClassForPortablePdbs.cs");
|
||||
sourceInformation.LineNumber.Should().Be(6);
|
||||
|
||||
sourceInformation = _pdbReader.GetSourceInformation(secondMethodInfo);
|
||||
sourceInformation.Should().NotBeNull();
|
||||
sourceInformation.Filename.Should().Contain("ClassForPortablePdbs.cs");
|
||||
sourceInformation.LineNumber.Should().Be(10);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>09c61bd7-c6db-4f89-85bf-4eb3c196049d</ProjectGuid>
|
||||
<RootNamespace>Microsoft.Extensions.Testing.Abstractions.Tests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.5.0-rc2-23924",
|
||||
"Microsoft.Extensions.Testing.Abstractions": { "target": "project" },
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-23924",
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||
"TestAppWithFullPdbs": { "target": "project" },
|
||||
"TestAppWithPortablePdbs": { "target": "project" },
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-dev-91790-12",
|
||||
"FluentAssertions": "4.2.2"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netstandardapp1.5": {
|
||||
"imports": [
|
||||
"dnxcore50",
|
||||
"netstandard1.3",
|
||||
"portable-net45+win8"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"testRunner": "xunit"
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using System.Reflection;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace Microsoft.Extensions.Testing.Abstractions.UnitTests
|
||||
{
|
||||
public class GivenThatWeWantToUseSourceInformationProviderToGetSourceInformation
|
||||
{
|
||||
private string _pdbPath = Path.Combine(AppContext.BaseDirectory, "TestAppWithPortablePdbs.pdb");
|
||||
|
||||
[Fact]
|
||||
public void It_creates_a_pdb_reader_right_away()
|
||||
{
|
||||
var pdbReaderFactoryMock = new Mock<IPdbReaderFactory>();
|
||||
var sourceInformationProvider = new SourceInformationProvider(_pdbPath, null, pdbReaderFactoryMock.Object);
|
||||
|
||||
pdbReaderFactoryMock.Verify(p => p.Create(_pdbPath), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_uses_the_reader_to_get_the_SourceInformation()
|
||||
{
|
||||
var type = typeof(GivenThatWeWantToUseSourceInformationProviderToGetSourceInformation);
|
||||
var methodInfo = type.GetMethod("It_uses_the_reader_to_get_the_SourceInformation");
|
||||
|
||||
var expectedSourceInformation = new SourceInformation("some file path.cs", 12);
|
||||
var pdbReaderMock = new Mock<IPdbReader>();
|
||||
pdbReaderMock.Setup(p => p.GetSourceInformation(methodInfo)).Returns(expectedSourceInformation);
|
||||
|
||||
var pdbReaderFactoryMock = new Mock<IPdbReaderFactory>();
|
||||
pdbReaderFactoryMock.Setup(p => p.Create(_pdbPath)).Returns(pdbReaderMock.Object);
|
||||
|
||||
var sourceInformationProvider = new SourceInformationProvider(_pdbPath, null, pdbReaderFactoryMock.Object);
|
||||
|
||||
var actualSourceInformation = sourceInformationProvider.GetSourceInformation(methodInfo);
|
||||
|
||||
actualSourceInformation.Should().Be(expectedSourceInformation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_disposes_of_the_reader_when_it_gets_disposed()
|
||||
{
|
||||
var pdbReaderMock = new Mock<IPdbReader>();
|
||||
|
||||
var pdbReaderFactoryMock = new Mock<IPdbReaderFactory>();
|
||||
pdbReaderFactoryMock.Setup(p => p.Create(_pdbPath)).Returns(pdbReaderMock.Object);
|
||||
|
||||
using (var sourceInformationProvider =
|
||||
new SourceInformationProvider(_pdbPath, null, pdbReaderFactoryMock.Object))
|
||||
{
|
||||
}
|
||||
|
||||
pdbReaderMock.Verify(p => p.Dispose(), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>deb3ab06-fcd8-4119-b8ca-b7aa6ce2f22d</ProjectGuid>
|
||||
<RootNamespace>Microsoft.Extensions.Testing.Abstractions.UnitTests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.5.0-rc2-23924",
|
||||
"Microsoft.Extensions.Testing.Abstractions": { "target": "project" },
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-23924",
|
||||
"System.Diagnostics.Process": "4.1.0-rc2-23924",
|
||||
"TestAppWithPortablePdbs": { "target": "project" },
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-dev-91790-12",
|
||||
"FluentAssertions": "4.2.2",
|
||||
"moq.netcore": "4.4.0-beta8"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netstandardapp1.5": {
|
||||
"imports": [
|
||||
"dnxcore50",
|
||||
"netstandard1.3",
|
||||
"portable-net45+win8"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"testRunner": "xunit"
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
namespace TestAppWithFullPdbs
|
||||
{
|
||||
public class ClassForFullPdbs
|
||||
{
|
||||
public void TestMethodForFullPdbs()
|
||||
{
|
||||
}
|
||||
|
||||
public void AnotherTestMethodForFullPdbs()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.25029" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>0a37ab59-bdb5-4957-9bb8-d965f9a67a5b</ProjectGuid>
|
||||
<RootNamespace>TestAppWithFullPdbs</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
14
test/TestingAbstractions/TestAppWithFullPdbs/project.json
Normal file
14
test/TestingAbstractions/TestAppWithFullPdbs/project.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"debugType": "full"
|
||||
},
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.5.0-rc2-23924"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.5": {
|
||||
"imports": [ "portable-net45+win8", "dnxcore50" ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
namespace TestAppWithPortablePdbs
|
||||
{
|
||||
public class ClassForPortablePdbs
|
||||
{
|
||||
public void TestMethodForPortablePdbs()
|
||||
{
|
||||
}
|
||||
|
||||
public void AnotherTestMethodForPortablePdbs()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.25029" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>7b0efbb4-4669-4b83-b47c-7f3e6db07af9</ProjectGuid>
|
||||
<RootNamespace>TestAppWithPortablePdbs</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"debugType": "portable"
|
||||
},
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.5.0-rc2-23924"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.5": {
|
||||
"imports": [ "portable-net45+win8", "dnxcore50" ]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue