Add tests for behavior of tools that target previous major version of shared framework

This commit is contained in:
Daniel Plaisted 2017-04-25 10:03:45 -07:00
parent 8615c30063
commit 01d3895b24
7 changed files with 162 additions and 2 deletions

View file

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<BuiltProjectOutputGroupOutput Include="$(ProjectRuntimeConfigFilePath)">
<FinalOutputPath>$(ProjectRuntimeConfigFilePath)</FinalOutputPath>
</BuiltProjectOutputGroupOutput>
</ItemGroup>
<ItemGroup>
<Compile Include="..\dotnet-portable\Program.cs" />
<Content Include="..\dotnet-prefercliruntime\prefercliruntime">
<Pack>true</Pack>
<PackagePath>\prefercliruntime</PackagePath>
</Content>
</ItemGroup>
</Project>

View file

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<BuiltProjectOutputGroupOutput Include="$(ProjectRuntimeConfigFilePath)">
<FinalOutputPath>$(ProjectRuntimeConfigFilePath)</FinalOutputPath>
</BuiltProjectOutputGroupOutput>
</ItemGroup>
<ItemGroup>
<Compile Include="..\dotnet-portable\Program.cs" />
</ItemGroup>
</Project>

View file

@ -2,6 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Reflection;
namespace ConsoleApplication
{
@ -10,6 +12,12 @@ namespace ConsoleApplication
public static void Main(string[] args)
{
Console.WriteLine("Hello Portable World!");
var coreAssembly = typeof(object).GetTypeInfo().Assembly;
string coreFolder = Path.GetDirectoryName(coreAssembly.Location);
string frameworkVersion = Path.GetFileName(coreFolder);
Console.WriteLine($"I'm running on shared framework version {frameworkVersion}!");
}
}
}

View file

@ -3,9 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>dotnet-portable</AssemblyName>
<OutputType>Exe</OutputType>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
<ItemGroup>

View file

@ -136,6 +136,24 @@
<VersionSuffix></VersionSuffix>
<Clean>True</Clean>
</BaseTestPackageProject>
<BaseTestPackageProject Include="TestAssets/TestPackages/dotnet-portable-v1">
<Name>dotnet-portable</Name>
<ProjectName>dotnet-portable-v1.csproj</ProjectName>
<IsTool>True</IsTool>
<IsApplicable>True</IsApplicable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Clean>True</Clean>
</BaseTestPackageProject>
<BaseTestPackageProject Include="TestAssets/TestPackages/dotnet-portable-v1-prefercli">
<Name>dotnet-portable</Name>
<ProjectName>dotnet-portable-v1-prefercli.csproj</ProjectName>
<IsTool>True</IsTool>
<IsApplicable>True</IsApplicable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Clean>True</Clean>
</BaseTestPackageProject>
<BaseTestPackageProject Include="TestAssets/TestPackages/dotnet-fallbackfoldertool">
<Name>dotnet-fallbackfoldertool</Name>
<ProjectName>dotnet-fallbackfoldertool.csproj</ProjectName>

View file

@ -0,0 +1,19 @@
using Microsoft.DotNet.Tools.Test.Utilities;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public class RequiresSpecificFrameworkTheoryAttribute : TheoryAttribute
{
public RequiresSpecificFrameworkTheoryAttribute(string framework)
{
if (!EnvironmentInfo.HasSharedFramework(framework))
{
this.Skip = $"This test requires a shared framework that isn't present: {framework}";
}
}
}
}

View file

@ -91,6 +91,82 @@ namespace Microsoft.DotNet.Tests
.And.Pass();
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void IfPreviousVersionOfSharedFrameworkIsNotInstalled_ToolsTargetingItFail(bool toolPrefersCLIRuntime)
{
var testInstance = TestAssets.Get("AppWithToolDependency")
.CreateInstance(identifier: toolPrefersCLIRuntime ? "preferCLIRuntime" : "")
.WithSourceFiles()
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);
testInstance = testInstance.WithProjectChanges(project =>
{
var ns = project.Root.Name.Namespace;
var toolReference = project.Descendants(ns + "DotNetCliToolReference")
.Where(tr => tr.Attribute("Include").Value == "dotnet-portable")
.Single();
toolReference.Attribute("Include").Value =
toolPrefersCLIRuntime ? "dotnet-portable-v1-prefercli" : "dotnet-portable-v1";
});
testInstance = testInstance.WithRestoreFiles();
new BuildCommand()
.WithProjectDirectory(testInstance.Root)
.Execute()
.Should().Pass();
new GenericCommand(toolPrefersCLIRuntime ? "portable-v1-prefercli" : "portable-v1")
.WithWorkingDirectory(testInstance.Root)
.WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0")
.Execute()
.Should().Fail();
}
[RequiresSpecificFrameworkTheory("netcoreapp1.1")]
[InlineData(true)]
[InlineData(false)]
public void IfPreviousVersionOfSharedFrameworkIsInstalled_ToolsTargetingItRun(bool toolPrefersCLIRuntime)
{
var testInstance = TestAssets.Get("AppWithToolDependency")
.CreateInstance(identifier: toolPrefersCLIRuntime ? "preferCLIRuntime" : "")
.WithSourceFiles()
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);
testInstance = testInstance.WithProjectChanges(project =>
{
var ns = project.Root.Name.Namespace;
var toolReference = project.Descendants(ns + "DotNetCliToolReference")
.Where(tr => tr.Attribute("Include").Value == "dotnet-portable")
.Single();
toolReference.Attribute("Include").Value =
toolPrefersCLIRuntime ? "dotnet-portable-v1-prefercli" : "dotnet-portable-v1";
});
testInstance = testInstance.WithRestoreFiles();
new BuildCommand()
.WithProjectDirectory(testInstance.Root)
.Execute()
.Should().Pass();
var result =
new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
.WithWorkingDirectory(testInstance.Root)
.WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0")
.Execute(toolPrefersCLIRuntime ? "portable-v1-prefercli" : "portable-v1");
result.Should().Pass()
.And.HaveStdOutContaining("I'm running on shared framework version 1.1.1!");
}
[Fact]
public void CanInvokeToolWhosePackageNameIsDifferentFromDllName()
{