I want to Unit Test a method that returns a FileContentResult of a PDF file. I am doing some tests to check the content type & file name, but it would be great if I could also generate the PDF somehow as part of the test? I currently have a method as follows:
public FileContentResult ConvertToPDF(int baseClassId)
{
try
{
return new DocumentWriter().ConvertDocumentToPDFSharp(baseClassId);
}
catch (Exception ex)
{
Logger.Instance.LogError("Error in Assessments_FormHeaderController ConvertToPDF", ex);
return new FileContentResult(GetBytes("Error fetching pdf, " + ex.Message + Environment.NewLine + ex.StackTrace), "text/plain");
}
}
and I am testing with the following:
[TestMethod]
public void ReturnFileContentResult()
{
DocumentPDFPrinterController pdfController = new DocumentPDFPrinterController();
FileContentResult result = pdfController.ConvertToPDF(0);
Assert.IsTrue(result.ContentType == "application/pdf" && result.FileDownloadName.Contains(".pdf"));
}
Can I add anything to this text which will create the pdf file in a given location(user downloads?).