2016-02-11 04:13:56 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-03-07 18:51:40 +00:00
|
|
|
|
using System.Linq;
|
2016-02-11 04:13:56 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyModel;
|
|
|
|
|
using Microsoft.Extensions.DependencyModel.Resolution;
|
|
|
|
|
using Moq;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
|
2016-03-17 15:36:37 +00:00
|
|
|
|
namespace Microsoft.Extensions.DependencyModel.Tests
|
2016-02-11 04:13:56 +00:00
|
|
|
|
{
|
|
|
|
|
public class CompositeResolverTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ReturnsFirstSuccesfullResolve()
|
|
|
|
|
{
|
|
|
|
|
var fail = new Mock<ICompilationAssemblyResolver>();
|
|
|
|
|
var success = new Mock<ICompilationAssemblyResolver>();
|
|
|
|
|
success.Setup(r => r.TryResolveAssemblyPaths(It.IsAny<CompilationLibrary>(), It.IsAny<List<string>>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
var failTwo = new Mock<ICompilationAssemblyResolver>();
|
|
|
|
|
|
|
|
|
|
var resolvers = new[]
|
|
|
|
|
{
|
|
|
|
|
fail.Object,
|
|
|
|
|
success.Object,
|
|
|
|
|
failTwo.Object
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var resolver = new CompositeCompilationAssemblyResolver(resolvers);
|
|
|
|
|
var result = resolver.TryResolveAssemblyPaths(null, null);
|
|
|
|
|
|
|
|
|
|
Assert.True(result);
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
public void PassesLibraryToAllResolvers()
|
|
|
|
|
{
|
|
|
|
|
var fail = new Mock<ICompilationAssemblyResolver>();
|
|
|
|
|
var failTwo = new Mock<ICompilationAssemblyResolver>();
|
|
|
|
|
var resolvers = new[]
|
|
|
|
|
{
|
|
|
|
|
fail.Object,
|
|
|
|
|
failTwo.Object
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-17 15:36:37 +00:00
|
|
|
|
var library = TestLibraryFactory.Create();
|
2016-02-11 04:13:56 +00:00
|
|
|
|
|
|
|
|
|
var resolver = new CompositeCompilationAssemblyResolver(resolvers);
|
|
|
|
|
var result = resolver.TryResolveAssemblyPaths(library, null);
|
|
|
|
|
|
|
|
|
|
fail.Verify(r => r.TryResolveAssemblyPaths(library, null), Times.Once());
|
|
|
|
|
failTwo.Verify(r => r.TryResolveAssemblyPaths(library, null), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PopulatedAssemblies()
|
|
|
|
|
{
|
|
|
|
|
var fail = new Mock<ICompilationAssemblyResolver>();
|
|
|
|
|
var success = new Mock<ICompilationAssemblyResolver>();
|
|
|
|
|
success.Setup(r => r.TryResolveAssemblyPaths(It.IsAny<CompilationLibrary>(), It.IsAny<List<string>>()))
|
|
|
|
|
.Returns(true)
|
|
|
|
|
.Callback((CompilationLibrary l, List<string> a) =>
|
|
|
|
|
{
|
|
|
|
|
a.Add("Assembly");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var resolvers = new[]
|
|
|
|
|
{
|
|
|
|
|
fail.Object,
|
|
|
|
|
success.Object
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var assemblies = new List<string>();
|
2016-03-17 15:36:37 +00:00
|
|
|
|
var library = TestLibraryFactory.Create();
|
2016-02-11 04:13:56 +00:00
|
|
|
|
|
|
|
|
|
var resolver = new CompositeCompilationAssemblyResolver(resolvers);
|
|
|
|
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
|
|
|
|
|
|
|
|
|
assemblies.Should().Contain("Assembly");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|