Пример #1
0
        public void UnitTests_PhaxCode_AttachNoOptions()
        {
            var testPdf = BinaryFixtures.getTestPdfFile();

            Action <IRestRequest> requestAsserts = req =>
            {
                Assert.AreEqual(1, req.Files.Count);
                Assert.AreEqual("filename", req.Files[0].Name);

                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(1, parameters["x"], "x's should be the same.");
                Assert.AreEqual(2, parameters["y"], "y's should be the same.");
            };

            var clientBuilder = new IRestClientBuilder {
                Op = "attachPhaxCodeToPdf", RequestAsserts = requestAsserts
            };

            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.BuildUntyped());

            var pdfBytes = phaxio.AttachPhaxCodeToPdf(1, 2, testPdf);

            Assert.IsNotEmpty(pdfBytes);

            var expectedPdf = BinaryFixtures.GetTestPdf();

            Assert.AreEqual(expectedPdf, pdfBytes, "PDFs should be the same.");
        }
Пример #2
0
        public void IntegrationTests_PhaxCode_AttachCodeAndGetBytes()
        {
            var config = new KeyManager();

            var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]);

            var testPdf = BinaryFixtures.getTestPdfFile();

            var code = phaxio.AttachPhaxCodeToPdf(0, 0, testPdf);

            Assert.IsNotEmpty(code);
        }
Пример #3
0
        // This is test runs faily long since Phaxio rate limits
        public void IntegrationTests_Fax_BasicScenario()
        {
            var config = new KeyManager();

            var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]);

            // Create a phax code
            var metadata = StringHelpers.Random(10);

            var phaxCodePng = phaxio.DownloadPhaxCodePng(metadata);

            var phaxCodeFilename = metadata + ".png";

            filesToCleanup.Add(phaxCodeFilename);

            File.WriteAllBytes(phaxCodeFilename, phaxCodePng);

            // Attach phax code to pdf
            var testPdf = BinaryFixtures.getTestPdfFile();

            var testPdfWithCodeBytes = phaxio.AttachPhaxCodeToPdf(0, 0, testPdf, metadata: metadata);

            var testPdfWithCodeFilename = metadata + ".pdf";

            filesToCleanup.Add(testPdfWithCodeFilename);

            File.WriteAllBytes(testPdfWithCodeFilename, testPdfWithCodeBytes);

            var testPdfWithCode = new FileInfo(testPdfWithCodeFilename);

            // Send phax using pdf with phax code
            var faxId = phaxio.SendFax("8088675309", testPdfWithCode);

            // Phaxio rate limits, so we need to wait a second.
            Thread.Sleep(100);

            // Download a thumbnail of the sent fax
            // It takes a little while for a fax to show up
            int retries = 0;
            bool downloadSuccess = false;
            while (retries < 20 && !downloadSuccess)
            {
                try
                {
                    var thumbnailBytes = phaxio.DownloadFax(faxId, "s");
                    var thumbnailFilename = metadata + ".jpg";

                    filesToCleanup.Add(thumbnailFilename);

                    File.WriteAllBytes(thumbnailFilename, thumbnailBytes);

                    downloadSuccess = true;
                }
                catch (Exception)
                {
                    retries++;
                    Thread.Sleep(1000);
                }
            }

            Assert.IsTrue(downloadSuccess, "DownloadFax should've worked");

            // Resend fax
            var resendResult = phaxio.ResendFax(faxId);

            Assert.True(resendResult.Success, "ResendFax should return success.");

            Thread.Sleep(500);

            // Cancel a fax
            var cancelResult = phaxio.CancelFax(faxId);

            Assert.IsFalse(cancelResult.Success, "CancelFax should not be successful.");

            Thread.Sleep(500);

            // Delete a fax
            var deleteResult = phaxio.DeleteFax(faxId);

            Assert.True(resendResult.Success, "DeleteResult should return success.");
        }
