-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
CompilationLibraryTests.cs
79 lines (68 loc) · 2.93 KB
/
CompilationLibraryTests.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
// 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 Microsoft.Extensions.DependencyModel.Resolution;
using Moq;
using System;
using System.Collections.Generic;
using System.IO;
using Xunit;
namespace Microsoft.Extensions.DependencyModel.Tests
{
public class CompilationLibraryTests
{
// Moq heavily utilizes RefEmit, which does not work on most aot workloads
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public void ResolveReferencePathsAcceptsCustomResolvers()
{
var fail = new Mock<ICompilationAssemblyResolver>();
var success = new Mock<ICompilationAssemblyResolver>();
success.Setup(r => r.TryResolveAssemblyPaths(It.IsAny<CompilationLibrary>(), It.IsAny<List<string>>()))
.Callback((CompilationLibrary l, List<string> a) =>
{
a.Add("Assembly");
})
.Returns(true);
var failTwo = new Mock<ICompilationAssemblyResolver>();
var resolvers = new[]
{
fail.Object,
success.Object,
failTwo.Object
};
var library = TestLibraryFactory.Create();
var result = library.ResolveReferencePaths(resolvers);
result.Should().BeEquivalentTo(new[] { "Assembly" });
fail.Verify(r => r.TryResolveAssemblyPaths(It.IsAny<CompilationLibrary>(), It.IsAny<List<string>>()),
Times.Once());
success.Verify(r => r.TryResolveAssemblyPaths(It.IsAny<CompilationLibrary>(), It.IsAny<List<string>>()),
Times.Once());
failTwo.Verify(r => r.TryResolveAssemblyPaths(It.IsAny<CompilationLibrary>(), It.IsAny<List<string>>()),
Times.Never());
}
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/60583", TestPlatforms.iOS | TestPlatforms.tvOS)]
public void ResolveReferencePathsAcceptsNullCustomResolvers()
{
var library = TestLibraryFactory.Create();
var assemblyPath = Path.Combine(AppContext.BaseDirectory, "refs", library.Name + ".dll");
Directory.CreateDirectory(Path.GetDirectoryName(assemblyPath));
File.WriteAllText(assemblyPath, "hello");
try
{
var result = library.ResolveReferencePaths(null);
result.Should().BeEquivalentTo(new[] { assemblyPath });
}
finally
{
File.Delete(assemblyPath);
}
}
[Fact]
public void ResolveReferencePathsThrowsOnNotFound()
{
var library = TestLibraryFactory.Create();
Assert.Throws<InvalidOperationException>(() => library.ResolveReferencePaths(null));
}
}
}