Skip to content

Commit

Permalink
TEST-0007 Fix more mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
hwinther committed Sep 22, 2024
1 parent e6736b6 commit 6c044b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
23 changes: 7 additions & 16 deletions tests/backend/WebApi.Tests/Controllers/ServiceControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public async Task Version_ReturnsOkResult()
// Assert
Assert.That(result, Is.InstanceOf<ActionResult<VersionInformation>>());
Assert.That(result.Result, Is.InstanceOf<OkObjectResult>());
_loggerMock.VerifyLog(LogLevel.Information, Times.Once(), "Version was called");
_loggerMock.VerifyNoError();
}

[Test]
Expand All @@ -50,6 +52,9 @@ public async Task Version_ReturnsVersionWithCorrectProperties()
Assert.That(version.EnvironmentName, Is.InstanceOf<string>());
Assert.That(version.InformationalVersion, Is.InstanceOf<string>());
});

_loggerMock.VerifyLog(LogLevel.Information, Times.Once(), "Version was called");
_loggerMock.VerifyNoError();
}

[Test]
Expand All @@ -65,21 +70,7 @@ public async Task Ping_ReturnsOkResult()
Assert.That(okResult.Value, Is.Not.Null);
Assert.That(okResult.Value, Is.AssignableFrom<GenericValue<string>>());
Assert.That(okResult.Value is GenericValue<string> {Value: "Ok"});
}

[Test]
public async Task Ping_LogsInformationMessage()
{
// Act
await _controller.Ping();

// Assert
_loggerMock.Verify(static logger => logger.Log(
It.Is<LogLevel>(static logLevel => logLevel == LogLevel.Information),
It.Is<EventId>(static eventId => eventId.Id == 0),
It.Is<It.IsAnyType>(static (@object, type) => @object.ToString() == "Ping was called" && type.Name == "FormattedLogValues"),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception?, string>>()),
Times.Once);
_loggerMock.VerifyLog(LogLevel.Information, Times.Once(), "Ping was called");
_loggerMock.VerifyNoError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<WeatherForecast[]>());
Assert.That(((WeatherForecast[]) okResult.Value).Count(), Is.EqualTo(5));
Assert.That(((WeatherForecast[]) okResult.Value).Length, Is.EqualTo(5));
}

[Test]
Expand All @@ -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<WeatherForecast[]>());
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<DateOnly>());
Assert.That(weatherForecast.TemperatureC, Is.InstanceOf<int>());
Assert.That(weatherForecast.TemperatureC, Is.LessThan(56));
Assert.That(weatherForecast.TemperatureC, Is.GreaterThan(-19));
Assert.That(weatherForecast.Summary, Is.InstanceOf<string>());
Assert.That(expectedValueRange, Contains.Item(weatherForecast.Summary));
}
}

Expand All @@ -71,12 +79,6 @@ public async Task Get_LogsInformationMessage()
await _controller.Get();

// Assert
_loggerMock.Verify(static logger => logger.Log(
It.Is<LogLevel>(static logLevel => logLevel == LogLevel.Information),
It.Is<EventId>(static eventId => eventId.Id == 0),
It.Is<It.IsAnyType>(static (@object, type) => @object.ToString() == "GetWeatherForecast was called" && type.Name == "FormattedLogValues"),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception?, string>>()),
Times.Once);
_loggerMock.VerifyLog(LogLevel.Information, Times.Once(), "GetWeatherForecast was called");
}
}

0 comments on commit 6c044b4

Please sign in to comment.