I was trying to attach a csv file as a body parameter in my test script. But still as per the below code controller expect file and just curious how should I pass that.
I run test script in below order
Method-1
public void AttachedRatesFile(string fileName) { _form = string.IsNullOrWhiteSpace(fileName) ? _form = new StringContent(string.Empty) : _form = new StreamContent(File.OpenRead($"{ResourceFolder}{fileName}")); _form.Headers.ContentType = new MediaTypeHeaderValue("application/csv"); _form.Headers.ContentDisposition = new ContentDispositionHeaderValue(fileName); } Method-2
public void PostRequestExecutes(string resource) { var content = new MultipartFormDataContent{_form}; WhenThePostRequestExecutesWithContent(resource, content); } Method-3
public async void WhenThePostRequestExecutesWithContent(string resource, HttpContent content) { ResponseMessage = await HttpClient.PostAsync(resource, content); } I see null in below file parameter
Controller:
public async Task<IActionResult> SeedData(IFormFile file) { var result = await _seedDataService.SeedData(file); return Ok(new { IsUploadSuccesful = result}); }