Я пытаюсь утверждать, что когда выдается ошибка, то лови ее в тесте. Я немного растерялся, когда возвращал BadRequest, и теперь мне нужно вернуть 500 с указанным c сообщением.
Вот мой код, который работал с BadRequest.
[Fact]
public async Task AppendEmailBase64Dto_InvalidBase64_ReturnBadRequest()
{
// Arrange
var emailControllerMocks = new EmailControllerMocks();
var mockLogger = emailControllerMocks.MockLogger();
var mockMapper = emailControllerMocks.MockMapper();
var mockEmsWorkUnit = emailControllerMocks.MockEmsWorkUnit();
var mockAzureBlob = emailControllerMocks.MockAzureBlobAndGetTemplate();
// Setup
var userRequestTemplateString = File.ReadAllText(@".\EmailController\UserRequestTemplate.txt");
mockAzureBlob.Setup(blob => blob.GetHtmlBlob(It.IsAny<string>(), It.IsAny<Uri>()))
.ReturnsAsync(userRequestTemplateString);
// Act
var emailController = new Controllers.ApiV10.EmailController(mockLogger.Object, mockMapper.Object, mockEmsWorkUnit.Object, mockAzureBlob.Object);
var jsonString = File.ReadAllText(@".\EmailController\TemplateBase64Invalid.json");
var testEmailBase64Dto = GeneralHelpers.Deserialize<EmailBase64Dto>(jsonString);
var badRequestResult = await emailController.AppendEmailBase64Dto(testEmailBase64Dto) as BadRequestObjectResult;
var result = badRequestResult.Value as BadRequestObjectResult;
var errorMessage = badRequestResult.Value as List<string>;
var statusCode = badRequestResult.StatusCode;
// Assert
Assert.Equal("The provided base64 template is not a valid base64 string", errorMessage[0]);
Assert.Equal(400, statusCode);
}