示例#1
0
        public void DownloadCompletedRaisedForImportedModulesInCatalog()
        {
            var mockModuleInitializer = new Mock <IModuleInitializer>();
            var modules = new List <ModuleInfo>();

            var mockModuleCatalog = new Mock <IModuleCatalog>();

            mockModuleCatalog.Setup(x => x.Modules).Returns(modules);
            mockModuleCatalog
            .Setup(x => x.AddModule(It.IsAny <ModuleInfo>()))
            .Callback <ModuleInfo>(modules.Add);

            var mockLogger = new Mock <ILoggerFacade>();

            List <ModuleInfo> modulesCompleted = new List <ModuleInfo>();
            var moduleManager = new TestableMefModuleManager(mockModuleInitializer.Object, mockModuleCatalog.Object, mockLogger.Object)
            {
                Modules =
                    new List <Lazy <IModule, IModuleExport> >()
                {
                    new Lazy <IModule, IModuleExport>(() => new TestModule(),
                                                      new TestModuleMetadata())
                }
            };

            moduleManager.LoadModuleCompleted += (o, e) =>
            {
                modulesCompleted.Add(e.ModuleInfo);
            };

            moduleManager.OnImportsSatisfied();

            Assert.AreEqual(1, modulesCompleted.Count);
        }
        public void DownloadCompletedNotRaisedForOnDemandImportedModules()
        {
            var mockModuleInitializer = new Mock <IModuleInitializer>();
            var modules = new List <ModuleInfo>();

            var mockModuleCatalog = new Mock <IModuleCatalog>();

            mockModuleCatalog.Setup(x => x.Modules).Returns(modules);
            mockModuleCatalog
            .Setup(x => x.AddModule(It.IsAny <ModuleInfo>()))
            .Callback <ModuleInfo>(modules.Add);

            var mockLogger = new Mock <ILoggerFacade>();

            List <ModuleInfo> modulesCompleted = new List <ModuleInfo>();
            var moduleManager = new TestableMefModuleManager(mockModuleInitializer.Object, mockModuleCatalog.Object, mockLogger.Object)
            {
                Modules =
                    new List <Lazy <IModule, IPluginModuleExport> >()
                {
                    new Lazy <IModule, IPluginModuleExport>(() => new TestModule(),
                                                            new TestModuleMetadata()
                    {
                        InitializationMode = InitializationMode.OnDemand
                    }),
                    new Lazy <IModule, IPluginModuleExport>(() => new TestModule(),
                                                            new TestModuleMetadata()
                    {
                        ModuleName = "WhenAvailableModule"
                    })
                }
            };

            moduleManager.LoadModuleCompleted += (o, e) =>
            {
                modulesCompleted.Add(e.ModuleInfo);
            };

            moduleManager.OnImportsSatisfied();

            Assert.AreEqual(1, modulesCompleted.Count);
            Assert.AreEqual("WhenAvailableModule", modulesCompleted[0].ModuleName);
        }
        public void DownloadCompletedNotRaisedForOnDemandImportedModules()
        {
            var mockModuleInitializer = new Mock<IModuleInitializer>();
            var modules = new List<ModuleInfo>();

            var mockModuleCatalog = new Mock<IModuleCatalog>();
            mockModuleCatalog.Setup(x => x.Modules).Returns(modules);
            mockModuleCatalog
                .Setup(x => x.AddModule(It.IsAny<ModuleInfo>()))
                .Callback<ModuleInfo>(modules.Add);

            var mockLogger = new Mock<ILoggerFacade>();

            List<ModuleInfo> modulesCompleted = new List<ModuleInfo>();
            var moduleManager = new TestableMefModuleManager(mockModuleInitializer.Object, mockModuleCatalog.Object, mockLogger.Object)
            {
                Modules =
                    new List<Lazy<IModule, IModuleExport>>()
                                                {
                                                    new Lazy<IModule, IModuleExport>(() => new TestModule(),
                                                                                     new TestModuleMetadata()
                                                                                         {
                                                                                             InitializationMode = InitializationMode.OnDemand
                                                                                         }),
                                                    new Lazy<IModule, IModuleExport>(() => new TestModule(),
                                                                                        new TestModuleMetadata()
                                                                                            {
                                                                                                ModuleName = "WhenAvailableModule"
                                                                                            })
                                                }
            };

            moduleManager.LoadModuleCompleted += (o, e) =>
            {
                modulesCompleted.Add(e.ModuleInfo);
            };

            moduleManager.OnImportsSatisfied();

            Assert.AreEqual(1, modulesCompleted.Count);
            Assert.AreEqual("WhenAvailableModule", modulesCompleted[0].ModuleName);
        }