// 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 Microsoft.DotNet.Tools.Test.Utilities; using Xunit; namespace Microsoft.DotNet.Cli.Run3.Tests { public class GivenDotnetRun3BuildsCsproj : TestBase { [Fact] public void ItCanRunAMSBuildProject() { var testAppName = "MSBuildTestApp"; var testInstance = TestAssetsManager .CreateTestInstance(testAppName); var testProjectDirectory = testInstance.TestRoot; new Restore3Command() .WithWorkingDirectory(testProjectDirectory) .Execute() .Should() .Pass(); new Build3Command() .WithWorkingDirectory(testProjectDirectory) .Execute() .Should() .Pass(); //TODO: https://github.com/dotnet/sdk/issues/187 - remove framework from below. new Run3Command() .WithWorkingDirectory(testProjectDirectory) .ExecuteWithCapturedOutput("--framework netcoreapp1.0") .Should() .Pass() .And .HaveStdOutContaining("Hello World!"); } [Fact] public void ItBuildsTheProjectBeforeRunning() { var testAppName = "MSBuildTestApp"; var testInstance = TestAssetsManager .CreateTestInstance(testAppName); var testProjectDirectory = testInstance.TestRoot; new Restore3Command() .WithWorkingDirectory(testProjectDirectory) .Execute() .Should() .Pass(); //TODO: https://github.com/dotnet/sdk/issues/187 - remove framework from below. new Run3Command() .WithWorkingDirectory(testProjectDirectory) .ExecuteWithCapturedOutput("--framework netcoreapp1.0") .Should() .Pass() .And .HaveStdOutContaining("Hello World!"); } [Fact] public void ItCanRunAMSBuildProjectWhenSpecifyingAFramework() { var testAppName = "MSBuildTestApp"; var testInstance = TestAssetsManager .CreateTestInstance(testAppName); var testProjectDirectory = testInstance.TestRoot; new Restore3Command() .WithWorkingDirectory(testProjectDirectory) .Execute() .Should() .Pass(); new Run3Command() .WithWorkingDirectory(testProjectDirectory) .ExecuteWithCapturedOutput("--framework netcoreapp1.0") .Should() .Pass() .And .HaveStdOutContaining("Hello World!"); } [Fact] public void ItReportsAGoodErrorWhenProjectHasMultipleFrameworks() { var testAppName = "MSBuildAppWithMultipleFrameworks"; var testInstance = TestAssetsManager .CreateTestInstance(testAppName); var testProjectDirectory = testInstance.TestRoot; new Restore3Command() .WithWorkingDirectory(testProjectDirectory) .Execute("/p:SkipInvalidConfigurations=true") .Should() .Pass(); // use --no-build so this test can run on all platforms. // the test app targets net451, which can't be built on non-Windows new Run3Command() .WithWorkingDirectory(testProjectDirectory) .ExecuteWithCapturedOutput("--no-build") .Should() .Fail() .And .HaveStdErrContaining("--framework"); } } }