public async void IReport_Download_Tests() { PdfReport report = new PdfReport("a/b/c/file.pdf"); Assert.True(await report.Configure(PdfApiMock.Object, BarcodeMock.Object), "Configure should succeed"); byte[] actualContent; byte[] expectedContent = { 0x01, 0x02, 0x03 }; await using (MemoryStream ms = new MemoryStream()) { await report.Download(ms); actualContent = ms.ToArray(); } PdfApiMock.Verify(e => e.DownloadFileAsync("a/b/c/file.pdf", null, null), Times.Exactly(1)); Assert.True(actualContent.SequenceEqual(expectedContent), "Download bytes do not match"); PdfApiMock.Invocations.Clear(); await using (MemoryStream ms = new MemoryStream()) { await report.Download(PdfApiMock.Object, ms, "a/b/c/file.pdf", null); actualContent = ms.ToArray(); } PdfApiMock.Verify(e => e.DownloadFileAsync("a/b/c/file.pdf", null, null), Times.Exactly(1)); Assert.True(actualContent.SequenceEqual(expectedContent), "Download bytes do not match"); }
public async void IReport_RemoveFile_Tests() { PdfReport report = new PdfReport("a/b/c/file.pdf"); Assert.True(await report.Configure(PdfApiMock.Object, BarcodeMock.Object), "Configure should succeed"); PdfApiMock.Invocations.Clear(); await report.RemoveFile("a/b/c/file.mock"); PdfApiMock.Verify(e => e.DeleteFileAsync("a/b/c/file.mock", null, null)); }
public async void IReport_RemoveFolder_Tests() { PdfReport report = new PdfReport("a/b/c/file.pdf"); Assert.True(await report.Configure(PdfApiMock.Object, BarcodeMock.Object), "Configure should succeed"); PdfApiMock.Invocations.Clear(); await report.RemoveFolder("mock_test"); PdfApiMock.Verify(e => e.DeleteFolderAsync("a/b/c/mock_test", null, It.IsAny <bool?>())); }
public async void IReport_CreateFolderPath_Tests() { PdfReport report = new PdfReport("a/b/c/file.pdf"); Assert.True(await report.Configure(PdfApiMock.Object, BarcodeMock.Object), "Configure should succeed"); PdfApiMock.Invocations.Clear(); await report.CreateFolderPath("1/2/3/mock_test"); PdfApiMock.Verify(e => e.CreateFolderAsync("1/2/3/mock_test", null)); }
public async void IReport_Configure_Tests() { PdfReport report = new PdfReport("a/b/c/file.pdf"); Assert.True(await report.Configure(PdfApiMock.Object, BarcodeMock.Object), "Configure should succeed"); PdfApiMock.Verify(e => e.CreateFolderAsync("a", null), Times.Exactly(2)); PdfApiMock.Verify(e => e.CreateFolderAsync("a/b", null), Times.Exactly(2)); PdfApiMock.Verify(e => e.CreateFolderAsync("a/b/c", null), Times.Exactly(2)); PdfApiMock.Verify(e => e.CreateFolderAsync("a/b/c/tmp_file.pdf", null), Times.Once); PdfApiMock.Verify(e => e.ObjectExistsAsync("a", null, null), Times.Exactly(2)); PdfApiMock.Verify(e => e.ObjectExistsAsync("a/b", null, null), Times.Exactly(2)); PdfApiMock.Verify(e => e.ObjectExistsAsync("a/b/c", null, null), Times.Exactly(2)); PdfApiMock.Verify(e => e.ObjectExistsAsync("a/b/c/tmp_file.pdf", null, null), Times.Once); }
public async void IReport_ReportMultiple_Tests() { PdfReport report = new PdfReport("a/b/c/file.pdf"); Assert.True(await report.Configure(PdfApiMock.Object, BarcodeMock.Object), "Configure should succeed"); var result = await report.Report(new Report.Model.Document() { DefaultFont = new Font { Name = "name1", Size = 10, Style = "italic" }, Content = new List <ContentObject>() { new ContentObject { Page = new List <PageContentItem>() { new PageContentItem() { Text = "mock text", Location = new Location() { Left = 10, Top = 20, Right = 300, Bottom = 400 } }, new PageContentItem() { Url = "file://issue-link-qr?link=123", Location = new Location() { Left = 50, Top = 60, Right = 700, Bottom = 800 } }, new PageContentItem() { Rows = new List <TableRow>() { new TableRow() { Cells = new List <TableCell>() { new TableCell() { Text = "cell 11" }, new TableCell() { Text = "cell 12" } } } } } } }, new ContentObject { Page = new List <PageContentItem>() { new PageContentItem() { Text = "mock text2", Location = new Location() { Left = 10, Top = 20, Right = 300, Bottom = 400 } }, new PageContentItem() { Url = "file://issue-link-qr?link=123", Location = new Location() { Left = 50, Top = 60, Right = 700, Bottom = 800 } }, new PageContentItem() { Rows = new List <TableRow>() { new TableRow() { Cells = new List <TableCell>() { new TableCell() { Text = "cell 11-1" }, new TableCell() { Text = "cell 12-1" } } } } } } } } }); Assert.True(result, "Invalid Report result"); Assert.Equal("name1", report._defaultFont.Name); Assert.Equal(10, report._defaultFont.Size); Assert.Equal("italic", report._defaultFont.Style); PdfApiMock.Verify(e => e.PutCreateDocumentAsync(It.IsRegex("[-0-9A-Fa-f]*\\.pdf"), null, "a/b/c/tmp_file.pdf"), Times.Exactly(2)); PdfApiMock.Verify(e => e.PostDocumentTextHeaderAsync(It.IsRegex("[-0-9A-Fa-f]*\\.pdf"), It.Is <TextHeader>(h => Regex.IsMatch(h.Value, "Generated.*by Aspose.PDF Exporter")) , It.IsAny <int?>(), It.IsAny <int?>(), null, "a/b/c/tmp_file.pdf"), Times.Exactly(2)); PdfApiMock.Verify(e => e.PostDocumentTextHeaderAsync(It.IsRegex("[-0-9A-Fa-f]*\\.pdf"), It.Is <TextHeader>(h => Regex.IsMatch(h.Value, "Generated.*by Aspose.PDF Exporter")) , It.IsAny <int?>(), It.IsAny <int?>(), null, "a/b/c/tmp_file.pdf"), Times.Exactly(2)); PdfApiMock.Verify(e => e.PostDocumentTextFooterAsync(It.IsRegex("[-0-9A-Fa-f]*\\.pdf"), It.Is <TextFooter>(h => Regex.IsMatch(h.Value, "Powered by Aspose.PDF for Cloud, Aspose.Barcode for Cloud")) , It.IsAny <int?>(), It.IsAny <int?>(), null, "a/b/c/tmp_file.pdf"), Times.Exactly(2)); PdfApiMock.Verify(e => e.PutAddTextAsync(It.IsRegex("[-0-9A-Fa-f]*\\.pdf"), 1, It.Is <Paragraph>(p => p.Lines.Exists(l => l.Segments.Exists(s => s.Value == "mock text")) && IsEqual(p.Rectangle.LLX, 10) && IsEqual(p.Rectangle.LLY, 440) && IsEqual(p.Rectangle.URX, 300) && IsEqual(p.Rectangle.URY, 820) ), "a/b/c/tmp_file.pdf", null), Times.Once); PdfApiMock.Verify(e => e.PutAddTextAsync(It.IsRegex("[-0-9A-Fa-f]*\\.pdf"), 1, It.Is <Paragraph>(p => p.Lines.Exists(l => l.Segments.Exists(s => s.Value == "mock text2")) && IsEqual(p.Rectangle.LLX, 10) && IsEqual(p.Rectangle.LLY, 440) && IsEqual(p.Rectangle.URX, 300) && IsEqual(p.Rectangle.URY, 820) ), "a/b/c/tmp_file.pdf", null), Times.Once); PdfApiMock.Verify(e => e.PostInsertImageAsync(It.IsRegex("[-0-9A-Fa-f]*\\.pdf"), 1 , It.Is <double>(m => IsEqual(m, 50)) , It.Is <double>(m => IsEqual(m, 40)) , It.Is <double>(m => IsEqual(m, 700)) , It.Is <double>(m => IsEqual(m, 780)) , It.IsRegex("[-0-9A-Fa-f]*\\.pdf"), null, "a/b/c/tmp_file.pdf", It.IsAny <Stream>()), Times.Exactly(2)); PdfApiMock.Verify(e => e.PostPageTablesAsync(It.IsRegex("[-0-9A-Fa-f]*\\.pdf"), 1, It.Is <List <Table> >(ts => ts.Count == 1 && ts[0].Rows.Count == 1 && ts[0].Rows[0].Cells[0].Paragraphs.Count == 1 && ts[0].Rows[0].Cells[0].Paragraphs[0].Text == "cell 11" && ts[0].Rows[0].Cells[1].Paragraphs.Count == 1 && ts[0].Rows[0].Cells[1].Paragraphs[0].Text == "cell 12" ), null, "a/b/c/tmp_file.pdf"), Times.Once); PdfApiMock.Verify(e => e.PostPageTablesAsync(It.IsRegex("[-0-9A-Fa-f]*\\.pdf"), 1, It.Is <List <Table> >(ts => ts.Count == 1 && ts[0].Rows.Count == 1 && ts[0].Rows[0].Cells[0].Paragraphs.Count == 1 && ts[0].Rows[0].Cells[0].Paragraphs[0].Text == "cell 11-1" && ts[0].Rows[0].Cells[1].Paragraphs.Count == 1 && ts[0].Rows[0].Cells[1].Paragraphs[0].Text == "cell 12-1" ), null, "a/b/c/tmp_file.pdf"), Times.Once); PdfApiMock.Verify(e => e.PutMergeDocumentsAsync("file.pdf", It.Is <MergeDocuments>(f => f.List.Count == 2), null, "a/b/c"), Times.Once); }