diff --git a/tests/backend/WebApi.Tests/Controllers/ServiceControllerTests.cs b/tests/backend/WebApi.Tests/Controllers/ServiceControllerTests.cs index 48a723b6..6c1b42c6 100644 --- a/tests/backend/WebApi.Tests/Controllers/ServiceControllerTests.cs +++ b/tests/backend/WebApi.Tests/Controllers/ServiceControllerTests.cs @@ -27,6 +27,8 @@ public async Task Version_ReturnsOkResult() // Assert Assert.That(result, Is.InstanceOf>()); Assert.That(result.Result, Is.InstanceOf()); + _loggerMock.VerifyLog(LogLevel.Information, Times.Once(), "Version was called"); + _loggerMock.VerifyNoError(); } [Test] @@ -50,6 +52,9 @@ public async Task Version_ReturnsVersionWithCorrectProperties() Assert.That(version.EnvironmentName, Is.InstanceOf()); Assert.That(version.InformationalVersion, Is.InstanceOf()); }); + + _loggerMock.VerifyLog(LogLevel.Information, Times.Once(), "Version was called"); + _loggerMock.VerifyNoError(); } [Test] @@ -65,21 +70,7 @@ public async Task Ping_ReturnsOkResult() Assert.That(okResult.Value, Is.Not.Null); Assert.That(okResult.Value, Is.AssignableFrom>()); Assert.That(okResult.Value is GenericValue {Value: "Ok"}); - } - - [Test] - public async Task Ping_LogsInformationMessage() - { - // Act - await _controller.Ping(); - - // Assert - _loggerMock.Verify(static logger => logger.Log( - It.Is(static logLevel => logLevel == LogLevel.Information), - It.Is(static eventId => eventId.Id == 0), - It.Is(static (@object, type) => @object.ToString() == "Ping was called" && type.Name == "FormattedLogValues"), - It.IsAny(), - It.IsAny>()), - Times.Once); + _loggerMock.VerifyLog(LogLevel.Information, Times.Once(), "Ping was called"); + _loggerMock.VerifyNoError(); } } \ No newline at end of file diff --git a/tests/backend/WebApi.Tests/Controllers/WeatherForecastControllerTests.cs b/tests/backend/WebApi.Tests/Controllers/WeatherForecastControllerTests.cs index 15226abb..4a3a61ea 100644 --- a/tests/backend/WebApi.Tests/Controllers/WeatherForecastControllerTests.cs +++ b/tests/backend/WebApi.Tests/Controllers/WeatherForecastControllerTests.cs @@ -41,7 +41,7 @@ public async Task Get_ReturnsFiveWeatherForecasts() var okResult = (OkObjectResult) result.Result; Assert.That(okResult.Value, Is.Not.Null); Assert.That(okResult.Value, Is.AssignableFrom()); - Assert.That(((WeatherForecast[]) okResult.Value).Count(), Is.EqualTo(5)); + Assert.That(((WeatherForecast[]) okResult.Value).Length, Is.EqualTo(5)); } [Test] @@ -56,11 +56,19 @@ public async Task Get_ReturnsWeatherForecastsWithCorrectProperties() var okResult = (OkObjectResult) result.Result; Assert.That(okResult.Value, Is.Not.Null); Assert.That(okResult.Value, Is.AssignableFrom()); + var expectedValueRange = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + foreach (var weatherForecast in (WeatherForecast[]) okResult.Value) { Assert.That(weatherForecast.Date, Is.InstanceOf()); Assert.That(weatherForecast.TemperatureC, Is.InstanceOf()); + Assert.That(weatherForecast.TemperatureC, Is.LessThan(56)); + Assert.That(weatherForecast.TemperatureC, Is.GreaterThan(-19)); Assert.That(weatherForecast.Summary, Is.InstanceOf()); + Assert.That(expectedValueRange, Contains.Item(weatherForecast.Summary)); } } @@ -71,12 +79,6 @@ public async Task Get_LogsInformationMessage() await _controller.Get(); // Assert - _loggerMock.Verify(static logger => logger.Log( - It.Is(static logLevel => logLevel == LogLevel.Information), - It.Is(static eventId => eventId.Id == 0), - It.Is(static (@object, type) => @object.ToString() == "GetWeatherForecast was called" && type.Name == "FormattedLogValues"), - It.IsAny(), - It.IsAny>()), - Times.Once); + _loggerMock.VerifyLog(LogLevel.Information, Times.Once(), "GetWeatherForecast was called"); } } \ No newline at end of file