コード例 #1
0
        public void ShouldLogModuleInitializeErrorsAndContinueLoading()
        {
            IServiceLocator containerFacade = new MockContainerAdapter();
            var logger = new MockLogger();
            var service = new CustomModuleInitializerService(containerFacade, logger);
            var invalidModule = CreateModuleInfo(typeof(InvalidModule));

            Assert.IsFalse(service.HandleModuleInitializerrorCalled);
            service.Initialize(invalidModule);
            Assert.IsTrue(service.HandleModuleInitializerrorCalled);
        }
コード例 #2
0
        public void ShouldLogModuleInitializationError()
        {
            IServiceLocator containerFacade = new MockContainerAdapter();
            var logger = new MockLogger();
            var service = new ModuleInitializer(containerFacade, logger);
            ExceptionThrowingModule.wasInitializedOnce = false;
            var exceptionModule = CreateModuleInfo(typeof(ExceptionThrowingModule));

            try
            {
                service.Initialize(exceptionModule);
            }
            catch (ModuleInitializeException)
            {
            }

            Assert.IsNotNull(logger.LastMessage);
            StringAssert.Contains(logger.LastMessage, "ExceptionThrowingModule");
        }
コード例 #3
0
        public void ShouldLogMessageOnModuleRetrievalError()
        {
            var loader = new MockModuleInitializer();
            var moduleInfo = CreateModuleInfo("ModuleThatNeedsRetrieval", InitializationMode.WhenAvailable);
            var catalog = new MockModuleCatalog { Modules = { moduleInfo } };
            var logger = new MockLogger();
            ModuleManager manager = new ModuleManager(loader, catalog, logger);
            var moduleTypeLoader = new MockModuleTypeLoader();
            moduleTypeLoader.LoadCompletedError = new Exception();
            manager.ModuleTypeLoaders = new List<IModuleTypeLoader> { moduleTypeLoader };

            try
            {
                manager.Run();
            }
            catch
            {
                // Ignore all errors to make sure logger is called even if errors thrown.
            }

            Assert.IsNotNull(logger.LastMessage);
            StringAssert.Contains(logger.LastMessage, "ModuleThatNeedsRetrieval");
            Assert.AreEqual<Category>(Category.Exception, logger.LastMessageCategory);
        }