Http Response Message
Microsoft does not make it easy to mock the HttpResponseMessage . It is an abstract, but still.
private static HttpResponseMessage BuildFakeResponse()
{
HttpResponseMessage response = new()
{
Content = new StringContent("Test Content ", Encoding.UTF8, "text/csv")
};
response.Content.Headers.Add("Content-Disposition", "attachment; filename = yourname.csv");
return response;
}
{
HttpResponseMessage response = new()
{
Content = new StringContent("Test Content ", Encoding.UTF8, "text/csv")
};
response.Content.Headers.Add("Content-Disposition", "attachment; filename = yourname.csv");
return response;
}
Here is one that worked with a model and using Json.
private static HttpResponseMessage BuildFakeResponse()
{
XXXXX xxxx = new();
string jsonXXXX = JsonConvert.SerializeObject(xxxx);
HttpResponseMessage response = new()
{
Content = new StringContent(jsonXXXX, Encoding.UTF8, "application/json")
};
response.Content.Headers.Add("Content-Disposition", "attachment; filename = yourname.csv");
return response;
}
{
XXXXX xxxx = new();
string jsonXXXX = JsonConvert.SerializeObject(xxxx);
HttpResponseMessage response = new()
{
Content = new StringContent(jsonXXXX, Encoding.UTF8, "application/json")
};
response.Content.Headers.Add("Content-Disposition", "attachment; filename = yourname.csv");
return response;
}
Comments
Post a Comment