public void ModuleInUnreferencedAssemblyInitializedByModuleInitializer() { AssemblyCatalog assemblyCatalog = new AssemblyCatalog(GetPathToModuleDll()); CompositionContainer compositionContainer = new CompositionContainer(assemblyCatalog); ModuleCatalog moduleCatalog = new ModuleCatalog(); Mock<MefFileModuleTypeLoader> mockFileTypeLoader = new Mock<MefFileModuleTypeLoader>(); compositionContainer.ComposeExportedValue<IModuleCatalog>(moduleCatalog); compositionContainer.ComposeExportedValue<MefFileModuleTypeLoader>(mockFileTypeLoader.Object); bool wasInit = false; var mockModuleInitializer = new Mock<IModuleInitializer>(); mockModuleInitializer.Setup(x => x.Initialize(It.IsAny<ModuleInfo>())).Callback(() => wasInit = true); var mockLoggerFacade = new Mock<ILoggerFacade>(); MefModuleManager moduleManager = new MefModuleManager( mockModuleInitializer.Object, moduleCatalog, mockLoggerFacade.Object); compositionContainer.SatisfyImportsOnce(moduleManager); moduleManager.Run(); Assert.IsTrue(wasInit); }
public void DeclaredModuleWithTypeInUnreferencedAssemblyIsUpdatedWithTypeNameFromExportAttribute() { AggregateCatalog aggregateCatalog = new AggregateCatalog(); CompositionContainer compositionContainer = new CompositionContainer(aggregateCatalog); var mockFileTypeLoader = new Mock<MefFileModuleTypeLoader>(); mockFileTypeLoader.Setup(tl => tl.CanLoadModuleType(It.IsAny<ModuleInfo>())).Returns(true); ModuleCatalog moduleCatalog = new ModuleCatalog(); ModuleInfo moduleInfo = new ModuleInfo { ModuleName = "MefModuleOne", ModuleType = "some type" }; moduleCatalog.AddModule(moduleInfo); compositionContainer.ComposeExportedValue<IModuleCatalog>(moduleCatalog); compositionContainer.ComposeExportedValue<MefFileModuleTypeLoader>(mockFileTypeLoader.Object); bool wasInit = false; var mockModuleInitializer = new Mock<IModuleInitializer>(); mockModuleInitializer.Setup(x => x.Initialize(It.IsAny<ModuleInfo>())).Callback(() => wasInit = true); var mockLoggerFacade = new Mock<ILoggerFacade>(); MefModuleManager moduleManager = new MefModuleManager( mockModuleInitializer.Object, moduleCatalog, mockLoggerFacade.Object); compositionContainer.SatisfyImportsOnce(moduleManager); moduleManager.Run(); Assert.IsFalse(wasInit); AssemblyCatalog assemblyCatalog = new AssemblyCatalog(GetPathToModuleDll()); aggregateCatalog.Catalogs.Add(assemblyCatalog); compositionContainer.SatisfyImportsOnce(moduleManager); mockFileTypeLoader.Raise(tl => tl.LoadModuleCompleted += null, new LoadModuleCompletedEventArgs(moduleInfo, null)); Assert.AreEqual(BuildMefSupportTypeName(), moduleInfo.ModuleType); Assert.IsTrue(wasInit); }