public async Task Generate_smoke()
        {
            var file = TestConfig.PathToDocumentPdf;
            CreateImageFromPdfTask sut = new CreateImageFromPdfTask();

            var convertParams = new CreatePdfImageTaskParams()
            {
                Dpi      = 600,
                FromPage = 1,
                Pages    = 1,
                Format   = CreatePdfImageTaskParams.ImageFormat.Png,
            };
            Boolean wasCalled = false;
            await sut.Run(
                file,
                convertParams,
                (i, s) =>
            {
                wasCalled = true;

                var tempFile = Path.GetTempFileName() + ".jpg";
                using (var fs = new FileStream(tempFile, FileMode.Create, FileAccess.Write))
                {
                    s.CopyTo(fs);
                }
                //System.Diagnostics.Process.Start(tempFile);
                return(Task.FromResult <Boolean>(true));
            }
                ).ConfigureAwait(false);

            Assert.IsTrue(wasCalled, "conversion failed.");
        }
Ejemplo n.º 2
0
        public async void Generate_smoke()
        {
            var file = TestConfig.PathToDocumentPdf;
            CreateImageFromPdfTask sut = new CreateImageFromPdfTask();

            var convertParams = new CreatePdfImageTaskParams()
            {
                Dpi      = 150,
                FromPage = 1,
                Pages    = 1,
                Format   = CreatePdfImageTaskParams.ImageFormat.Jpg,
            };
            Boolean wasCalled = false;
            var     result    = await sut.Run(
                file,
                convertParams,
                (i, s) =>
            {
                wasCalled = true;
                return(Task.FromResult <Boolean>(true));
            }
                );

            Assert.IsTrue(wasCalled, "conversion failed.");
        }
        public async Task Generate_with_password_removal()
        {
            var file = TestConfig.PathToPasswordProtectedPdf;
            CreateImageFromPdfTask sut = new CreateImageFromPdfTask();

            sut.Decryptor = new PdfDecrypt()
            {
                Logger = new TestLogger()
            };
            sut.Passwords.Add("jarvistest");

            var convertParams = new CreatePdfImageTaskParams()
            {
                Dpi      = 150,
                FromPage = 1,
                Pages    = 1,
                Format   = CreatePdfImageTaskParams.ImageFormat.Jpg,
            };
            Boolean wasCalled = false;
            await sut.Run(
                file,
                convertParams,
                (i, s) =>
            {
                wasCalled = true;
                return(Task.FromResult <Boolean>(true));
            }
                ).ConfigureAwait(false);

            Assert.IsTrue(wasCalled, "conversion failed.");
        }
        private static void TestFile(
            List <PollerTestResult> retValue,
            CreateImageFromPdfTask task,
            String fileName,
            Byte[] fileContent)
        {
            var tempFile = Path.Combine(Path.GetTempPath(), fileName);

            if (File.Exists(tempFile))
            {
                File.Delete(tempFile);
            }
            File.WriteAllBytes(tempFile, fileContent);
            try
            {
                var convertParams = new CreatePdfImageTaskParams()
                {
                    Dpi      = 150,
                    FromPage = 1,
                    Pages    = 1,
                    Format   = CreatePdfImageTaskParams.ImageFormat.Jpg,
                };
                Boolean wasCalled = false;
                var     result    = task.Run(
                    tempFile,
                    convertParams,
                    (i, s) =>
                {
                    wasCalled = true;
                    return(Task.FromResult <Boolean>(true));
                }
                    );
                result.Wait();
                if (wasCalled)
                {
                    retValue.Add(new PollerTestResult(true, "Pdf to Jpg"));
                }
                else
                {
                    retValue.Add(new PollerTestResult(false, "Pdf to Jpg"));
                }
            }
            catch (Exception ex)
            {
                retValue.Add(new PollerTestResult(false, "Pdf to Jpg: " + ex.Message));
            }
        }