private static TestLocal InitializeCommander(ICommandRegistrationContainer registrations, Action <IConsoleCommand> assert)
        {
            var memoryRx      = MemoryRx.Create();
            var loggerFactory = new LoggerFactory(memoryRx);

            var builder = new ContainerBuilder();

            builder
            .RegisterInstance(loggerFactory)
            .As <ILoggerFactory>();

            builder
            .RegisterInstance(assert);

            builder
            .RegisterModule(new CommanderModule(registrations));


            var container = builder.Build();
            var scope     = container.BeginLifetimeScope();

            return(new TestLocal(container, scope)
            {
                MemoryRx = memoryRx,
                Executor = scope.Resolve <ICommandLineExecutor>(),
                Assert = assert
            });
        }
Beispiel #2
0
        public void Log_TwoRxs_Logged()
        {
            var memoryRx1 = MemoryRx.Create();
            var memoryRx2 = MemoryRx.Create();

            var loggerFactory = new LoggerFactory(memoryRx1, memoryRx2);

            var logger1 = loggerFactory.CreateLogger("Logger1");
            var logger2 = loggerFactory.CreateLogger("Logger2");

            logger1.Information("Hallo1");
            logger2.Information("Hallo2");

            Assert.AreEqual(2, memoryRx1.Logs.Count);
            Assert.AreEqual(2, memoryRx2.Logs.Count);

            logger1.Dispose();

            logger1.Information("Hallo3"); // does not log anymore
            logger2.Information("Hallo4");

            Assert.AreEqual(3, memoryRx1.Logs.Count);
            Assert.AreEqual(3, memoryRx2.Logs.Count);
            Assert.That.Collection().AreEqual(new[] { "Hallo1", "Hallo2", "Hallo4" }, memoryRx1.Logs.Select(x => x.Message()));
            Assert.That.Collection().AreEqual(new[] { "Hallo1", "Hallo2", "Hallo4" }, memoryRx2.Logs.Select(x => x.Message()));
        }
Beispiel #3
0
        public static (MemoryRx, ILoggerFactory, ILogger) Create(IEnumerable <DateTime> timestamps = null)
        {
            var memoryRx = MemoryRx.Create();

            var loggerFactory = new LoggerFactory(memoryRx)
            {
                Configuration = new LoggerConfiguration
                {
                    Attachements =
                    {
                        new MockTimestamp(timestamps)
                    }
                }
            };

            return(memoryRx, loggerFactory, loggerFactory.CreateLogger("MockLogger"));
        }
Beispiel #4
0
        public void Log_LogFilterGreaterThenOrEqual_Logged()
        {
            var memoryRx      = MemoryRx.Create();
            var loggerFactory = new LoggerFactory(memoryRx)
            {
                Configuration = new LoggerConfiguration
                {
                    LogPredicate = LogFilter.Any.Min(LogLevel.Information)
                }
            };

            var logger = loggerFactory.CreateLogger("TestLogger");

            logger.Trace("Hallo trace!");
            logger.Debug("Hallo debug!");
            logger.Information("Hallo information!");
            logger.Warning("Hallo warning!");
            logger.Error("Hallo error!");
            logger.Fatal("Hallo fatal!");

            Assert.AreEqual(4, memoryRx.Logs.Count);
        }
Beispiel #5
0
        public void Log_LogFilterContains_Logged()
        {
            //var (memoryRx, loggerFactory, logger) = MockLogger.Create(new DateTime(2017, 5, 1), 10);

            var memoryRx      = MemoryRx.Create();
            var loggerFactory = new LoggerFactory(memoryRx)
            {
                Configuration = new LoggerConfiguration
                {
                    LogPredicate = LogFilter.Any.Contains(LogLevel.Debug | LogLevel.Error)
                }
            };

            var logger = loggerFactory.CreateLogger("TestLogger");

            logger.Trace("Hallo trace!");
            logger.Debug("Hallo debug!");
            logger.Information("Hallo information!");
            logger.Warning("Hallo warning!");
            logger.Error("Hallo error!");
            logger.Fatal("Hallo fatal!");

            Assert.AreEqual(2, memoryRx.Logs.Count);
        }