From 7d6e836dd5e72961f1c68c3c7fc86b0cd0bb9c09 Mon Sep 17 00:00:00 2001 From: Rama Krishnan Raghupathy Date: Wed, 18 Jan 2017 17:04:40 -0800 Subject: [PATCH] Integration test for publish filter profile --- .../NewtonsoftFilterProfile.csproj | 7 ++ ...WeWantToPublishAProjectWithDependencies.cs | 112 ++++++++++++++++++ .../TestAssetsManager.cs | 2 +- 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 TestAssets/TestProjects/NewtonsoftFilterProfile/NewtonsoftFilterProfile.csproj diff --git a/TestAssets/TestProjects/NewtonsoftFilterProfile/NewtonsoftFilterProfile.csproj b/TestAssets/TestProjects/NewtonsoftFilterProfile/NewtonsoftFilterProfile.csproj new file mode 100644 index 000000000000..9088de6bbc0e --- /dev/null +++ b/TestAssets/TestProjects/NewtonsoftFilterProfile/NewtonsoftFilterProfile.csproj @@ -0,0 +1,7 @@ + + + + 9.0.1 + + + diff --git a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs index d2134ec06352..b0a58030e38c 100644 --- a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs +++ b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs @@ -8,6 +8,7 @@ using Microsoft.NET.TestFramework.Commands; using Xunit; using static Microsoft.NET.TestFramework.Commands.MSBuildTest; +using Microsoft.DotNet.InternalAbstractions; using System.Runtime.InteropServices; namespace Microsoft.NET.Publish.Tests @@ -109,5 +110,116 @@ public void It_publishes_projects_targeting_netcoreapp11_with_p2p_targeting_netc .Should() .Pass(); } + + [Fact] + public void It_publishes_projects_with_simple_dependencies_with_filter_profile() + { + TestAsset simpleDependenciesAsset = _testAssetsManager + .CopyTestAsset("SimpleDependencies") + .WithSource() + .Restore(); + + string filterProjDir = _testAssetsManager.GetAndValidateTestProjectDirectory("NewtonsoftFilterProfile"); + string filterProjFile = Path.Combine(filterProjDir, "NewtonsoftFilterProfile.csproj"); + + PublishCommand publishCommand = new PublishCommand(Stage0MSBuild, simpleDependenciesAsset.TestRoot); + publishCommand + .Execute($"/p:FilterProjFile={filterProjFile}") + .Should() + .Pass(); + + DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory(); + + publishDirectory.Should().OnlyHaveFiles(new[] { + "SimpleDependencies.dll", + "SimpleDependencies.pdb", + "SimpleDependencies.deps.json", + "SimpleDependencies.runtimeconfig.json", + "System.Collections.NonGeneric.dll" + }); +//TODO: Enable testing the run once dotnet host has the notion of looking up shared packages +// string appPath = publishCommand.GetPublishedAppPath("SimpleDependencies"); + +// Command runAppCommand = Command.Create( +// RepoInfo.DotNetHostPath, +// new[] { appPath, "one", "two" }); + +// string expectedOutput = +//@"{ +// ""one"": ""one"", +// ""two"": ""two"" +//}"; + +// runAppCommand +// .CaptureStdOut() +// .Execute() +// .Should() +// .Pass() +// .And +// .HaveStdOutContaining(expectedOutput); + } + + [Fact] + public void It_publishes_projects_with_filter_and_rid() + { + var rid = RuntimeEnvironment.GetRuntimeIdentifier(); + TestAsset simpleDependenciesAsset = _testAssetsManager + .CopyTestAsset("SimpleDependencies") + .WithSource() + .Restore("", $"/p:RuntimeIdentifier={rid}"); + + string filterProjDir = _testAssetsManager.GetAndValidateTestProjectDirectory("NewtonsoftFilterProfile"); + string filterProjFile = Path.Combine(filterProjDir, "NewtonsoftFilterProfile.csproj"); + + + PublishCommand publishCommand = new PublishCommand(Stage0MSBuild, simpleDependenciesAsset.TestRoot); + publishCommand + .Execute($"/p:RuntimeIdentifier={rid}", $"/p:FilterProjFile={filterProjFile}") + .Should() + .Pass(); + + DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory(runtimeIdentifier: rid); + + string libPrefix = ""; + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + libPrefix = "lib"; + } + publishDirectory.Should().HaveFiles(new[] { + "SimpleDependencies.dll", + "SimpleDependencies.pdb", + "SimpleDependencies.deps.json", + "SimpleDependencies.runtimeconfig.json", + "System.Collections.NonGeneric.dll", + $"{libPrefix}coreclr{Constants.DynamicLibSuffix}" + + }); + + publishDirectory.Should().NotHaveFiles(new[] { + "Newtonsoft.Json.dll", + "System.Runtime.Serialization.Primitives.dll" + }); + +//TODO: Enable testing the run once dotnet host has the notion of looking up shared packages +// string appPath = publishCommand.GetPublishedAppPath("SimpleDependencies"); + +// Command runAppCommand = Command.Create( +// RepoInfo.DotNetHostPath, +// new[] { appPath, "one", "two" }); + +// string expectedOutput = +//@"{ +// ""one"": ""one"", +// ""two"": ""two"" +//}"; + +// runAppCommand +// .CaptureStdOut() +// .Execute() +// .Should() +// .Pass() +// .And +// .HaveStdOutContaining(expectedOutput); + } } } \ No newline at end of file diff --git a/test/Microsoft.NET.TestFramework/TestAssetsManager.cs b/test/Microsoft.NET.TestFramework/TestAssetsManager.cs index 98ca95532dda..3cf4e452b26f 100644 --- a/test/Microsoft.NET.TestFramework/TestAssetsManager.cs +++ b/test/Microsoft.NET.TestFramework/TestAssetsManager.cs @@ -89,7 +89,7 @@ public TestAsset CreateTestProject( return testAsset; } - private string GetAndValidateTestProjectDirectory(string testProjectName) + public string GetAndValidateTestProjectDirectory(string testProjectName) { string testProjectDirectory = Path.Combine(ProjectsRoot, testProjectName);