Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void DebugLoggedUserTest()
        {
            //-- Arrange
            var userEnricher = new SerilogUserLogEnricher();

            var expectedLevel = "Debug";
            var expected      = "This is debug message.  MessagePayload { SomeString = \"some payload\" }";
            var actor         = new SerilogAdapter(new Serilog.LoggerConfiguration()
                                                   .Enrich.FromLogContext()
                                                   .WriteTo.MockConsoleForUser()
                                                   .MinimumLevel.Debug());

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