-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
DependencyContextLoaderTests.cs
111 lines (99 loc) · 3.66 KB
/
DependencyContextLoaderTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using FluentAssertions;
using System;
using System.IO;
using System.Reflection;
using Xunit;
namespace Microsoft.Extensions.DependencyModel.Tests
{
public class DependencyContextLoaderTests
{
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "GetEntryAssembly() returns null")]
public void LoadLoadsExtraPaths()
{
string appDepsPath = "appPath.deps.json";
string fxDepsPath = "fxPath.deps.json";
string extraDepsPath = "extra1.deps.json";
var fileSystem = FileSystemMockBuilder.Create()
.AddFile(
appDepsPath,
@"{
""runtimeTarget"": {
""name"":"".NETCoreApp,Version=v1.0/osx.10.10-x64"",
""signature"":""target-signature""
},
""targets"": {
"".NETCoreApp,Version=v1.0/osx.10.10-x64"": {}
}
}")
.AddFile(
fxDepsPath,
@"{
""targets"": {
"".NETCoreApp,Version=v1.0/osx.10.10-x64"": {
}
}
}")
.AddFile(
extraDepsPath,
@"
{
""targets"": {
"".NETStandard,Version=v1.5"": {
""System.Banana/1.0.0"": {
""runtimeTargets"": {
""runtimes/unix/Banana.dll"": { ""rid"": ""unix"", ""assetType"": ""runtime"" },
""runtimes/win7/Banana.dll"": { ""rid"": ""win7"", ""assetType"": ""runtime"" },
""runtimes/native/win7/Apple.dll"": { ""rid"": ""win7"", ""assetType"": ""native"" },
""runtimes/native/unix/libapple.so"": { ""rid"": ""unix"", ""assetType"": ""native"" }
}
}
}
},
""libraries"": {
""System.Banana/1.0.0"": {
""type"": ""package"",
""serviceable"": false,
""sha512"": ""HASH-System.Banana""
}
}
}")
.Build();
var loader = new DependencyContextLoader(
appDepsPath,
new[] { fxDepsPath, extraDepsPath },
fileSystem,
() => new DependencyContextJsonReader());
var context = loader.Load(Assembly.GetEntryAssembly());
context.RuntimeLibraries.Should().Contain(l => l.Name == "System.Banana");
}
// Load method is marked RequiresAssemblyFiles so this test doesn't make sense on single file
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.HasAssemblyFiles))]
public void LoadCanLoadANonEntryAssembly()
{
var loader = new DependencyContextLoader();
var context = loader.Load(typeof(DependencyContextLoaderTests).Assembly);
context.RuntimeLibraries.Should().Contain(l => l.Name == "nonentrypointassembly");
}
[Fact]
public void LoadReturnsNullWhenNotFound()
{
var loader = new DependencyContextLoader();
Assert.Null(loader.Load(typeof(Moq.Mock).Assembly));
}
[Fact]
public void LoadReturnsNullWhenAssemblyLocationIsEmpty()
{
var loader = new DependencyContextLoader();
Assert.Null(loader.Load(new EmptyLocationAssembly()));
}
private class EmptyLocationAssembly : Assembly
{
public override string Location => string.Empty;
public override AssemblyName GetName() => new AssemblyName("EmptyLocation");
public override Stream? GetManifestResourceStream(string name) => null;
}
}
}