This question already has an answer here:
I have unit tests which uses following extension method
CSVExtensions.CreateCSVFile(fileName, data);
Now during testing
public static class CSVExtension{
public static void CreateCSVFile(string filename, byte[] bytes)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Content-Length", bytes.Length.ToString());
HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=\"" + filename + ".csv" + "\"");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
HttpContext.Current is always null
Please suggest solution
Aucun commentaire:
Enregistrer un commentaire