Пример #1
0
        public void WillLogLoggedOutUserAfterLogout()
        {
            //-- Arrange
            var userEnricher  = new SerilogUserLogEnricher();
            var expectedLevel = "Verbose";
            var expected      = "This is verbose message. MessagePayload { SomeString = \"some payload\" }";
            var actor         = new SerilogAdapter(new Serilog.LoggerConfiguration()
                                                   .Enrich.FromLogContext()
                                                   .WriteTo.MockConsoleForUser()
                                                   .MinimumLevel.Verbose());

            //-- Act
            userEnricher.UserLoggedIn(User);
            actor.Verbose(expected, new MessagePayload()
            {
                SomeString = "some payload"
            });
            Assert.AreEqual($"{expectedLevel}:[{User.UserName}] {expected}", MockFormatSink.LastLogEntry);
            userEnricher.UserLoggedOut();
            actor.Verbose(expected, new MessagePayload()
            {
                SomeString = "some payload"
            });

            //-- Assert
            Assert.AreEqual($"{expectedLevel}:[No-user] {expected}", MockFormatSink.LastLogEntry);
        }
Пример #2
0
        public void VerboseTest()
        {
            //-- Arrange
            var expectedLevel = "Verbose";
            var expected      = "This is verbose message. MessagePayload { SomeString = \"some payload\" }";
            var actor         = new SerilogAdapter(new Serilog.LoggerConfiguration()
                                                   .WriteTo.MockConsole()
                                                   .MinimumLevel.Verbose());

            //-- Act
            actor.Verbose(expected, new MessagePayload()
            {
                SomeString = "some payload"
            });


            //-- Assert
            Assert.AreEqual($"{expectedLevel}:{expected}", MockSink.LastLogEntry);
        }