2016-06-17 23:16:09 +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.Tools.Test.Utilities;
|
|
|
|
using Xunit;
|
2016-12-18 08:45:25 +00:00
|
|
|
using System.Linq;
|
2016-06-17 23:16:09 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
namespace Microsoft.DotNet.Cli.Build.Tests
|
2016-06-17 23:16:09 +00:00
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
public class GivenDotnetBuildBuildsCsproj : TestBase
|
2016-06-17 23:16:09 +00:00
|
|
|
{
|
|
|
|
[Fact]
|
2016-12-18 08:45:25 +00:00
|
|
|
public void ItBuildsARunnableOutput()
|
2016-06-17 23:16:09 +00:00
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
2016-10-31 23:16:07 +00:00
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance(testAppName)
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
2016-09-27 21:41:06 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
new BuildCommand()
|
2016-10-31 23:16:07 +00:00
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
2016-07-21 23:29:35 +00:00
|
|
|
.Execute()
|
2016-10-31 23:16:07 +00:00
|
|
|
.Should().Pass();
|
2016-06-17 23:16:09 +00:00
|
|
|
|
|
|
|
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
2016-10-31 23:16:07 +00:00
|
|
|
|
|
|
|
var outputDll = testInstance.Root.GetDirectory("bin", configuration, "netcoreapp1.0")
|
|
|
|
.GetFile($"{testAppName}.dll");
|
|
|
|
|
2016-06-17 23:16:09 +00:00
|
|
|
var outputRunCommand = new TestCommand("dotnet");
|
|
|
|
|
2016-10-31 23:16:07 +00:00
|
|
|
outputRunCommand.ExecuteWithCapturedOutput(outputDll.FullName)
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("Hello World");
|
2016-06-17 23:16:09 +00:00
|
|
|
}
|
2016-12-18 08:45:25 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItRunsWhenRestoringToSpecificPackageDir()
|
|
|
|
{
|
|
|
|
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
|
|
|
|
|
|
|
|
string dir = "pkgs";
|
|
|
|
string args = $"--packages {dir}";
|
|
|
|
|
|
|
|
new NewCommand()
|
|
|
|
.WithWorkingDirectory(rootPath)
|
|
|
|
.Execute()
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(rootPath)
|
|
|
|
.Execute(args)
|
|
|
|
.Should()
|
|
|
|
.Pass()
|
|
|
|
.And.NotHaveStdErr();
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
.WithWorkingDirectory(rootPath)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
var outputDll = Directory.EnumerateFiles(Path.Combine(rootPath, "bin"), "*.dll", SearchOption.AllDirectories).Single();
|
|
|
|
|
|
|
|
var outputRunCommand = new TestCommand("dotnet");
|
|
|
|
|
|
|
|
outputRunCommand.ExecuteWithCapturedOutput(outputDll)
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("Hello World");
|
|
|
|
}
|
2017-01-12 01:06:03 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItPrintsBuildSummary()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance(testAppName)
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
|
|
string expectedBuildSummary = @"Build succeeded.
|
|
|
|
0 Warning(s)
|
|
|
|
0 Error(s)";
|
|
|
|
|
|
|
|
var cmd = new BuildCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.ExecuteWithCapturedOutput();
|
|
|
|
cmd.Should().Pass();
|
|
|
|
cmd.StdOut.Should().ContainVisuallySameFragment(expectedBuildSummary);
|
|
|
|
}
|
2016-06-17 23:16:09 +00:00
|
|
|
}
|
|
|
|
}
|