Esempio n. 1
0
        public void PDFComponent_OpenDocument_PasswordProtected_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "PwdProtected(Pwd is pwd).pdf");

            var component = new PDFComponent();

            component.OpenDocument(pdfFile);
            Assert.IsFalse(component.IsDocumentOpened);
            component.OpenDocument(pdfFile, "pwd");
            Assert.IsTrue(component.IsDocumentOpened);
            component.CloseDocument();
            component.Dispose();
        }
        public void PDFPageComponent_Properties_Test_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component     = new PDFComponent();
            var pageComponent = component.PageComponent;

            Assert.IsNotNull(pageComponent);
            Assert.IsNotNull(pageComponent[PageLayoutType.Standard]);

            component.OpenDocument(pdfFile, string.Empty);
            Assert.IsTrue(component.IsDocumentOpened);

            Assert.AreEqual(1, pageComponent.CurrentPageIndex);
            Assert.AreEqual(1094, pageComponent.PageCount);

            // Test all layout adapters
            foreach (PageLayoutType type in Enum.GetValues(typeof(PageLayoutType)))
            {
                Assert.IsNotNull(pageComponent[type]);
            }

            // Standard
            Assert.IsTrue(866448 - pageComponent[PageLayoutType.Standard].CumulativeHeight <= 1, "Value: " + pageComponent[PageLayoutType.Standard].CumulativeHeight);
            Assert.IsTrue(792 - pageComponent[PageLayoutType.Standard].HighestGridCellHeight <= 1, "Value: " + pageComponent[PageLayoutType.Standard].HighestGridCellHeight);
            Assert.IsTrue(612 - pageComponent[PageLayoutType.Standard].WidestGridCellWidth <= 1, "Value: " + pageComponent[PageLayoutType.Standard].WidestGridCellWidth);

            // Thumbnail
            Assert.IsTrue(218800 - (int)pageComponent[PageLayoutType.Thumbnail].CumulativeHeight <= 1, "Value: " + (int)pageComponent[PageLayoutType.Thumbnail].CumulativeHeight);
            Assert.IsTrue(100 - (int)pageComponent[PageLayoutType.Thumbnail].HighestGridCellHeight <= 1, "Value: " + (int)pageComponent[PageLayoutType.Thumbnail].HighestGridCellHeight);
            Assert.IsTrue(77 - (int)pageComponent[PageLayoutType.Thumbnail].WidestGridCellWidth <= 1, "Value: " + (int)pageComponent[PageLayoutType.Thumbnail].WidestGridCellWidth);

            component.CloseDocument();
            component.Dispose();
        }
        public void PDFPageComponent_Pages_Enumerate_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component     = new PDFComponent();
            var pageComponent = component.PageComponent;

            component.OpenDocument(pdfFile, string.Empty);
            Assert.IsTrue(component.IsDocumentOpened);

            Assert.IsNotNull(pageComponent.Pages);

            var pageIndex = 0;

            foreach (var page in pageComponent.Pages)
            {
                Assert.IsNotNull(page);
                Assert.AreEqual(pageIndex++, page.PageIndex);
                Assert.IsNotNull(page.PageLabel);
                Assert.AreEqual(792, page.Height);
                Assert.AreEqual(612, page.Width);
            }

            component.CloseDocument();
            component.Dispose();
        }
Esempio n. 4
0
        public void PDFComponent_OpenDocument_DocumentDoesNotExist_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "FileDoesNotExist.pdf");

            var component = new PDFComponent();

            component.OpenDocument(pdfFile);
            Assert.IsFalse(component.IsDocumentOpened);
            component.Dispose();
        }
Esempio n. 5
0
        public void PDFComponent_OpenDocument_DocumentExists_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component = new PDFComponent();

            component.OpenDocument(pdfFile);
            Assert.IsTrue(component.IsDocumentOpened);
            component.CloseDocument();
            Assert.IsFalse(component.IsDocumentOpened);
            component.CloseDocument();
            Assert.IsFalse(component.IsDocumentOpened);
            component.Dispose();
        }
Esempio n. 6
0
        public void PDFComponent_FileWithPath_Get_Success()
        {
            var pdfFile = _constDiversePagesPDF;
            var pdfPath = Path.Combine(_pdfFilesFolder, pdfFile);

            var component = new PDFComponent();

            Assert.IsNull(component.FileWithPath);
            component.OpenDocument(pdfPath);
            Assert.AreEqual(pdfPath, component.FileWithPath);
            component.CloseDocument();
            Assert.IsNull(component.FileWithPath);

            component.Dispose();
        }
