dotnet-installer/test/dotnet-publish.Tests/PublishDesktopTests.cs

132 lines
5.5 KiB
C#
Raw Normal View History

2016-04-08 23:27:09 +00:00
using System.Diagnostics;
using System.IO;
using System.Linq;
2016-04-08 23:27:09 +00:00
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Xunit;
namespace Microsoft.DotNet.Tools.Publish.Tests
{
public class PublishDesktopTests : TestBase
{
2016-04-11 19:19:42 +00:00
[WindowsOnlyTheory]
[InlineData(null, null)]
2016-04-11 19:19:42 +00:00
[InlineData("win7-x64", "the-win-x64-version.txt")]
[InlineData("win7-x86", "the-win-x86-version.txt")]
public async Task DesktopApp_WithDependencyOnNativePackage_ProducesExpectedOutput(string runtime, string expectedOutputName)
{
if(string.IsNullOrEmpty(expectedOutputName))
{
expectedOutputName = $"the-win-{RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant()}-version.txt";
}
2016-04-11 19:19:42 +00:00
var testInstance = TestAssetsManager.CreateTestInstance(Path.Combine("..", "DesktopTestProjects", "DesktopAppWithNativeDep"))
.WithLockFiles();
var publishCommand = new PublishCommand(testInstance.TestRoot, runtime: runtime);
var result = await publishCommand.ExecuteAsync();
result.Should().Pass();
// Test the output
var outputDir = publishCommand.GetOutputDirectory(portable: false);
outputDir.Should().HaveFile(expectedOutputName);
outputDir.Should().HaveFile(publishCommand.GetOutputExecutable());
}
[WindowsOnlyTheory]
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20201", null, "libuv.dll", false)]
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20202", "win7-x64", "libuv.dll", false)]
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20203", "win7-x86", "libuv.dll", false)]
[InlineData("KestrelDesktopForce32", "http://localhost:20204", "win7-x86", "libuv.dll", true)]
[InlineData("KestrelDesktop", "http://localhost:20205", null, "libuv.dll", false)]
[InlineData("KestrelDesktop", "http://localhost:20206", "win7-x64", "libuv.dll", false)]
[InlineData("KestrelDesktop", "http://localhost:20207", "win7-x86", "libuv.dll", false)]
public async Task DesktopApp_WithKestrel_WorksWhenPublished(string project, string url, string runtime, string libuvName, bool forceRunnable)
{
var runnable = forceRunnable || string.IsNullOrEmpty(runtime) || (PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier().Contains(runtime));
2016-04-08 23:27:09 +00:00
var testInstance = GetTestInstance()
.WithLockFiles();
2016-04-08 23:27:09 +00:00
var publishCommand = new PublishCommand(Path.Combine(testInstance.TestRoot, project), runtime: runtime);
var result = await publishCommand.ExecuteAsync();
result.Should().Pass();
// Test the output
var outputDir = publishCommand.GetOutputDirectory(portable: false);
2016-04-08 23:27:09 +00:00
outputDir.Should().HaveFile(libuvName);
outputDir.Should().HaveFile(publishCommand.GetOutputExecutable());
2016-04-08 23:27:09 +00:00
Task exec = null;
if (runnable)
{
var outputExePath = Path.Combine(outputDir.FullName, publishCommand.GetOutputExecutable());
var command = new TestCommand(outputExePath);
2016-04-08 23:27:09 +00:00
try
{
exec = command.ExecuteAsync(url);
NetworkHelper.IsServerUp(url).Should().BeTrue($"Unable to connect to kestrel server - {project} @ {url}");
NetworkHelper.TestGetRequest(url, url);
}
finally
{
command.KillTree();
}
if (exec != null)
{
await exec;
}
}
}
[WindowsOnlyTheory]
[InlineData("KestrelDesktop", "http://localhost:20301", null)]
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20302", null)]
[InlineData("KestrelDesktop", "http://localhost:20303", "net451")]
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20304", "net451")]
public async Task DesktopApp_WithKestrel_WorksWhenRun(string project, string url, string framework)
2016-04-08 23:27:09 +00:00
{
// Disabled due to https://github.com/dotnet/cli/issues/2428
if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
{
return;
}
2016-04-08 23:27:09 +00:00
var testInstance = GetTestInstance()
.WithLockFiles()
.WithBuildArtifacts();
Task exec = null;
var command = new RunCommand(Path.Combine(testInstance.TestRoot, project), framework);
try
{
2016-04-08 23:27:09 +00:00
exec = command.ExecuteAsync(url);
NetworkHelper.IsServerUp(url).Should().BeTrue($"Unable to connect to kestrel server - {project} @ {url}");
NetworkHelper.TestGetRequest(url, url);
}
finally
{
command.KillTree();
}
2016-04-08 23:27:09 +00:00
if (exec != null)
{
await exec;
}
}
2016-04-08 23:27:09 +00:00
private static TestInstance GetTestInstance([CallerMemberName] string callingMethod = "")
{
2016-04-08 23:27:09 +00:00
return TestAssetsManager.CreateTestInstance(Path.Combine("..", "DesktopTestProjects", "DesktopKestrelSample"), callingMethod);
}
}
}