public void ExportDataToWord_Valid( ) { var table = CreateSampleData( ); ExportDataInfo exportInfo = ExportToWordHelper.ExportToWord(table, "Test Report"); byte[] byteStrem = exportInfo.FileStream; string path = CreateExportDirectory( ); string filePath = Path.Combine(path, "Test.docx"); var file = new FileStream(filePath, FileMode.Create); file.Write(byteStrem, 0, byteStrem.Length); file.Close( ); }
public void Test07DownloadCsvExportedFile() { long reportId = GetReportByAlias("test:managerReport"); ExportDataInfo res = PostExportRequest(string.Format(@"data/v2/report/export/{0}/csv", reportId), HttpStatusCode.OK, new ReportParameters()); Assert.IsNotNullOrEmpty(res.FileHash, "The exported file has been saved to the database."); using ( PlatformHttpRequest request = new PlatformHttpRequest( string.Format(@"data/v2/report/export/download/{0}/sample/csv", res.FileHash), PlatformHttpMethod.Get)) { HttpWebResponse response = request.GetResponse(); Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "We have a {0} returned, expected {1}", response.StatusCode, HttpStatusCode.OK); Assert.AreEqual(response.ContentType, "text/html"); using (Stream stream = response.GetResponseStream()) { Assert.IsNotNull(stream); using (FileStream fileStream = File.Create(CsvFile)) { CopyToFile(stream, fileStream); //Read data from the file fileStream.Position = 0; StreamReader sr = new StreamReader(fileStream); int readLineCount = 0; while (!sr.EndOfStream) { sr.ReadLine(); readLineCount++; } Assert.Greater(readLineCount, 0, "There are no rows in the file."); //Read the first row fileStream.Position = 0; sr = new StreamReader(fileStream); string rowString = sr.ReadLine(); Assert.AreEqual("Name", rowString); //read secong row string row2 = sr.ReadLine(); Assert.AreEqual("Glenn Uidam", row2); } } } }
public void Test08DownloadWordExportedFile() { long reportId = GetReportByAlias("test:managerReport"); ExportDataInfo res = PostExportRequest(string.Format(@"data/v2/report/export/{0}/word", reportId), HttpStatusCode.OK, new ReportParameters()); Assert.IsNotNullOrEmpty(res.FileHash, "The exported file has been saved to the database."); using ( PlatformHttpRequest request = new PlatformHttpRequest( string.Format(@"data/v2/report/export/download/{0}/sample/word", res.FileHash), PlatformHttpMethod.Get)) { HttpWebResponse response = request.GetResponse(); Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "We have a {0} returned, expected {1}", response.StatusCode, HttpStatusCode.OK); Assert.AreEqual(response.ContentType, "text/html"); using (Stream stream = response.GetResponseStream()) { Assert.IsNotNull(stream); using (FileStream fileStream = File.Create(WordFile)) { CopyToFile(stream, fileStream); fileStream.Position = 0; using (WordprocessingDocument doc = WordprocessingDocument.Open(fileStream, false)) { Body body = doc.MainDocumentPart.Document.Body; DocumentFormat.OpenXml.Wordprocessing.Table table = body.Descendants <DocumentFormat.OpenXml.Wordprocessing.Table>().FirstOrDefault(); Assert.IsNotNull(table, "The word document hasn't got a table"); var rows = table.Descendants <TableRow>(); Assert.Greater(rows.Count(), 0, "There are no rows in the table"); //Get first row. TableRow row = rows.First(); TableCell cell = row.GetFirstChild <TableCell>(); Assert.AreEqual("Name", cell.FirstChild.InnerText); //Get second row TableRow row1 = rows.Skip(1).First(); TableCell cell1 = row1.GetFirstChild <TableCell>(); Assert.AreEqual("Glenn Uidam", cell1.FirstChild.InnerText); } } } } }