Esempio n. 7
0
        public void PDFComponent_ChildComponents_RequireThem_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component = new PDFComponent();

            var pageComponent = component.PageComponent;

            Assert.IsNotNull(pageComponent);
            var zoomComponent = component.ZoomComponent;

            Assert.IsNotNull(zoomComponent);
            var bookmarkComponent = component.BookmarkComponent;

            Assert.IsNotNull(bookmarkComponent);

            component.OpenDocument(pdfFile);
            Assert.IsTrue(component.IsDocumentOpened);

            pageComponent = component.PageComponent;
            Assert.IsNotNull(pageComponent);
            zoomComponent = component.ZoomComponent;
            Assert.IsNotNull(zoomComponent);
            bookmarkComponent = component.BookmarkComponent;
            Assert.IsNotNull(bookmarkComponent);

            component.CloseDocument();

            pageComponent = component.PageComponent;
            Assert.IsNotNull(pageComponent);
            zoomComponent = component.ZoomComponent;
            Assert.IsNotNull(zoomComponent);
            bookmarkComponent = component.BookmarkComponent;
            Assert.IsNotNull(bookmarkComponent);

            component.Dispose();

            Assert.IsTrue(pageComponent.IsDisposed);
            Assert.IsTrue(zoomComponent.IsDisposed);
            Assert.IsTrue(bookmarkComponent.IsDisposed);

            pageComponent = component.PageComponent;
            Assert.IsNull(pageComponent);
            zoomComponent = component.ZoomComponent;
            Assert.IsNull(zoomComponent);
            bookmarkComponent = component.BookmarkComponent;
            Assert.IsNull(bookmarkComponent);
        }
Esempio n. 8
0
        public void PDFComponent_DocumentInformation_Get_Success()
        {
            var pdfFile   = Path.Combine(_pdfFilesFolder, _constDiversePagesPDF);
            var component = new PDFComponent();

            component.OpenDocument(pdfFile);
            var info = component.DocumentInformation;

            Assert.AreEqual("Diverse pages", info.Title);
            Assert.AreEqual("Miloš Konečný", info.Author);
            Assert.AreEqual("Diverse pages", info.Subject);
            Assert.AreEqual("-", info.Keywords);
            Assert.AreEqual("Miloš Konečný", info.Creator);
            Assert.AreEqual("PDFsharp 1.50.4740 (www.pdfsharp.com)", info.Producer);
            Assert.AreEqual(DateTimeOffset.Parse("2021-02-12T11:37:53+01:00", CultureInfo.InvariantCulture), info.CreationDate);
            Assert.AreEqual(DateTimeOffset.Parse("2021-02-12T11:37:53+01:00", CultureInfo.InvariantCulture), info.ModDate);
            component.Dispose();
        }
Esempio n. 9
0
        public void PDFBookmarkComponent_EnumerateBookmarks_CheckCount_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component         = new PDFComponent();
            var bookmarkComponent = component.BookmarkComponent;

            component.OpenDocument(pdfFile, string.Empty);
            Assert.IsTrue(component.IsDocumentOpened);

            var bookmarkCount          = 0;
            Queue <IPDFBookmark> queue = new Queue <IPDFBookmark>(bookmarkComponent.Bookmarks);

            while (queue.Count != 0)
            {
                var bookmark = queue.Dequeue();
                Assert.IsNotNull(bookmark);
                Assert.IsFalse(string.IsNullOrEmpty(bookmark.Text));
                Assert.IsNotNull(bookmark.Action);
                Assert.IsNotNull(bookmark.Action.Destination);
                Assert.IsNotNull(bookmark.Destination);
                var destA = bookmark.Action.Destination;
                var destB = bookmark.Destination;
                Assert.AreEqual(destA.PageIndex, destB.PageIndex);
                Assert.AreEqual(destA.X, destB.X);
                Assert.AreEqual(destA.Y, destB.Y);
                Assert.AreEqual(destA.Zoom, destB.Zoom);

                bookmarkCount++;
                foreach (var childBookmark in bookmark.Bookmarks)
                {
                    queue.Enqueue(childBookmark);
                }
            }

            Assert.AreEqual(218, bookmarkCount);

            component.CloseDocument();
            component.Dispose();
        }
Esempio n. 10
0
        public void PDFZoomComponent_StartZoom_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component     = new PDFComponent();
            var zoomComponent = component.ZoomComponent;

            Assert.AreEqual(1d, zoomComponent.CurrentZoomFactor);

            component.OpenDocument(pdfFile, string.Empty);
            Assert.IsTrue(component.IsDocumentOpened);
            Assert.AreEqual(1d, zoomComponent.CurrentZoomFactor);

            zoomComponent.CurrentZoomFactor = 2.1d;
            Assert.AreEqual(2.1d, zoomComponent.CurrentZoomFactor);

            component.CloseDocument();
            Assert.AreEqual(1d, zoomComponent.CurrentZoomFactor);

            component.CloseDocument();
            component.Dispose();
        }
