Skip to content

Commit

Permalink
Add unit-tests for copy debug symbols and documentation to output dir…
Browse files Browse the repository at this point in the history
…ectory

- Testing CopyDebugSymbolFilesFromPackages and CopyDocumentationFilesFromPackagesAdd unit-tests for EnableCopySymbolsAndXmlDocsToOutputDir
  • Loading branch information
ocalles committed Sep 9, 2022
1 parent b8c9610 commit 0231a17
Showing 1 changed file with 152 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
using Xunit.Abstractions;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Reflection.Metadata;

namespace Microsoft.NET.Build.Tests
{
Expand Down Expand Up @@ -530,7 +532,7 @@ void Test_inbox_assembly_wins_conflict_resolution(bool useSdkProject, string htt

testProject.PackageReferences.Add(new TestPackageReference("System.Net.Http", httpPackageVersion));

testProject.SourceFiles["Program.cs"] =
testProject.SourceFiles["Program.cs"] =
(useAlias ? "extern alias snh;" + Environment.NewLine : "") +

@"using System;
Expand Down Expand Up @@ -850,5 +852,154 @@ public void It_allows_TargetFrameworkVersion_to_be_capitalized()
.Should()
.Pass();
}

[WindowsOnlyTheory]
[InlineData("true", "true")]
[InlineData("true", "false")]
[InlineData("false", "true")]
[InlineData("false", "false")]
public void It_places_package_pdb_and_xml_files_in_output_directory(string enableCopyDebugSymbolFilesFromPackages, string enableDocumentationFilesFromPackages)
{
var testProject = new TestProject()
{
Name = "DesktopUsingPackageWithPdbAndXml",
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
IsExe = true,
};

testProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1"));

testProject.AdditionalProperties.Add("CopyDebugSymbolFilesFromPackages", enableCopyDebugSymbolFilesFromPackages);
testProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", enableDocumentationFilesFromPackages);

TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name);

var buildCommand = new BuildCommand(testAsset);

buildCommand
.Execute()
.Should()
.Pass();

var outputDirectory = buildCommand.GetOutputDirectory(testProject.TargetFrameworks);

HelperCheckPdbAndDocumentation(outputDirectory, "Microsoft.Build", enableCopyDebugSymbolFilesFromPackages, enableDocumentationFilesFromPackages);
}

[WindowsOnlyTheory]
[InlineData("true", "true")]
[InlineData("true", "false")]
[InlineData("false", "true")]
[InlineData("false", "false")]
public void It_places_package_pdb_and_xml_files_from_project_references_in_output_directory(string enableCopyDebugSymbolFilesFromPackages, string enableDocumentationFilesFromPackages)
{
var libraryProject = new TestProject()
{
Name = "ProjectWithPackage",
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
IsExe = false,
};

libraryProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1"));

var consumerProject = new TestProject()
{
Name = "ConsumerProject",
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
IsExe = true,
};

consumerProject.AdditionalProperties.Add("CopyDebugSymbolFilesFromPackages", enableCopyDebugSymbolFilesFromPackages);
consumerProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", enableDocumentationFilesFromPackages);

consumerProject.ReferencedProjects.Add(libraryProject);

TestAsset testAsset = _testAssetsManager.CreateTestProject(consumerProject, consumerProject.Name);

var buildCommand = new BuildCommand(testAsset);

buildCommand
.Execute()
.Should()
.Pass();

var outputDirectory = buildCommand.GetOutputDirectory(libraryProject.TargetFrameworks);

HelperCheckPdbAndDocumentation(outputDirectory, "Microsoft.Build", enableCopyDebugSymbolFilesFromPackages, enableDocumentationFilesFromPackages);
}

[WindowsOnlyTheory]
[InlineData("true", "true")]
[InlineData("true", "false")]
[InlineData("false", "true")]
[InlineData("false", "false")]
public void It_places_package_pdb_and_xml_files_in_publish_directory(string enableCopyDebugSymbolFilesFromPackages, string enableDocumentationFilesFromPackages)
{
var testProject = new TestProject()
{
Name = "DesktopPublishPackageWithPdbAndXml",
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
IsExe = true,
};

testProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1"));

testProject.AdditionalProperties.Add("CopyDebugSymbolFilesFromPackages", enableCopyDebugSymbolFilesFromPackages);
testProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", enableDocumentationFilesFromPackages);

TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name);

var buildCommand = new BuildCommand(testAsset);

buildCommand
.Execute()
.Should()
.Pass();

var publishCommand = new PublishCommand(testAsset);

publishCommand
.Execute()
.Should()
.Pass();

var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks);

HelperCheckPdbAndDocumentation(publishDirectory, "Microsoft.Build", enableCopyDebugSymbolFilesFromPackages, enableDocumentationFilesFromPackages);
}

void HelperCheckPdbAndDocumentation(
DirectoryInfo directoryInfo,
string packageName,
string enableCopyDebugSymbolFilesFromPackages,
string enableDocumentationFilesFromPackages)
{
string assemblyFile = packageName + ".dll";
string pdbFile = packageName + ".pdb";
string docFile = packageName + ".xml";

ShouldHave(assemblyFile);
if (enableCopyDebugSymbolFilesFromPackages == "true")
{
ShouldHave(pdbFile);
}
else
{
ShouldNotHave(pdbFile);
}

if (enableDocumentationFilesFromPackages == "true")
{
ShouldHave(docFile);
}
else
{
ShouldNotHave(docFile);
}

void ShouldHave(string file) => directoryInfo.Should().HaveFile(file);

void ShouldNotHave(string file) => directoryInfo.Should().NotHaveFile(file);
}
}
}

0 comments on commit 0231a17

Please sign in to comment.