Beispiel #1
0
        public void ConfigureFromConfigurationReader()
        {
            IConfigurationReader r = mocks.StrictMock <IConfigurationReader>();

            using (mocks.Record())
            {
                Expect.Call(r.GetSection(LogManager.COMMON_LOGGING_SECTION)).Return(null);
                Expect.Call(r.GetSection(LogManager.COMMON_LOGGING_SECTION)).Return(new TraceLoggerFactoryAdapter());
                Expect.Call(r.GetSection(LogManager.COMMON_LOGGING_SECTION)).Return(new LogSetting(typeof(ConsoleOutLoggerFactoryAdapter), null));
                Expect.Call(r.GetSection(LogManager.COMMON_LOGGING_SECTION)).Return(new object());
            }

            using (mocks.Playback())
            {
                ILog log;

                // accepts null sectionhandler return
                LogManager.Reset(r);
                log = LogManager.GetLogger <LogManagerTests>();
                Assert.AreEqual(typeof(NoOpLogger), log.GetType());

                // accepts ILoggerFactoryAdapter sectionhandler returns
                LogManager.Reset(r);
                log = LogManager.GetLogger(typeof(LogManagerTests));
                Assert.AreEqual(typeof(TraceLogger), log.GetType());

                // accepts LogSetting sectionhandler returns
                LogManager.Reset(r);
                log = LogManager.GetLogger(typeof(LogManagerTests));
                Assert.AreEqual(typeof(ConsoleOutLogger), log.GetType());

                // every other return type throws ConfigurationException
                LogManager.Reset(r);
                Assert.Throws(Is.TypeOf <ConfigurationException>()
                              .And.Message.EqualTo(string.Format("ConfigurationReader {0} returned unknown settings instance of type System.Object", r.GetType().Name))
                              , delegate
                {
                    log = LogManager.GetLogger(typeof(LogManagerTests));
                }
                              );
            }
        }