Skip to content

Commit 25590b0

Browse files
committed
Add unit-tests for EnableCopySymbolsAndXmlDocsToOutputDir
1 parent 67a795b commit 25590b0

File tree

1 file changed

+93
-1
lines changed

1 file changed

+93
-1
lines changed

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Xunit.Abstractions;
2020
using System.Text.RegularExpressions;
2121
using System.Collections.Generic;
22+
using System.Security.Cryptography;
2223

2324
namespace Microsoft.NET.Build.Tests
2425
{
@@ -530,7 +531,7 @@ void Test_inbox_assembly_wins_conflict_resolution(bool useSdkProject, string htt
530531

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

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

536537
@"using System;
@@ -850,5 +851,96 @@ public void It_allows_TargetFrameworkVersion_to_be_capitalized()
850851
.Should()
851852
.Pass();
852853
}
854+
855+
[WindowsOnlyTheory]
856+
[InlineData("true")]
857+
[InlineData("false")]
858+
public void It_places_package_pdb_and_xml_files_in_output_directory_correctly(string enableSymbolsAndXmlFiles)
859+
{
860+
var testProject = new TestProject()
861+
{
862+
Name = "DesktopUsingPackageWithPdbAndXml",
863+
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
864+
IsExe = true,
865+
};
866+
867+
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1"));
868+
869+
// Should copy xml and pdb files to output directory
870+
testProject.AdditionalProperties.Add("EnableCopySymbolsAndXmlDocsToOutputDir", enableSymbolsAndXmlFiles);
871+
872+
TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name);
873+
874+
var buildCommand = new BuildCommand(testAsset);
875+
876+
buildCommand
877+
.Execute()
878+
.Should()
879+
.Pass();
880+
881+
// By default Xml documentation is copied to the output directory
882+
var outputDirectory = buildCommand.GetOutputDirectory(testProject.TargetFrameworks);
883+
884+
if (enableSymbolsAndXmlFiles == "true")
885+
{
886+
outputDirectory.Should().HaveFile("Microsoft.Build.dll");
887+
outputDirectory.Should().HaveFile("Microsoft.Build.pdb");
888+
outputDirectory.Should().HaveFile("Microsoft.Build.xml");
889+
} else
890+
{
891+
outputDirectory.Should().HaveFile("Microsoft.Build.dll");
892+
outputDirectory.Should().NotHaveFile("Microsoft.Build.pdb");
893+
outputDirectory.Should().NotHaveFile("Microsoft.Build.xml");
894+
}
895+
}
896+
897+
[WindowsOnlyTheory]
898+
[InlineData("true")]
899+
[InlineData("false")]
900+
public void It_places_package_xml_files_in_publish_directory_correctly(string enableSymbolsAndXmlFiles)
901+
{
902+
var testProject = new TestProject()
903+
{
904+
Name = "DesktopPublishPackageWithPdbAndXml",
905+
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
906+
IsExe = true,
907+
};
908+
909+
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1"));
910+
911+
// Should copy xml and pdb files to output directory
912+
testProject.AdditionalProperties.Add("EnableCopySymbolsAndXmlDocsToOutputDir", enableSymbolsAndXmlFiles);
913+
914+
TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name);
915+
916+
var buildCommand = new BuildCommand(testAsset);
917+
918+
buildCommand
919+
.Execute()
920+
.Should()
921+
.Pass();
922+
923+
var publishCommand = new PublishCommand(testAsset);
924+
publishCommand
925+
.Execute()
926+
.Should()
927+
.Pass();
928+
929+
// By default Xml documentation is copied to the output directory
930+
var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks);
931+
932+
if (enableSymbolsAndXmlFiles == "true")
933+
{
934+
publishDirectory.Should().HaveFile("Microsoft.Build.dll");
935+
publishDirectory.Should().HaveFile("Microsoft.Build.pdb");
936+
publishDirectory.Should().HaveFile("Microsoft.Build.xml");
937+
}
938+
else
939+
{
940+
publishDirectory.Should().HaveFile("Microsoft.Build.dll");
941+
publishDirectory.Should().NotHaveFile("Microsoft.Build.pdb");
942+
publishDirectory.Should().NotHaveFile("Microsoft.Build.xml");
943+
}
944+
}
853945
}
854946
}

0 commit comments

Comments
 (0)