I\'m implementing ms word document generation using content controls and OpenXML SDK. I\'d like to have some automated testing for that code (unit tests or some easy UI auto
I am actually doing something similar with the OpenXML SDK for spreadsheets and I actually just write OpenXML api code that opens the file from a stream for the purpose of testing. Unit Tests don't really tell you enough since you need to know if it is a valid file.
// There should be a sheet for every team
[TestMethod]
[HostType("Moles")]
public void CaseExportTeamSheetsTest()
{
IRepository ServiceRepository;
CaseController target;
BuildCaseControllerMoledCases(out ServiceRepository, out target);
FileStreamResult actual = target.Export(); using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(actual.FileStream, false))
{
var services = ServiceRepository.All;
foreach (var item in services)
{
// get a worksheet foreach service
var sheets = spreadsheetDocument.WorkbookPart.Workbook.Descendants().Where(s => s.Name == item.ServiceName);
Assert.IsTrue(sheets.Count() > 0);
}
}
actual.FileStream.Close();
actual.FileStream.Dispose();
}