2017-04-07 17:02:55 +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;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Build.Tests
|
|
|
|
{
|
|
|
|
public class GivenThatWeWantToBeBackwardsCompatibleWith1xProjects : TestBase
|
|
|
|
{
|
2017-04-27 20:52:48 +00:00
|
|
|
[RequiresSpecificFrameworkTheory("netcoreapp1.1")]
|
2017-04-07 17:02:55 +00:00
|
|
|
[InlineData("netcoreapp1.1")]
|
|
|
|
public void ItRestoresBuildsAndRuns(string target)
|
|
|
|
{
|
|
|
|
|
|
|
|
var testAppName = "TestAppSimple";
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance(testAppName + "_" + target.Replace('.', '_'))
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
// Replace the 'TargetFramework'
|
|
|
|
ChangeProjectTargetFramework(testInstance.Root.GetFile($"{testAppName}.csproj"), target);
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
|
|
|
|
|
|
|
var outputDll = testInstance.Root.GetDirectory("bin", configuration, target)
|
|
|
|
.GetFile($"{testAppName}.dll");
|
|
|
|
|
2017-04-08 07:32:34 +00:00
|
|
|
new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
|
2017-04-07 17:02:55 +00:00
|
|
|
.ExecuteWithCapturedOutput(outputDll.FullName)
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("Hello World");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[InlineData("netstandard1.3")]
|
|
|
|
[InlineData("netstandard1.6")]
|
|
|
|
public void ItRestoresBuildsAndPacks(string target)
|
|
|
|
{
|
|
|
|
|
|
|
|
var testAppName = "TestAppSimple";
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance(testAppName + "_" + target.Replace('.', '_'))
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
// Replace the 'TargetFramework'
|
|
|
|
ChangeProjectTargetFramework(testInstance.Root.GetFile($"{testAppName}.csproj"), target);
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
new PackCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
}
|
|
|
|
|
2017-04-14 20:31:12 +00:00
|
|
|
[RequiresSpecificFrameworkFact("netcoreapp1.0")] // https://github.com/dotnet/cli/issues/6087
|
|
|
|
public void ItRunsABackwardsVersionedTool()
|
2017-04-14 16:40:46 +00:00
|
|
|
{
|
2017-04-17 16:27:25 +00:00
|
|
|
var testInstance = TestAssets.Get("11TestAppWith10CLIToolReferences")
|
2017-04-14 16:40:46 +00:00
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.Root;
|
|
|
|
|
|
|
|
new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
2017-04-14 20:31:12 +00:00
|
|
|
.ExecuteWithCapturedOutput("outputsframeworkversion-netcoreapp1.0")
|
2017-04-14 16:40:46 +00:00
|
|
|
.Should()
|
|
|
|
.Pass()
|
|
|
|
.And
|
2017-04-14 20:31:12 +00:00
|
|
|
.HaveStdOutContaining("netcoreapp1.0");
|
2017-04-14 16:40:46 +00:00
|
|
|
}
|
2017-04-07 17:02:55 +00:00
|
|
|
|
|
|
|
void ChangeProjectTargetFramework(FileInfo projectFile, string target)
|
|
|
|
{
|
|
|
|
var projectXml = XDocument.Load(projectFile.ToString());
|
|
|
|
var ns = projectXml.Root.Name.Namespace;
|
|
|
|
var propertyGroup = projectXml.Root.Elements(ns + "PropertyGroup").First();
|
|
|
|
var rootNamespaceElement = propertyGroup.Element(ns + "TargetFramework");
|
|
|
|
rootNamespaceElement.SetValue(target);
|
|
|
|
projectXml.Save(projectFile.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|