Пример #4
0
        public void UnitTests_PhaxCode_AttachNoOptions()
        {
            var testPdf = BinaryFixtures.getTestPdfFile();

            Action<IRestRequest> requestAsserts = req =>
            {
                Assert.AreEqual(1, req.Files.Count);
                Assert.AreEqual("filename", req.Files[0].Name);

                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(1, parameters["x"], "x's should be the same.");
                Assert.AreEqual(2, parameters["y"], "y's should be the same.");
            };

            var clientBuilder = new IRestClientBuilder { Op = "attachPhaxCodeToPdf", RequestAsserts = requestAsserts };

            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.BuildUntyped());

            var pdfBytes = phaxio.AttachPhaxCodeToPdf(1, 2, testPdf);

            Assert.IsNotEmpty(pdfBytes);

            var expectedPdf = BinaryFixtures.GetTestPdf();

            Assert.AreEqual(expectedPdf, pdfBytes, "PDFs should be the same.");
        }
Пример #5
0
        // This is test runs faily long since Phaxio rate limits
        public void IntegrationTests_Fax_BasicScenario()
        {
            var config = new KeyManager();

            var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]);

            // Create a phax code
            var metadata = StringHelpers.Random(10);

            var phaxCodePng = phaxio.DownloadPhaxCodePng(metadata);

            var phaxCodeFilename = BinaryFixtures.GetQualifiedPath(metadata + ".png");

            filesToCleanup.Add(phaxCodeFilename);

            File.WriteAllBytes(phaxCodeFilename, phaxCodePng);

            // Attach phax code to pdf
            var testPdf = BinaryFixtures.getTestPdfFile();

            if (extraRateLimit)
            {
                Thread.Sleep(1000);
            }
            var testPdfWithCodeBytes = phaxio.AttachPhaxCodeToPdf(0, 0, testPdf, metadata: metadata);

            var testPdfWithCodeFilename = BinaryFixtures.GetQualifiedPath(metadata + ".pdf");

            filesToCleanup.Add(testPdfWithCodeFilename);

            File.WriteAllBytes(testPdfWithCodeFilename, testPdfWithCodeBytes);

            var testPdfWithCode = new FileInfo(testPdfWithCodeFilename);

            // Send phax using pdf with phax code
            if (extraRateLimit)
            {
                Thread.Sleep(1000);
            }
            var result = phaxio.SendFax("8088675309", testPdfWithCode);

            Assert.That(result.Success, Is.True, $"unsuccessful send: {result.Message}");
            Assert.That(result.Id, Is.Not.Null, $"missing fax ID: {result.Message}");
            var faxId = result.Id;

            // Bail if configured such that the account doesn't support the
            // rest of the test.
            if (!storageEnabled)
            {
                return;
            }

            // Phaxio rate limits, so we need to wait a second.
            if (extraRateLimit)
            {
                Thread.Sleep(1000);
            }
            Thread.Sleep(100);

            // Download a thumbnail of the sent fax
            // It takes a little while for a fax to show up
            int  retries         = 0;
            bool downloadSuccess = false;

            while (retries < 20 && !downloadSuccess)
            {
                try
                {
                    var thumbnailBytes    = phaxio.DownloadFax(faxId, "s");
                    var thumbnailFilename = BinaryFixtures.GetQualifiedPath(metadata + ".jpg");

                    filesToCleanup.Add(thumbnailFilename);

                    File.WriteAllBytes(thumbnailFilename, thumbnailBytes);

                    downloadSuccess = true;
                }
                catch (Exception)
                {
                    retries++;
                    Thread.Sleep(1000);
                }
            }

            Assert.IsTrue(downloadSuccess, "DownloadFax should've worked");

            // Resend fax
            if (extraRateLimit)
            {
                Thread.Sleep(1000);
            }
            var resendResult = phaxio.ResendFax(faxId);

            Assert.True(resendResult.Success, "ResendFax should return success.");

            Thread.Sleep(500);

            // Cancel a fax
            var cancelResult = phaxio.CancelFax(faxId);

            Assert.IsFalse(cancelResult.Success, "CancelFax should not be successful.");

            Thread.Sleep(500);

            // Delete a fax
            var deleteResult = phaxio.DeleteFax(faxId);

            Assert.True(resendResult.Success, "DeleteResult should return success.");
        }