Skip to content

Commit

Permalink
Add unit-tests for EnableCopySymbolsAndXmlDocsToOutputDir
Browse files Browse the repository at this point in the history
  • Loading branch information
ocalles committed Sep 8, 2022
1 parent 67a795b commit 25590b0
Showing 1 changed file with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Xunit.Abstractions;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Security.Cryptography;

namespace Microsoft.NET.Build.Tests
{
Expand Down Expand Up @@ -530,7 +531,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 +851,96 @@ public void It_allows_TargetFrameworkVersion_to_be_capitalized()
.Should()
.Pass();
}

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

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

// Should copy xml and pdb files to output directory
testProject.AdditionalProperties.Add("EnableCopySymbolsAndXmlDocsToOutputDir", enableSymbolsAndXmlFiles);

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

var buildCommand = new BuildCommand(testAsset);

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

// By default Xml documentation is copied to the output directory
var outputDirectory = buildCommand.GetOutputDirectory(testProject.TargetFrameworks);

if (enableSymbolsAndXmlFiles == "true")
{
outputDirectory.Should().HaveFile("Microsoft.Build.dll");
outputDirectory.Should().HaveFile("Microsoft.Build.pdb");
outputDirectory.Should().HaveFile("Microsoft.Build.xml");
} else
{
outputDirectory.Should().HaveFile("Microsoft.Build.dll");
outputDirectory.Should().NotHaveFile("Microsoft.Build.pdb");
outputDirectory.Should().NotHaveFile("Microsoft.Build.xml");
}
}

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

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

// Should copy xml and pdb files to output directory
testProject.AdditionalProperties.Add("EnableCopySymbolsAndXmlDocsToOutputDir", enableSymbolsAndXmlFiles);

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();

// By default Xml documentation is copied to the output directory
var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks);

if (enableSymbolsAndXmlFiles == "true")
{
publishDirectory.Should().HaveFile("Microsoft.Build.dll");
publishDirectory.Should().HaveFile("Microsoft.Build.pdb");
publishDirectory.Should().HaveFile("Microsoft.Build.xml");
}
else
{
publishDirectory.Should().HaveFile("Microsoft.Build.dll");
publishDirectory.Should().NotHaveFile("Microsoft.Build.pdb");
publishDirectory.Should().NotHaveFile("Microsoft.Build.xml");
}
}
}
}

0 comments on commit 25590b0

Please sign in to comment.