From 25590b005254a56a90f10c774f796bc543d442cd Mon Sep 17 00:00:00 2001 From: Osvaldo Calles Date: Wed, 7 Sep 2022 17:43:35 -0700 Subject: [PATCH] Add unit-tests for EnableCopySymbolsAndXmlDocsToOutputDir --- .../GivenThatWeWantToBuildADesktopExe.cs | 94 ++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs index 3e2f9987c8cc..a000c4c8186e 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs @@ -19,6 +19,7 @@ using Xunit.Abstractions; using System.Text.RegularExpressions; using System.Collections.Generic; +using System.Security.Cryptography; namespace Microsoft.NET.Build.Tests { @@ -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; @@ -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"); + } + } } }