public void Returns_Assembly_From_Remote() { // Arrange var someAssembly = GetRealAssembly(); var someAssemblyName = someAssembly.GetName(); var pluginLogger = this.LooseMock <IPluginLogger>(); var pluginLoadContext = this.Mock <IPluginLoadContext>(); var pluginDependencyContext = this.Mock <IPluginDependencyContext>(); var sut = new Prise.DefaultAssemblyLoadStrategy(pluginLogger, pluginLoadContext, pluginDependencyContext); var loadFromDependencyContext = CreateLookupFunction((c, a) => ValueOrProceed <AssemblyFromStrategy> .Proceed()); var loadFromRemote = CreateLookupFunction((c, a) => ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(someAssembly), false)); var loadFromAppDomain = CreateLookupFunction((c, a) => ValueOrProceed <AssemblyFromStrategy> .Proceed()); this.Arrange <IPluginDependencyContext>() .Setup(p => p.HostDependencies).Returns(Enumerable.Empty <HostDependency>()); this.Arrange <IPluginDependencyContext>() .Setup(p => p.RemoteDependencies).Returns(Enumerable.Empty <RemoteDependency>()); // Act, Assert Assert.Equal(someAssembly, sut.LoadAssembly(someAssemblyName, loadFromDependencyContext, loadFromRemote, loadFromAppDomain).Assembly); }
public void Returns_Null_From_AppDomain_When_IsHostAssembly_And_Not_RemoteAssembly() { // Arrange var someAssembly = GetRealAssembly(); var someAssemblyName = someAssembly.GetName(); var pluginLogger = this.LooseMock <IPluginLogger>(); var pluginLoadContext = this.Mock <IPluginLoadContext>(); var pluginDependencyContext = this.Mock <IPluginDependencyContext>(); var sut = new Prise.DefaultAssemblyLoadStrategy(pluginLogger, pluginLoadContext, pluginDependencyContext); var loadFromDependencyContext = CreateLookupFunction((c, a) => ValueOrProceed <AssemblyFromStrategy> .Proceed()); var loadFromRemote = CreateLookupFunction((c, a) => ValueOrProceed <AssemblyFromStrategy> .Proceed()); var loadFromAppDomain = CreateLookupFunction((c, a) => ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(someAssembly), false)); // Mock the fact that it was setup as a host assembly that should be loaded from the host. this.Arrange <IPluginDependencyContext>() .Setup(p => p.HostDependencies).Returns(new List <HostDependency> { new HostDependency { DependencyName = someAssemblyName } }); this.Arrange <IPluginDependencyContext>() .Setup(p => p.RemoteDependencies).Returns(Enumerable.Empty <RemoteDependency>()); // Act, Assert Assert.Null(sut.LoadAssembly(someAssemblyName, loadFromDependencyContext, loadFromRemote, loadFromAppDomain)?.Assembly); }
public async Task LoadAssembly_Returns_Assembly_From_Remote() { var sut = new DefaultAssemblyLoadStrategy(); var pluginDependencyContext = this.mockRepository.Create <IPluginDependencyContext>(); var initialPluginLoadDirectory = GetPathToAssemblies(); var someAssembly = Assembly.LoadFile(Path.Combine(initialPluginLoadDirectory, "Newtonsoft.Json.dll")); var someAssemblyName = someAssembly.GetName(); var loadFromDependencyContext = CreateLookupFunction((c, a) => ValueOrProceed <AssemblyFromStrategy> .Proceed()); var loadFromRemote = CreateLookupFunction((c, a) => ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(someAssembly), false)); var loadFromAppDomain = CreateLookupFunction((c, a) => ValueOrProceed <RuntimeAssemblyShim> .Proceed()); pluginDependencyContext .Setup(p => p.HostDependencies).Returns(Enumerable.Empty <HostDependency>()); pluginDependencyContext .Setup(p => p.RemoteDependencies).Returns(Enumerable.Empty <RemoteDependency>()); Assert.AreEqual(someAssembly, sut.LoadAssembly(initialPluginLoadDirectory, someAssemblyName, pluginDependencyContext.Object, loadFromDependencyContext, loadFromRemote, loadFromAppDomain)?.Assembly); }