Skip to content

Commit

Permalink
Integration test for publish filter profile
Browse files Browse the repository at this point in the history
  • Loading branch information
ramarag committed Jan 24, 2017
1 parent a07294d commit c11f9f7
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>9.0.1</Version>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

using System.IO;
using Microsoft.DotNet.Cli.Utils;
using FluentAssertions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Xunit;
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;
using Microsoft.DotNet.InternalAbstractions;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.NET.Publish.Tests
{
Expand Down Expand Up @@ -109,5 +113,94 @@ 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()
{
string project = "SimpleDependencies";
string tfm = "netcoreapp1.0";
TestAsset simpleDependenciesAsset = _testAssetsManager
.CopyTestAsset(project)
.WithSource()
.Restore("", $"/p:TargetFramework={tfm}");

string filterProjDir = _testAssetsManager.GetAndValidateTestProjectDirectory("NewtonsoftFilterProfile");
string filterProjFile = Path.Combine(filterProjDir, "NewtonsoftFilterProfile.csproj");

PublishCommand publishCommand = new PublishCommand(Stage0MSBuild, simpleDependenciesAsset.TestRoot);
publishCommand
.Execute($"/p:TargetFramework={tfm}", $"/p:FilterProjFile={filterProjFile}")
.Should()
.Pass();

DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory();

publishDirectory.Should().OnlyHaveFiles(new[] {
$"{project}.dll",
$"{project}.pdb",
$"{project}.deps.json",
$"{project}.runtimeconfig.json",
"System.Collections.NonGeneric.dll"
});

var runtimeConfig = ReadJson(System.IO.Path.Combine(publishDirectory.ToString(), $"{project}.runtimeconfig.json"));

runtimeConfig["runtimeOptions"]["tfm"].ToString().Should().Be(tfm);

//TODO: Enable testing the run once dotnet host has the notion of looking up shared packages
}

[Fact]
public void It_publishes_projects_with_filter_and_rid()
{
string project = "SimpleDependencies";
var rid = RuntimeEnvironment.GetRuntimeIdentifier();
TestAsset simpleDependenciesAsset = _testAssetsManager
.CopyTestAsset(project)
.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[] {
$"{project}.dll",
$"{project}.pdb",
$"{project}.deps.json",
$"{project}.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
}
private static JObject ReadJson(string path)
{
using (JsonTextReader jsonReader = new JsonTextReader(File.OpenText(path)))
{
JsonSerializer serializer = new JsonSerializer();
return serializer.Deserialize<JObject>(jsonReader);
}
}
}
}
2 changes: 1 addition & 1 deletion test/Microsoft.NET.TestFramework/TestAssetsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit c11f9f7

Please sign in to comment.