In my service class, I have this constructor.
public IngestService()
{
_extractedFilePath = configuration["Path:Ingest"];
if (string.IsNullOrEmpty(_extractedFilePath))
{
_logger.LogError($"Invalid conguration. Check appsettings.");
throw new Exception("Invalid conguration. Check appsettings.");
}
}
and I have this test using XUnit
[Fact]
public async Task WhenInvalidConstructor_ThenShouldThrowETest() {
var _ingestService = new IngestService();
}
When I debug it, it can reach the constructor. But how do I capture the exception and assert the exception message "Invalid conguration. Check appsettings."?