fix equality issue in DependencyContextLoader (#2379)

When checking if the provided assembly is the Entry Point Assembly, we
previously just checked if the AssemblyNames were equal, but it turns
out AssemblyName doesn't implement Equals, so it was using Reference
Equality, which fails. This change uses Assembly.Equals, which has an
Equals implementation that works.

Also adds some tests to ensure it's working.

This unblocks scenarios where the EntityFramework `dotnet-ef` command
was trying to read DependencyContext.Default but receiving a null
reference.
This commit is contained in:
Andrew Stanton-Nurse 2016-04-08 15:33:32 -07:00
parent 3d157d0ec8
commit 803fef6a8b
10 changed files with 260 additions and 96 deletions

View file

@ -53,7 +53,7 @@ namespace Microsoft.DotNet.Tests
{
return;
}
var appDirectory = Path.Combine(_desktopTestProjectsRoot, "AppWithDirectDependencyDesktopAndPortable");
new BuildCommand(Path.Combine(appDirectory, "project.json"))
@ -71,6 +71,17 @@ namespace Microsoft.DotNet.Tests
result.Should().Pass();
}
[Fact]
public void ToolsCanAccessDependencyContextProperly()
{
var appDirectory = Path.Combine(_testProjectsRoot, "DependencyContextFromTool");
CommandResult result = new DependencyContextTestCommand() { WorkingDirectory = appDirectory }
.Execute(Path.Combine(appDirectory, "project.json"));
result.Should().Pass();
}
public static IEnumerable<object[]> DependencyToolArguments
{
get
@ -152,6 +163,26 @@ namespace Microsoft.DotNet.Tests
}
}
class DependencyContextTestCommand : TestCommand
{
public DependencyContextTestCommand()
: base("dotnet")
{
}
public override CommandResult Execute(string path)
{
var args = $"dependency-context-test {path}";
return base.Execute(args);
}
public override CommandResult ExecuteWithCapturedOutput(string path)
{
var args = $"dependency-context-test {path}";
return base.ExecuteWithCapturedOutput(args);
}
}
class DependencyToolInvokerCommand : TestCommand
{
public DependencyToolInvokerCommand()

View file

@ -32,6 +32,7 @@
"../../TestAssets/TestProjects/AppWithDirectAndToolDependency/**/*",
"../../TestAssets/TestProjects/AppWithDirectDependency/**/*",
"../../TestAssets/TestProjects/AppWithToolDependency/**/*",
"../../TestAssets/TestProjects/DependencyContextFromTool/**/*",
"../../TestAssets/DesktopTestProjects/AppWithDirectDependencyDesktopAndPortable/**/*"
],
"testRunner": "xunit"