Exemplo n.º 1
0
        public void Returns_Null_From_AppDomain_When_NOT_IsHostAssembly_And_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> .Proceed());

            // 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
                }
            });

            // Mock the fact that it was ALSO setup as a remote assembly that should be loaded from the plugin.
            this.Arrange <IPluginDependencyContext>()
            .Setup(p => p.RemoteDependencies).Returns(new List <RemoteDependency> {
                new RemoteDependency {
                    DependencyName = someAssemblyName
                }
            });

            // Act, Assert
            Assert.Null(sut.LoadAssembly(someAssemblyName, loadFromDependencyContext, loadFromRemote, loadFromAppDomain)?.Assembly);
        }
Exemplo n.º 2
0
        public async Task LoadAssembly_Returns_Null_From_AppDomain_When_NOT_IsHostAssembly_And_RemoteAssembly()
        {
            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> .Proceed());
            var loadFromAppDomain         = CreateLookupFunction((c, a) => ValueOrProceed <RuntimeAssemblyShim> .Proceed());

            // Mock the fact that it was setup as a host assembly that should be loaded from the host.
            pluginDependencyContext
            .Setup(p => p.HostDependencies).Returns(new List <HostDependency> {
                new HostDependency {
                    DependencyName = someAssemblyName
                }
            });

            // Mock the fact that it was ALSO setup as a remote assembly that should be loaded from the plugin.
            pluginDependencyContext
            .Setup(p => p.RemoteDependencies).Returns(new List <RemoteDependency> {
                new RemoteDependency {
                    DependencyName = someAssemblyName
                }
            });

            Assert.IsNull(sut.LoadAssembly(initialPluginLoadDirectory, someAssemblyName, pluginDependencyContext.Object, loadFromDependencyContext, loadFromRemote, loadFromAppDomain)?.Assembly);
        }
Exemplo n.º 3
0
        public void Returns_Null_When_AssemblyName_NotFound()
        {
            // Arrange
            var pluginLoadContext       = this.Mock <IPluginLoadContext>();
            var pluginDependencyContext = this.Mock <IPluginDependencyContext>();
            var sut          = new Prise.DefaultAssemblyLoadStrategy(pluginLoadContext, pluginDependencyContext);
            var assemblyname = new AssemblyName(this.CreateFixture <string>());
            var loadFromDependencyContext = CreateLookupFunction((c, a) => ValueOrProceed <Assembly> .Proceed());
            var loadFromRemote            = CreateLookupFunction((c, a) => ValueOrProceed <Assembly> .Proceed());
            var loadFromAppDomain         = CreateLookupFunction((c, a) => ValueOrProceed <Assembly> .Proceed());

            this.Arrange <IPluginDependencyContext>()
            .Setup(p => p.HostDependencies).Returns(Enumerable.Empty <HostDependency>());

            // Act, Assert
            Assert.Null(sut.LoadAssembly(assemblyname, loadFromDependencyContext, loadFromRemote, loadFromAppDomain));
        }
Exemplo n.º 4
0
        public async Task LoadAssembly_Returns_Null_When_AssemblyName_NotFound()
        {
            var sut                        = new DefaultAssemblyLoadStrategy();
            var assemblyname               = new AssemblyName("Newtonsoft.Json.dll");
            var pluginDependencyContext    = this.mockRepository.Create <IPluginDependencyContext>();
            var loadFromDependencyContext  = CreateLookupFunction((c, a) => ValueOrProceed <AssemblyFromStrategy> .Proceed());
            var loadFromRemote             = CreateLookupFunction((c, a) => ValueOrProceed <AssemblyFromStrategy> .Proceed());
            var loadFromAppDomain          = CreateLookupFunction((c, a) => ValueOrProceed <RuntimeAssemblyShim> .Proceed());
            var initialPluginLoadDirectory = GetPathToAssemblies();

            pluginDependencyContext
            .Setup(p => p.HostDependencies).Returns(Enumerable.Empty <HostDependency>());

            pluginDependencyContext
            .Setup(p => p.RemoteDependencies).Returns(Enumerable.Empty <RemoteDependency>());

            Assert.IsNull(sut.LoadAssembly(initialPluginLoadDirectory, assemblyname, pluginDependencyContext.Object, loadFromDependencyContext, loadFromRemote, loadFromAppDomain)?.Assembly);
        }
Exemplo n.º 5
0
        public void Returns_Assembly_From_Remote()
        {
            // Arrange
            var someAssembly            = GetRealAssembly();
            var someAssemblyName        = someAssembly.GetName();
            var pluginLoadContext       = this.Mock <IPluginLoadContext>();
            var pluginDependencyContext = this.Mock <IPluginDependencyContext>();
            var sut = new Prise.DefaultAssemblyLoadStrategy(pluginLoadContext, pluginDependencyContext);
            var loadFromDependencyContext = CreateLookupFunction((c, a) => ValueOrProceed <Assembly> .Proceed());
            var loadFromRemote            = CreateLookupFunction((c, a) => ValueOrProceed <Assembly> .FromValue(someAssembly, false));
            var loadFromAppDomain         = CreateLookupFunction((c, a) => ValueOrProceed <Assembly> .Proceed());

            this.Arrange <IPluginDependencyContext>()
            .Setup(p => p.HostDependencies).Returns(Enumerable.Empty <HostDependency>());

            // Act, Assert
            Assert.Equal(someAssembly, sut.LoadAssembly(someAssemblyName, loadFromDependencyContext, loadFromRemote, loadFromAppDomain));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public void Returns_AssemblyPath_FromRemote()
        {
            // 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 <string, string>((c, a) => ValueOrProceed <string> .Proceed());
            var loadFromRemote            = CreateLookupFunction <string, string>((c, a) => ValueOrProceed <string> .FromValue(someAssemblyName.Name, false));
            var loadFromAppDomain         = CreateLookupFunction <string, IntPtr>((c, a) => ValueOrProceed <IntPtr> .Proceed());

            // Act
            var result = sut.LoadUnmanagedDll(someAssemblyName.Name, loadFromDependencyContext, loadFromRemote, loadFromAppDomain);

            // Assert
            Assert.Equal(someAssemblyName.Name, result.Path);
            Assert.Equal(IntPtr.Zero, result.Pointer);
        }
Exemplo n.º 8
0
        public async Task LoadUnmanagedDll_Returns_AssemblyPath_FromRemote()
        {
            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 <string, string>((c, a) => ValueOrProceed <string> .Proceed());
            var loadFromRemote            = CreateLookupFunction <string, string>((c, a) => ValueOrProceed <string> .FromValue(someAssemblyName.Name, false));
            var loadFromAppDomain         = CreateLookupFunction <string, IntPtr>((c, a) => ValueOrProceed <IntPtr> .Proceed());

            var result = sut.LoadUnmanagedDll(initialPluginLoadDirectory, someAssemblyName.Name, pluginDependencyContext.Object, loadFromDependencyContext, loadFromRemote, loadFromAppDomain);

            Assert.AreEqual(someAssemblyName.Name, result.Path);
            Assert.AreEqual(IntPtr.Zero, result.Pointer);
        }