public void LogValuesAndEventId_LogsCorrectValues()
        {
            // Arrange
            var sink          = new TestSink();
            var logger        = SetUp(sink);
            var testLogValues = new TestLogValues()
            {
                Value = 1
            };

            // Act
            logger.LogTrace(1, testLogValues.ToString());
            logger.LogInformation(2, testLogValues.ToString());
            logger.LogWarning(3, testLogValues.ToString());
            logger.LogError(4, testLogValues.ToString());
            logger.LogCritical(5, testLogValues.ToString());
            logger.LogDebug(6, testLogValues.ToString());

            // Assert
            Assert.Equal(6, sink.Writes.Count());

            Assert.True(sink.Writes.TryTake(out var trace));
            Assert.Equal(LogLevel.Trace, trace.LogLevel);
            Assert.Equal(1, trace.EventId);
            Assert.Null(trace.Exception);
            Assert.Equal("Test 1", trace.Formatter(trace.State, trace.Exception));

            Assert.True(sink.Writes.TryTake(out var information));
            Assert.Equal(LogLevel.Information, information.LogLevel);
            Assert.Equal(2, information.EventId);
            Assert.Null(information.Exception);
            Assert.Equal("Test 1", information.Formatter(information.State, information.Exception));

            Assert.True(sink.Writes.TryTake(out var warning));
            Assert.Equal(LogLevel.Warning, warning.LogLevel);
            Assert.Equal(3, warning.EventId);
            Assert.Null(warning.Exception);
            Assert.Equal("Test 1", warning.Formatter(warning.State, warning.Exception));

            Assert.True(sink.Writes.TryTake(out var error));
            Assert.Equal(LogLevel.Error, error.LogLevel);
            Assert.Equal(4, error.EventId);
            Assert.Null(error.Exception);
            Assert.Equal("Test 1", error.Formatter(error.State, error.Exception));

            Assert.True(sink.Writes.TryTake(out var critical));
            Assert.Equal(LogLevel.Critical, critical.LogLevel);
            Assert.Equal(5, critical.EventId);
            Assert.Null(critical.Exception);
            Assert.Equal("Test 1", critical.Formatter(critical.State, critical.Exception));

            Assert.True(sink.Writes.TryTake(out var debug));
            Assert.Equal(LogLevel.Debug, debug.LogLevel);
            Assert.Equal(6, debug.EventId);
            Assert.Null(debug.Exception);
            Assert.Equal("Test 1", debug.Formatter(debug.State, debug.Exception));
        }
        public void LogLevel_LogValuesAndEventId_LogsCorrectValues(LogLevel logLevel, int eventId)
        {
            // Arrange
            var sink          = new TestSink();
            var logger        = SetUp(sink);
            var testLogValues = new TestLogValues()
            {
                Value = 1
            };

            // Act
            logger.Log(logLevel, eventId, testLogValues.ToString());

            // Assert
            Assert.True(sink.Writes.TryTake(out var write));
            Assert.Equal(logLevel, write.LogLevel);
            Assert.Equal(eventId, write.EventId);
            Assert.Null(write.Exception);
            Assert.Equal("Test 1", write.Formatter(write.State, write.Exception));
        }
        public void LogValuesEventIdAndError_LogsCorrectValues()
        {
            // Arrange
            var sink = new TestSink();
            var logger = SetUp(sink);
            var testLogValues = new TestLogValues()
            {
                Value = 1
            };

            // Act
            logger.LogVerbose(1, testLogValues, _exception);
            logger.LogInformation(2, testLogValues, _exception);
            logger.LogWarning(3, testLogValues, _exception);
            logger.LogError(4, testLogValues, _exception);
            logger.LogCritical(5, testLogValues, _exception);
            logger.LogDebug(6, testLogValues, _exception);

            // Assert
            Assert.Equal(6, sink.Writes.Count);

            var verbose = sink.Writes[0];
            Assert.Equal(LogLevel.Verbose, verbose.LogLevel);
            Assert.Same(testLogValues, verbose.State);
            Assert.Equal(1, verbose.EventId);
            Assert.Equal(_exception, verbose.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                verbose.Formatter(verbose.State, verbose.Exception));

            var information = sink.Writes[1];
            Assert.Equal(LogLevel.Information, information.LogLevel);
            Assert.Same(testLogValues, information.State);
            Assert.Equal(2, information.EventId);
            Assert.Equal(_exception, information.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                information.Formatter(information.State, information.Exception));

            var warning = sink.Writes[2];
            Assert.Equal(LogLevel.Warning, warning.LogLevel);
            Assert.Same(testLogValues, warning.State);
            Assert.Equal(3, warning.EventId);
            Assert.Equal(_exception, warning.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                warning.Formatter(warning.State, warning.Exception));

            var error = sink.Writes[3];
            Assert.Equal(LogLevel.Error, error.LogLevel);
            Assert.Same(testLogValues, error.State);
            Assert.Equal(4, error.EventId);
            Assert.Equal(_exception, error.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                error.Formatter(error.State, error.Exception));

            var critical = sink.Writes[4];
            Assert.Equal(LogLevel.Critical, critical.LogLevel);
            Assert.Same(testLogValues, critical.State);
            Assert.Equal(5, critical.EventId);
            Assert.Equal(_exception, critical.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                critical.Formatter(critical.State, critical.Exception));

            var debug = sink.Writes[4];
            Assert.Equal(LogLevel.Debug, debug.LogLevel);
            Assert.Same(testLogValues, debug.State);
            Assert.Equal(6, debug.EventId);
            Assert.Equal(_exception, debug.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                debug.Formatter(debug.State, debug.Exception));
        }
        public void LogValues_LogsCorrectValues()
        {
            // Arrange
            var sink = new TestSink();
            var logger = SetUp(sink);
            var testLogValues = new TestLogValues()
            {
                Value = 1
            };

            // Act
            logger.LogVerbose(testLogValues);
            logger.LogInformation(testLogValues);
            logger.LogWarning(testLogValues);
            logger.LogError(testLogValues);
            logger.LogCritical(testLogValues);
            logger.LogDebug(testLogValues);

            // Assert
            Assert.Equal(6, sink.Writes.Count);

            var verbose = sink.Writes[0];
            Assert.Equal(LogLevel.Verbose, verbose.LogLevel);
            Assert.Same(testLogValues, verbose.State);
            Assert.Equal(0, verbose.EventId);
            Assert.Equal(null, verbose.Exception);
            Assert.Equal("Test 1", verbose.Formatter(verbose.State, verbose.Exception));

            var information = sink.Writes[1];
            Assert.Equal(LogLevel.Information, information.LogLevel);
            Assert.Same(testLogValues, information.State);
            Assert.Equal(0, information.EventId);
            Assert.Equal(null, information.Exception);
            Assert.Equal("Test 1", information.Formatter(information.State, information.Exception));

            var warning = sink.Writes[2];
            Assert.Equal(LogLevel.Warning, warning.LogLevel);
            Assert.Same(testLogValues, warning.State);
            Assert.Equal(0, warning.EventId);
            Assert.Equal(null, warning.Exception);
            Assert.Equal("Test 1", warning.Formatter(warning.State, warning.Exception));

            var error = sink.Writes[3];
            Assert.Equal(LogLevel.Error, error.LogLevel);
            Assert.Same(testLogValues, error.State);
            Assert.Equal(0, error.EventId);
            Assert.Equal(null, error.Exception);
            Assert.Equal("Test 1", error.Formatter(error.State, error.Exception));

            var critical = sink.Writes[4];
            Assert.Equal(LogLevel.Critical, critical.LogLevel);
            Assert.Same(testLogValues, critical.State);
            Assert.Equal(0, critical.EventId);
            Assert.Equal(null, critical.Exception);
            Assert.Equal("Test 1", critical.Formatter(critical.State, critical.Exception));

            var debug = sink.Writes[5];
            Assert.Equal(LogLevel.Debug, debug.LogLevel);
            Assert.Same(testLogValues, debug.State);
            Assert.Equal(0, debug.EventId);
            Assert.Equal(null, debug.Exception);
            Assert.Equal("Test 1", debug.Formatter(debug.State, debug.Exception));
        }
        public void LogValuesEventIdAndError_LogsCorrectValues()
        {
            // Arrange
            var sink          = new TestSink();
            var logger        = SetUp(sink);
            var testLogValues = new TestLogValues()
            {
                Value = 1
            };

            // Act
            logger.LogVerbose(1, testLogValues, _exception);
            logger.LogInformation(2, testLogValues, _exception);
            logger.LogWarning(3, testLogValues, _exception);
            logger.LogError(4, testLogValues, _exception);
            logger.LogCritical(5, testLogValues, _exception);
            logger.LogDebug(6, testLogValues, _exception);

            // Assert
            Assert.Equal(6, sink.Writes.Count);

            var verbose = sink.Writes[0];

            Assert.Equal(LogLevel.Verbose, verbose.LogLevel);
            Assert.Same(testLogValues, verbose.State);
            Assert.Equal(1, verbose.EventId);
            Assert.Equal(_exception, verbose.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                verbose.Formatter(verbose.State, verbose.Exception));

            var information = sink.Writes[1];

            Assert.Equal(LogLevel.Information, information.LogLevel);
            Assert.Same(testLogValues, information.State);
            Assert.Equal(2, information.EventId);
            Assert.Equal(_exception, information.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                information.Formatter(information.State, information.Exception));

            var warning = sink.Writes[2];

            Assert.Equal(LogLevel.Warning, warning.LogLevel);
            Assert.Same(testLogValues, warning.State);
            Assert.Equal(3, warning.EventId);
            Assert.Equal(_exception, warning.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                warning.Formatter(warning.State, warning.Exception));

            var error = sink.Writes[3];

            Assert.Equal(LogLevel.Error, error.LogLevel);
            Assert.Same(testLogValues, error.State);
            Assert.Equal(4, error.EventId);
            Assert.Equal(_exception, error.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                error.Formatter(error.State, error.Exception));

            var critical = sink.Writes[4];

            Assert.Equal(LogLevel.Critical, critical.LogLevel);
            Assert.Same(testLogValues, critical.State);
            Assert.Equal(5, critical.EventId);
            Assert.Equal(_exception, critical.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                critical.Formatter(critical.State, critical.Exception));

            var debug = sink.Writes[4];

            Assert.Equal(LogLevel.Debug, debug.LogLevel);
            Assert.Same(testLogValues, debug.State);
            Assert.Equal(6, debug.EventId);
            Assert.Equal(_exception, debug.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                debug.Formatter(debug.State, debug.Exception));
        }
        public void LogValues_LogsCorrectValues()
        {
            // Arrange
            var sink          = new TestSink();
            var logger        = SetUp(sink);
            var testLogValues = new TestLogValues()
            {
                Value = 1
            };

            // Act
            logger.LogVerbose(testLogValues);
            logger.LogInformation(testLogValues);
            logger.LogWarning(testLogValues);
            logger.LogError(testLogValues);
            logger.LogCritical(testLogValues);
            logger.LogDebug(testLogValues);

            // Assert
            Assert.Equal(6, sink.Writes.Count);

            var verbose = sink.Writes[0];

            Assert.Equal(LogLevel.Verbose, verbose.LogLevel);
            Assert.Same(testLogValues, verbose.State);
            Assert.Equal(0, verbose.EventId);
            Assert.Equal(null, verbose.Exception);
            Assert.Equal("Test 1", verbose.Formatter(verbose.State, verbose.Exception));

            var information = sink.Writes[1];

            Assert.Equal(LogLevel.Information, information.LogLevel);
            Assert.Same(testLogValues, information.State);
            Assert.Equal(0, information.EventId);
            Assert.Equal(null, information.Exception);
            Assert.Equal("Test 1", information.Formatter(information.State, information.Exception));

            var warning = sink.Writes[2];

            Assert.Equal(LogLevel.Warning, warning.LogLevel);
            Assert.Same(testLogValues, warning.State);
            Assert.Equal(0, warning.EventId);
            Assert.Equal(null, warning.Exception);
            Assert.Equal("Test 1", warning.Formatter(warning.State, warning.Exception));

            var error = sink.Writes[3];

            Assert.Equal(LogLevel.Error, error.LogLevel);
            Assert.Same(testLogValues, error.State);
            Assert.Equal(0, error.EventId);
            Assert.Equal(null, error.Exception);
            Assert.Equal("Test 1", error.Formatter(error.State, error.Exception));

            var critical = sink.Writes[4];

            Assert.Equal(LogLevel.Critical, critical.LogLevel);
            Assert.Same(testLogValues, critical.State);
            Assert.Equal(0, critical.EventId);
            Assert.Equal(null, critical.Exception);
            Assert.Equal("Test 1", critical.Formatter(critical.State, critical.Exception));

            var debug = sink.Writes[5];

            Assert.Equal(LogLevel.Debug, debug.LogLevel);
            Assert.Same(testLogValues, debug.State);
            Assert.Equal(0, debug.EventId);
            Assert.Equal(null, debug.Exception);
            Assert.Equal("Test 1", debug.Formatter(debug.State, debug.Exception));
        }
        public void LogValuesEventIdAndError_LogsCorrectValues()
        {
            // Arrange
            var sink          = new TestSink();
            var logger        = SetUp(sink);
            var testLogValues = new TestLogValues()
            {
                Value = 1
            };

            // Act
            logger.LogTrace(1, _exception, testLogValues.ToString());
            logger.LogInformation(2, _exception, testLogValues.ToString());
            logger.LogWarning(3, _exception, testLogValues.ToString());
            logger.LogError(4, _exception, testLogValues.ToString());
            logger.LogCritical(5, _exception, testLogValues.ToString());
            logger.LogDebug(6, _exception, testLogValues.ToString());

            // Assert
            Assert.Equal(6, sink.Writes.Count);

            var trace = sink.Writes[0];

            Assert.Equal(LogLevel.Trace, trace.LogLevel);
            Assert.Equal(testLogValues.ToString(), trace.State.ToString());
            Assert.Equal(1, trace.EventId);
            Assert.Equal(_exception, trace.Exception);
            Assert.Equal(
                "Test 1",
                trace.Formatter(trace.State, trace.Exception));

            var information = sink.Writes[1];

            Assert.Equal(LogLevel.Information, information.LogLevel);
            Assert.Equal(testLogValues.ToString(), information.State.ToString());
            Assert.Equal(2, information.EventId);
            Assert.Equal(_exception, information.Exception);
            Assert.Equal(
                "Test 1",
                information.Formatter(information.State, information.Exception));

            var warning = sink.Writes[2];

            Assert.Equal(LogLevel.Warning, warning.LogLevel);
            Assert.Equal(testLogValues.ToString(), warning.State.ToString());
            Assert.Equal(3, warning.EventId);
            Assert.Equal(_exception, warning.Exception);
            Assert.Equal(
                "Test 1",
                warning.Formatter(warning.State, warning.Exception));

            var error = sink.Writes[3];

            Assert.Equal(LogLevel.Error, error.LogLevel);
            Assert.Equal(testLogValues.ToString(), error.State.ToString());
            Assert.Equal(4, error.EventId);
            Assert.Equal(_exception, error.Exception);
            Assert.Equal(
                "Test 1",
                error.Formatter(error.State, error.Exception));

            var critical = sink.Writes[4];

            Assert.Equal(LogLevel.Critical, critical.LogLevel);
            Assert.Equal(testLogValues.ToString(), critical.State.ToString());
            Assert.Equal(5, critical.EventId);
            Assert.Equal(_exception, critical.Exception);
            Assert.Equal(
                "Test 1",
                critical.Formatter(critical.State, critical.Exception));

            var debug = sink.Writes[5];

            Assert.Equal(LogLevel.Debug, debug.LogLevel);
            Assert.Equal(testLogValues.ToString(), debug.State.ToString());
            Assert.Equal(6, debug.EventId);
            Assert.Equal(_exception, debug.Exception);
            Assert.Equal(
                "Test 1",
                debug.Formatter(debug.State, debug.Exception));
        }