Esempio n. 11
0
        public void PDFComponent_Attach_NewComponent_Success()
        {
            // Prepare 'IPDFDocumentObserver'
            var childComponent        = new Mock <IPDFChildComponent>();
            var documentObserver      = childComponent.As <IPDFDocumentObserver>();
            var documentClosedCounter = 0;

            documentObserver.Setup(a => a.DocumentClosed()).Callback(() => documentClosedCounter++);
            var documentClosingCounter = 0;

            documentObserver.Setup(a => a.DocumentClosing()).Callback(() => documentClosingCounter++);
            var documentOpenedCounter = 0;
            var openedFile            = string.Empty;

            documentObserver.Setup(a => a.DocumentOpened(It.IsAny <string>())).Callback <string>((file) =>
            {
                documentOpenedCounter++;
                openedFile = file;
            });
            var documentFailedCounter = 0;
            var failedFile            = string.Empty;

            documentObserver.Setup(a => a.DocumentOpenFailed(It.IsAny <string>())).Callback <string>((file) =>
            {
                documentFailedCounter++;
                failedFile = file;
            });
            var documentOpeningCounter = 0;
            var openingFile            = string.Empty;

            documentObserver.Setup(a => a.DocumentOpening(It.IsAny <string>())).Callback <string>((file) =>
            {
                documentOpeningCounter++;
                openingFile = file;
            });

            var pdfFileExists       = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");
            var pdfFileDoesNotExist = Path.Combine(_pdfFilesFolder, "FileDoesNotExist.pdf");

            var component = new PDFComponent();

            component.Attach(childComponent.Object);

            // Check before any operation processed
            Assert.AreEqual(0, documentClosedCounter);
            Assert.AreEqual(0, documentClosingCounter);
            Assert.AreEqual(0, documentOpenedCounter);
            Assert.AreEqual(0, documentFailedCounter);
            Assert.AreEqual(0, documentOpeningCounter);
            Assert.AreEqual(string.Empty, openedFile);
            Assert.AreEqual(string.Empty, failedFile);
            Assert.AreEqual(string.Empty, openingFile);

            // Open pdf document
            component.OpenDocument(pdfFileExists);
            Assert.IsTrue(component.IsDocumentOpened);

            // Check values
            Assert.AreEqual(0, documentClosedCounter);
            Assert.AreEqual(0, documentClosingCounter);
            Assert.AreEqual(1, documentOpenedCounter);
            Assert.AreEqual(0, documentFailedCounter);
            Assert.AreEqual(1, documentOpeningCounter);
            Assert.AreEqual(pdfFileExists, openedFile);
            Assert.AreEqual(string.Empty, failedFile);
            Assert.AreEqual(pdfFileExists, openingFile);

            // Reset values
            openedFile  = string.Empty;
            openingFile = string.Empty;

            // Close pdf document
            component.CloseDocument();
            Assert.IsFalse(component.IsDocumentOpened);

            // Check values
            Assert.AreEqual(1, documentClosedCounter);
            Assert.AreEqual(1, documentClosingCounter);
            Assert.AreEqual(1, documentOpenedCounter);
            Assert.AreEqual(0, documentFailedCounter);
            Assert.AreEqual(1, documentOpeningCounter);
            Assert.AreEqual(string.Empty, openedFile);
            Assert.AreEqual(string.Empty, failedFile);
            Assert.AreEqual(string.Empty, openingFile);

            // Reset values
            documentClosedCounter  = 0;
            documentClosingCounter = 0;
            documentOpenedCounter  = 0;
            documentFailedCounter  = 0;
            documentOpeningCounter = 0;

            // Open pdf document that does not exist
            component.OpenDocument(pdfFileDoesNotExist);
            Assert.IsFalse(component.IsDocumentOpened);

            // Check values
            Assert.AreEqual(0, documentClosedCounter);
            Assert.AreEqual(0, documentClosingCounter);
            Assert.AreEqual(0, documentOpenedCounter);
            Assert.AreEqual(1, documentFailedCounter);
            Assert.AreEqual(1, documentOpeningCounter);
            Assert.AreEqual(string.Empty, openedFile);
            Assert.AreEqual(pdfFileDoesNotExist, failedFile);
            Assert.AreEqual(pdfFileDoesNotExist, openingFile);

            // Reset values
            failedFile  = string.Empty;
            openingFile = string.Empty;

            // Close pdf document
            component.CloseDocument();
            Assert.IsFalse(component.IsDocumentOpened);

            // Check values
            Assert.AreEqual(0, documentClosedCounter);
            Assert.AreEqual(0, documentClosingCounter);
            Assert.AreEqual(0, documentOpenedCounter);
            Assert.AreEqual(1, documentFailedCounter);
            Assert.AreEqual(1, documentOpeningCounter);
            Assert.AreEqual(string.Empty, openedFile);
            Assert.AreEqual(string.Empty, failedFile);
            Assert.AreEqual(string.Empty, openingFile);

            // Reset values
            documentClosedCounter  = 0;
            documentClosingCounter = 0;
            documentOpenedCounter  = 0;
            documentFailedCounter  = 0;
            documentOpeningCounter = 0;

            // Close not opened pdf document
            component.CloseDocument();
            Assert.IsFalse(component.IsDocumentOpened);

            // Check values
            Assert.AreEqual(0, documentClosedCounter);
            Assert.AreEqual(0, documentClosingCounter);
            Assert.AreEqual(0, documentOpenedCounter);
            Assert.AreEqual(0, documentFailedCounter);
            Assert.AreEqual(0, documentOpeningCounter);
            Assert.AreEqual(string.Empty, openedFile);
            Assert.AreEqual(string.Empty, failedFile);
            Assert.AreEqual(string.Empty, openingFile);

            component.Dispose();
        }