Beispiel #1
0
        private ILog GetLoggerFromType(Type type)
        {
            var loggerName = _loggerMapper.GetLoggerName(type);
            var logger     = _log4NetAdapter.GetLogger(loggerName);

            return(logger);
        }
        public void SHOULD_INJECT_CONSTRUCTOR_WITH_MAPPED_LOGGER(string loggerName)
        {
            //Arrange
            var builder       = new ContainerBuilder();
            var loggingModule = new Log4NetModule(new Log4NetMiddleware(_log4NetAdapter, _loggerMapperAdapter));
            var fakeLogger    = Substitute.For <ILog>();

            fakeLogger.Logger.Name.Returns(loggerName);
            _log4NetAdapter.GetLogger(loggerName).Returns(fakeLogger);
            builder.RegisterModule(loggingModule);
            builder.RegisterType <InjectableClass>();
            _loggerMapperAdapter.GetLoggerName(typeof(InjectableClass)).Returns(loggerName);
            var container = builder.Build();

            //Act
            var resolved = container.Resolve <InjectableClass>();

            //Assert
            resolved.InternalLogger.Logger.Name.Should().Be(loggerName);
        }