Skip to content

Commit

Permalink
Add test for roll-forward assembly-loading behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dsplaisted committed Apr 6, 2018
1 parent 17270bd commit b5bb3d1
Showing 1 changed file with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.Extensions.DependencyModel;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
Expand Down Expand Up @@ -132,5 +133,92 @@ private void Versions_are_not_included(bool build, [CallerMemberName] string cal
runtimeFile.FileVersion.Should().BeNull();
}
}

[Fact]
public void Inbox_version_of_assembly_is_loaded_over_applocal_version()
{
var testProject = GetTestProject();

testProject.SourceFiles["Program.cs"] = @"
using System;
static class Program
{
public static void Main()
{
Console.WriteLine(typeof(object).Assembly.Location);
Console.WriteLine(typeof(System.Collections.Immutable.ImmutableList).Assembly.Location);
}
}
";

var testAsset = _testAssetsManager.CreateTestProject(testProject)
.Restore(Log, testProject.Name);

var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));

publishCommand.Execute()
.Should()
.Pass();

var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks, runtimeIdentifier: testProject.RuntimeIdentifier);


// Assembly from package should be deployed, as it is newer than the in-box version for netcoreapp2.0,
// which is what the app targets
publishDirectory.Should().HaveFile("System.Collections.Immutable.dll");

var exePath = Path.Combine(publishDirectory.FullName, testProject.Name + ".dll");

// We want to test a .NET Core 2.0 app rolling forward to .NET Core 2.1.
// This wouldn't happen in our test environment as we also have the .NET Core 2.0 shared
// framework installed. So we get the RuntimeFrameworkVersion of an app
// that targets .NET Core 2.1, and then use the --fx-version parameter to the host
// to force the .NET Core 2.0 app to run on that version
string rollForwardVersion = GetRollForwardNetCoreAppVersion();

var foo = TestContext.Current.ToolsetUnderTest.CliVersionForBundledVersions;
var runAppCommand = Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath,
new string[] { "exec", "--fx-version", rollForwardVersion, exePath });

var runAppResult = runAppCommand
.CaptureStdOut()
.CaptureStdErr()
.Execute();

runAppResult
.Should()
.Pass();

var stdOutLines = runAppResult.StdOut.Split(Environment.NewLine);

string coreDir = Path.GetDirectoryName(stdOutLines[0]);
string immutableDir = Path.GetDirectoryName(stdOutLines[1]);

immutableDir.Should().BeEquivalentTo(coreDir, "immutable collections library from Framework should win");

}

string GetRollForwardNetCoreAppVersion()
{
var testProject = new TestProject()
{
Name = nameof(GetRollForwardNetCoreAppVersion),
TargetFrameworks = "netcoreapp2.1",
IsSdkProject = true,
IsExe = true
};
var testAsset = _testAssetsManager.CreateTestProject(testProject)
.Restore(Log, testProject.Name);
var getValuesCommand = new GetValuesCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name),
testProject.TargetFrameworks, "RuntimeFrameworkVersion")
{
ShouldCompile = false
};

getValuesCommand.Execute().Should().Pass();

return getValuesCommand.GetValues().Single();
}
}
}

0 comments on commit b5bb3d1

Please sign in to comment.