Пример #1
0
        public void LocatePluginAssemblyDownloadFail()
        {
            var token    = new UploadToken();
            var commands = new Mock <IHostApplicationCommands>();
            {
                commands.Setup(c => c.PreparePluginContainerForTransfer(It.IsAny <AssemblyName>()))
                .Returns(
                    Task <UploadToken> .Factory.StartNew(
                        () =>
                {
                    return(token);
                }));
            }

            var commandContainer = new Mock <ISendCommandsToRemoteEndpoints>();
            {
                commandContainer.Setup(c => c.CommandsFor <IHostApplicationCommands>(It.IsAny <EndpointId>()))
                .Returns(commands.Object);
            }

            DownloadDataFromRemoteEndpoints layer = (id, u, file) => Task <FileInfo> .Factory.StartNew(
                () =>
            {
                Assert.AreSame(token, u);
                throw new FileNotFoundException();
            });

            var fileSystem = new Mock <IFileSystem>();
            {
                fileSystem.Setup(f => f.Path)
                .Returns(new MockPath());
                fileSystem.Setup(f => f.File)
                .Returns(new MockFile(new Dictionary <string, string>()));
            }

            var endpoint = new EndpointId("a");
            var resolver = new PluginLoadingAssemblyResolver(
                commandContainer.Object,
                layer,
                fileSystem.Object,
                endpoint);

            Assert.IsNull(resolver.LocatePluginAssembly(new object(), new ResolveEventArgs("a")));
        }
        public void LocatePluginAssembly()
        {
            var token = new UploadToken();
            var commands = new Mock<IHostApplicationCommands>();
            {
                commands.Setup(c => c.PreparePluginContainerForTransfer(It.IsAny<AssemblyName>()))
                    .Returns(Task<UploadToken>.Factory.StartNew(() => token));
            }

            var commandContainer = new Mock<ISendCommandsToRemoteEndpoints>();
            {
                commandContainer.Setup(c => c.CommandsFor<IHostApplicationCommands>(It.IsAny<EndpointId>()))
                    .Returns(commands.Object);
            }

            DownloadDataFromRemoteEndpoints layer = (id, u, file) =>
            {
                Assert.AreSame(token, u);
                return Task<FileInfo>.Factory.StartNew(() => new FileInfo(file));
            };

            var fileSystem = new Mock<IFileSystem>();
            {
                fileSystem.Setup(f => f.Path)
                    .Returns(new MockPath());
                fileSystem.Setup(f => f.File)
                    .Returns(new MockFile(new Dictionary<string, string>()));
            }

            var endpoint = new EndpointId("a");
            var resolver = new PluginLoadingAssemblyResolver(
                commandContainer.Object,
                layer,
                fileSystem.Object,
                endpoint);
            Assert.AreEqual(
                Assembly.GetExecutingAssembly(),
                resolver.LocatePluginAssembly(new object(), new ResolveEventArgs(Assembly.GetExecutingAssembly().GetName().FullName)));
        }
Пример #3
0
        public void LocatePluginAssemblyWithUnknownAssemblyOnHost()
        {
            var commands = new Mock <IHostApplicationCommands>();
            {
                commands.Setup(c => c.PreparePluginContainerForTransfer(It.IsAny <AssemblyName>()))
                .Returns(
                    Task <UploadToken> .Factory.StartNew(
                        () =>
                {
                    throw new FileNotFoundException();
                }));
            }

            var commandContainer = new Mock <ISendCommandsToRemoteEndpoints>();
            {
                commandContainer.Setup(c => c.CommandsFor <IHostApplicationCommands>(It.IsAny <EndpointId>()))
                .Returns(commands.Object);
            }

            DownloadDataFromRemoteEndpoints layer = (id, token, file) =>
            {
                Assert.Fail();
                return(Task <FileInfo> .Factory.StartNew(() => new FileInfo(file)));
            };

            var fileSystem = new Mock <IFileSystem>();

            var endpoint = new EndpointId("a");
            var resolver = new PluginLoadingAssemblyResolver(
                commandContainer.Object,
                layer,
                fileSystem.Object,
                endpoint);

            Assert.IsNull(resolver.LocatePluginAssembly(new object(), new ResolveEventArgs("a")));
        }
        public void LocatePluginAssemblyWithUnknownAssemblyOnHost()
        {
            var commands = new Mock<IHostApplicationCommands>();
            {
                commands.Setup(c => c.PreparePluginContainerForTransfer(It.IsAny<AssemblyName>()))
                    .Returns(
                        Task<UploadToken>.Factory.StartNew(
                            () =>
                            {
                                throw new FileNotFoundException();
                            }));
            }

            var commandContainer = new Mock<ISendCommandsToRemoteEndpoints>();
            {
                commandContainer.Setup(c => c.CommandsFor<IHostApplicationCommands>(It.IsAny<EndpointId>()))
                    .Returns(commands.Object);
            }

            DownloadDataFromRemoteEndpoints layer = (id, token, file) =>
                {
                    Assert.Fail();
                    return Task<FileInfo>.Factory.StartNew(() => new FileInfo(file));
                };

            var fileSystem = new Mock<IFileSystem>();

            var endpoint = new EndpointId("a");
            var resolver = new PluginLoadingAssemblyResolver(
                commandContainer.Object,
                layer,
                fileSystem.Object,
                endpoint);
            Assert.IsNull(resolver.LocatePluginAssembly(new object(), new ResolveEventArgs("a")));
        }