My service class methode is
public async ValueTask<HttpResponseMessage> UploadFileAsync(string fileKey)
{
..
var multipartContent = new MultipartFormDataContent();
multipartContent.Add(httpContent, "upfile", Path.GetFileName(fileKey));
//in negative test case I am sending empty fileKey value then throwing argument exception from here
..
return httpResponseMessage;
}
I am calling this value task fileupload method in my test case like below
[Fact]
public async Task UploadFileAsync_WhenFileKeyParameterIsEmpty_ReturnArguementException()
{
string fileKey = "";
var ex = Assert.ThrowsAsync<ArgumentException>(()=>objHttpService.UploadFileAsync(fileKey));
Assert.Equal("The value cannot be null or empty. (Parameter 'fileName')", ex.Message);
}
I couldn't able to get any response in ex variable, and getting assert failure like below.
Message: Assert.Throws() Failure Expected: typeof(System.ArgumentException) Actual: (No exception was thrown)