2016-04-08 23:27:09 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
2016-04-08 15:51:51 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Publish.Tests
|
|
|
|
|
{
|
|
|
|
|
public class PublishDesktopTests : TestBase
|
|
|
|
|
{
|
|
|
|
|
[WindowsOnlyTheory]
|
2016-04-08 23:27:09 +00:00
|
|
|
|
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20201", null, "libuv.dll", true)]
|
|
|
|
|
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20202", "win7-x64", "libuv.dll", true)]
|
|
|
|
|
[InlineData("KestrelDesktop", "http://localhost:20204", null, "libuv.dll", true)]
|
|
|
|
|
[InlineData("KestrelDesktop", "http://localhost:20205", "win7-x64", "libuv.dll", true)]
|
|
|
|
|
public async Task DesktopApp_WithKestrel_WorksWhenPublished(string project, string url, string runtime, string libuvName, bool runnable)
|
2016-04-08 15:51:51 +00:00
|
|
|
|
{
|
2016-04-08 23:27:09 +00:00
|
|
|
|
var testInstance = GetTestInstance()
|
|
|
|
|
.WithLockFiles();
|
2016-04-08 15:51:51 +00:00
|
|
|
|
|
2016-04-08 23:27:09 +00:00
|
|
|
|
var publishCommand = new PublishCommand(Path.Combine(testInstance.TestRoot, project), runtime: runtime);
|
2016-04-08 15:51:51 +00:00
|
|
|
|
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);
|
2016-04-08 15:51:51 +00:00
|
|
|
|
outputDir.Should().HaveFile(publishCommand.GetOutputExecutable());
|
|
|
|
|
|
2016-04-08 23:27:09 +00:00
|
|
|
|
Task exec = null;
|
|
|
|
|
if (runnable)
|
|
|
|
|
{
|
|
|
|
|
var command = new TestCommand(Path.Combine(outputDir.FullName, publishCommand.GetOutputExecutable()));
|
|
|
|
|
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:20207")]
|
|
|
|
|
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20208")]
|
|
|
|
|
public async Task DesktopApp_WithKestrel_WorksWhenRun(string project, string url)
|
|
|
|
|
{
|
|
|
|
|
var testInstance = GetTestInstance()
|
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
|
|
|
|
|
|
|
|
|
Task exec = null;
|
|
|
|
|
var command = new RunCommand(Path.Combine(testInstance.TestRoot, project));
|
2016-04-08 15:51:51 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2016-04-08 23:27:09 +00:00
|
|
|
|
exec = command.ExecuteAsync(url);
|
2016-04-08 15:51:51 +00:00
|
|
|
|
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 15:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 23:27:09 +00:00
|
|
|
|
private static TestInstance GetTestInstance([CallerMemberName] string callingMethod = "")
|
2016-04-08 15:51:51 +00:00
|
|
|
|
{
|
2016-04-08 23:27:09 +00:00
|
|
|
|
return TestAssetsManager.CreateTestInstance(Path.Combine("..", "DesktopTestProjects", "DesktopKestrelSample"), callingMethod);
|
2016-04-08 15:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|