Ejemplo n.º 1
0
        public async Task ShouldLogHelloWorld()
        {
            // Arrange

            // Act
            await _factory.CreateDefaultClient().GetAsync("/");

            var log = Assert.Single(_factory.GetSerilogTestLoggerSink().LogEntries);

            // Assert the message rendered by a default formatter
            Assert.Equal("Hello \"World\"!", log.Message);
        }
Ejemplo n.º 2
0
        public async Task Test1()
        {
            var client   = _webApplicationFactory.CreateClient();
            var response = await client.GetAsync("/WeatherForecast");

            var testLoggerSink = _webApplicationFactory.GetSerilogTestLoggerSink();
            var logEntry       = testLoggerSink.LogEntries.FirstOrDefault(x => x.LoggerName == "TestingLogsWithSerilogDemo.Controllers.WeatherForecastController");

            logEntry.ShouldNotBeNull();
            logEntry.Message.ShouldBe("test message from \"WeatherForecastController\"");
            logEntry.Properties.ShouldContain(x =>
                                              x.Key == "controller" &&
                                              x.Value.ToString() != null &&
                                              x.Value.ToString() !.Equals("WeatherForecastController", StringComparison.OrdinalIgnoreCase));
            logEntry.Properties.ShouldContain(x => x.Key == "MachineName");
        }