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

119 lines
4.2 KiB
C#
Raw Normal View History

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;
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;
namespace Microsoft.DotNet.Cli.Publish.Tests
2016-09-23 16:11:44 +00:00
{
public class GivenDotnetPublishPublishesProjects : TestBase
2016-09-23 16:11:44 +00:00
{
[Fact]
public void ItPublishesARunnablePortableApp()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager
.CreateTestInstance(testAppName);
2016-09-23 16:11:44 +00:00
var testProjectDirectory = testInstance.TestRoot;
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute("/p:SkipInvalidConfigurations=true")
.Should().Pass();
new PublishCommand()
2016-09-23 16:11:44 +00:00
.WithWorkingDirectory(testProjectDirectory)
.Execute("--framework netcoreapp1.0")
.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)
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
2016-09-23 16:11:44 +00:00
}
[Fact]
public void ItPublishesARunnableSelfContainedApp()
{
2016-10-03 14:37:15 +00:00
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles()
.WithRestoreFiles();
var testProjectDirectory = testInstance.Root;
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
new PublishCommand()
.WithFramework("netcoreapp1.0")
.WithRuntime(rid)
.WithWorkingDirectory(testProjectDirectory)
//Workaround for https://github.com/dotnet/cli/issues/4501
.WithEnvironmentVariable("SkipInvalidConfigurations", "true")
.Execute("/p:SkipInvalidConfigurations=true")
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
var outputProgram = testProjectDirectory
.GetDirectory("bin", configuration, "netcoreapp1.0", rid, "publish", $"{testAppName}{Constants.ExeSuffix}")
.FullName;
new TestCommand(outputProgram)
.ExecuteWithCapturedOutput()
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
}
[Fact]
public void ItPublishesAppWhenRestoringToSpecificPackageDirectory()
{
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
var rootDir = new DirectoryInfo(rootPath);
string dir = "pkgs";
string args = $"--packages {dir}";
new NewCommand()
.WithWorkingDirectory(rootPath)
.Execute()
.Should()
.Pass();
new RestoreCommand()
.WithWorkingDirectory(rootPath)
.Execute(args)
.Should()
.Pass();
new PublishCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.Should().Pass();
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
var outputProgram = rootDir
.GetDirectory("bin", configuration, "netcoreapp1.0", "publish", $"{rootDir.Name}.dll")
.FullName;
new TestCommand(outputProgram)
.ExecuteWithCapturedOutput()
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
}
2016-09-23 16:11:44 +00:00
}
}