2016-09-23 16:11:44 +00:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using FluentAssertions;
|
2016-09-30 22:47:23 +00:00
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
using Microsoft.DotNet.PlatformAbstractions;
|
2016-09-23 16:11:44 +00:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
using Xunit;
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
namespace Microsoft.DotNet.Cli.Publish.Tests
|
2016-09-23 16:11:44 +00:00
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
public class GivenDotnetPublishPublishesProjects : TestBase
|
2016-09-23 16:11:44 +00:00
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void ItPublishesARunnablePortableApp()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
|
|
|
var testInstance = TestAssetsManager
|
2016-09-27 21:41:06 +00:00
|
|
|
.CreateTestInstance(testAppName);
|
2016-09-23 16:11:44 +00:00
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.TestRoot;
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
new RestoreCommand()
|
2016-09-27 21:41:06 +00:00
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-10-28 01:46:43 +00:00
|
|
|
.Execute("/p:SkipInvalidConfigurations=true")
|
2016-10-26 22:23:40 +00:00
|
|
|
.Should().Pass();
|
2016-09-27 21:41:06 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
new PublishCommand()
|
2016-09-23 16:11:44 +00:00
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-09-27 22:38:59 +00:00
|
|
|
.Execute("--framework netcoreapp1.0")
|
2016-10-26 22:23:40 +00:00
|
|
|
.Should().Pass();
|
2016-09-23 16:11:44 +00:00
|
|
|
|
|
|
|
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
|
|
|
var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, "netcoreapp1.0", "publish", $"{testAppName}.dll");
|
|
|
|
|
|
|
|
new TestCommand("dotnet")
|
|
|
|
.ExecuteWithCapturedOutput(outputDll)
|
2016-10-26 22:23:40 +00:00
|
|
|
.Should().Pass()
|
2016-10-28 01:46:43 +00:00
|
|
|
.And.HaveStdOutContaining("Hello World");
|
2016-09-23 16:11:44 +00:00
|
|
|
}
|
2016-09-30 22:47:23 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItPublishesARunnableSelfContainedApp()
|
|
|
|
{
|
2016-10-03 14:37:15 +00:00
|
|
|
var testAppName = "MSBuildTestApp";
|
2016-09-30 22:47:23 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
2016-09-30 22:47:23 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var testProjectDirectory = testInstance.Root;
|
|
|
|
|
|
|
|
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
2016-10-26 22:23:40 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
new PublishCommand()
|
2016-09-30 22:47:23 +00:00
|
|
|
.WithFramework("netcoreapp1.0")
|
|
|
|
.WithRuntime(rid)
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-10-28 01:46:43 +00:00
|
|
|
//Workaround for https://github.com/dotnet/cli/issues/4501
|
|
|
|
.WithEnvironmentVariable("SkipInvalidConfigurations", "true")
|
|
|
|
.Execute("/p:SkipInvalidConfigurations=true")
|
2016-10-26 22:23:40 +00:00
|
|
|
.Should().Pass();
|
2016-09-30 22:47:23 +00:00
|
|
|
|
|
|
|
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
var outputProgram = testProjectDirectory
|
|
|
|
.GetDirectory("bin", configuration, "netcoreapp1.0", rid, "publish", $"{testAppName}{Constants.ExeSuffix}")
|
|
|
|
.FullName;
|
2016-09-30 22:47:23 +00:00
|
|
|
|
|
|
|
new TestCommand(outputProgram)
|
|
|
|
.ExecuteWithCapturedOutput()
|
2016-10-26 22:23:40 +00:00
|
|
|
.Should().Pass()
|
2016-10-28 01:46:43 +00:00
|
|
|
.And.HaveStdOutContaining("Hello World");
|
2016-09-30 22:47:23 +00:00
|
|
|
}
|
2016-09-23 16:11:44 +00:00
|
|
|
}
|
|
|
|
}
|