示例#1
0
        public Result Send(IEnumerable <string> toNumbers, IEnumerable <FileInfo> files, FaxOptions options = null)
        {
            var result = client.SendFax(toNumbers, files, options);

            Id = result.Id;
            return(result);
        }
示例#2
0
        public void UnitTests_Fax_SendMultipleFilesNoOptions()
        {
            var testToNumber = "8088675309";

            Action <IRestRequest> requestAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(testToNumber, parameters["to[]"]);

                Assert.AreEqual(3, parameters.Count());
            };

            var clientBuilder = new IRestClientBuilder {
                Op = "send", RequestAsserts = requestAsserts
            };
            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build());

            var testFile = BinaryFixtures.getTestPdfFile();

            var result = phaxio.SendFax(testToNumber, new List <FileInfo> {
                testFile, testFile
            });

            Assert.AreEqual("1234", result.Id, "FaxId should be the same.");
        }
示例#3
0
        public void UnitTests_Fax_SendSingleWithTags()
        {
            var testToNumber = "8088675309";
            var testOptions  = new FaxOptions
            {
                Tags = new Dictionary <string, string> {
                    { "key1", "value1" }, { "key2", "value2" }
                }
            };

            Action <IRestRequest> requestAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(testToNumber, parameters["to[]"]);

                foreach (var pair in testOptions.Tags)
                {
                    var tagKey = "tag[" + pair.Key + "]";
                    Assert.IsTrue(parameters.ContainsKey(tagKey));
                    Assert.AreEqual(pair.Value, parameters[tagKey]);
                }
            };

            var clientBuilder = new IRestClientBuilder {
                Op = "send", RequestAsserts = requestAsserts
            };
            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build());

            var testFile = BinaryFixtures.getTestPdfFile();

            var result = phaxio.SendFax(testToNumber, testFile, testOptions);

            Assert.AreEqual("1234", result.Id, "FaxId should be the same.");
        }
示例#4
0
        public void IntegrationTests_Fax_Send()
        {
            var config = new KeyManager();

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

            var testPdf = BinaryFixtures.getTestPdfFile();

            var faxId = phaxio.SendFax("8088675309", testPdf);

            Assert.IsNotEmpty(faxId);
        }
示例#5
0
        public void IntegrationTests_Fax_Send()
        {
            var config = new KeyManager();

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

            var testPdf = BinaryFixtures.getTestPdfFile();

            var result = phaxio.SendFax("8088675309", testPdf);

            Assert.IsNotEmpty(result.Id);
        }
示例#6
0
        public void UnitTests_Fax_SendSingleFileSomeOptions()
        {
            var testToNumber = "8088675309";
            var testOptions  = new FaxOptions
            {
                HeaderText     = "headertext",
                StringData     = "somedata",
                StringDataType = "html",
                IsBatch        = true
            };

            Action <IRestRequest> requestAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(testToNumber, parameters["to[]"]);

                var props = typeof(FaxOptions).GetProperties();
                foreach (var prop in props)
                {
                    var serializeAs = prop.GetCustomAttributes(false)
                                      .OfType <SerializeAsAttribute>()
                                      .FirstOrDefault();

                    if (serializeAs != null)
                    {
                        object expectedValue = prop.GetValue(testOptions, null);

                        if (expectedValue == null)
                        {
                            Assert.False(parameters.ContainsKey(serializeAs.Value));
                        }
                        else
                        {
                            Assert.AreEqual(expectedValue, parameters[serializeAs.Value]);
                        }
                    }
                }
            };

            var clientBuilder = new IRestClientBuilder {
                Op = "send", RequestAsserts = requestAsserts
            };
            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build());

            var testFile = BinaryFixtures.getTestPdfFile();

            var result = phaxio.SendFax(testToNumber, testFile, testOptions);

            Assert.AreEqual("1234", result.Id, "FaxId should be the same.");
        }
示例#7
0
        public void UnitTests_Fax_SendSingleFileOptions()
        {
            var testToNumber = "8088675309";
            var testOptions  = new FaxOptions
            {
                HeaderText          = "headertext",
                StringData          = "somedata",
                StringDataType      = "html",
                IsBatch             = true,
                BatchDelaySeconds   = 10,
                AvoidBatchCollision = true,
                CallbackUrl         = "https://example.com/callback",
                CancelTimeoutAfter  = 20,
                CallerId            = "3213214321",
                FailureErrorType    = "failure_type"
            };

            Action <IRestRequest> requestAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(testToNumber, parameters["to[]"]);

                var props = typeof(FaxOptions).GetProperties();
                foreach (var prop in props)
                {
                    var serializeAs = prop.GetCustomAttributes(false)
                                      .OfType <SerializeAsAttribute>()
                                      .FirstOrDefault();

                    if (serializeAs != null)
                    {
                        object expectedValue = prop.GetValue(testOptions, null);

                        Assert.AreEqual(expectedValue, parameters[serializeAs.Value]);
                    }
                }
            };

            var clientBuilder = new IRestClientBuilder {
                Op = "send", RequestAsserts = requestAsserts
            };
            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build());

            var testFile = BinaryFixtures.getTestPdfFile();

            var result = phaxio.SendFax(testToNumber, testFile, testOptions);

            Assert.AreEqual("1234", result.Id, "FaxId should be the same.");
        }
示例#8
0
        public void UnitTests_Fax_SendSingleFileOptions()
        {
            var testToNumber = "8088675309";
            var testOptions = new FaxOptions
            {
                HeaderText = "headertext",
                StringData = "somedata",
                StringDataType = "html",
                IsBatch = true,
                BatchDelaySeconds = 10,
                AvoidBatchCollision = true,
                CallbackUrl = "https://example.com/callback",
                CancelTimeoutAfter = 20,
                CallerId = "3213214321",
                FailureErrorType = "failure_type"
            };

            Action<IRestRequest> requestAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(testToNumber, parameters["to[]"]);

                var props = typeof(FaxOptions).GetProperties();
                foreach (var prop in props)
                {
                    var serializeAs = prop.GetCustomAttributes(false)
                        .OfType<SerializeAsAttribute>()
                        .FirstOrDefault();

                    if (serializeAs != null)
                    {
                        object expectedValue = prop.GetValue(testOptions, null);

                        Assert.AreEqual(expectedValue, parameters[serializeAs.Value]);
                    }   
                }
            };

            var clientBuilder = new IRestClientBuilder { Op = "send", RequestAsserts = requestAsserts };
            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build());

            var testFile = BinaryFixtures.getTestPdfFile();

            var faxId = phaxio.SendFax(testToNumber, testFile, testOptions);

            Assert.AreEqual("1234", faxId, "FaxId should be the same.");
        }
示例#9
0
        public void UnitTests_Fax_SendSingleFileNoOptions()
        {
            var testToNumber = "8088675309";

            Action<IRestRequest> requestAsserts = req =>
            {
                Assert.AreEqual(req.Parameters[2].Value, testToNumber);
            };

            var clientBuilder = new IRestClientBuilder { Op = "send", RequestAsserts = requestAsserts };
            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build());

            var testFile = BinaryFixtures.getTestPdfFile();

            var faxId = phaxio.SendFax(testToNumber, testFile);

            Assert.AreEqual("1234", faxId, "FaxId should be the same.");
        }
示例#10
0
        public void UnitTests_Fax_SendSingleFileNoOptions()
        {
            var testToNumber = "8088675309";

            Action <IRestRequest> requestAsserts = req =>
            {
                Assert.AreEqual(req.Parameters[2].Value, testToNumber);
            };

            var clientBuilder = new IRestClientBuilder {
                Op = "send", RequestAsserts = requestAsserts
            };
            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build());

            var testFile = BinaryFixtures.getTestPdfFile();

            var result = phaxio.SendFax(testToNumber, testFile);

            Assert.That(result.Success, Is.True, $"unsuccessful call: {result.Message}");
            Assert.That(result.Id, Is.Not.Null, $"no fax ID returned: {result.Message}");
            Assert.AreEqual("1234", result.Id, "FaxId should be the same.");
        }
示例#11
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.");
        }
示例#12
0
        public void UnitTests_Fax_SendSingleFileSomeOptions()
        {
            var testToNumber = "8088675309";
            var testOptions = new FaxOptions
            {
                HeaderText = "headertext",
                StringData = "somedata",
                StringDataType = "html",
                IsBatch = true
            };

            Action<IRestRequest> requestAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(testToNumber, parameters["to[]"]);

                var props = typeof(FaxOptions).GetProperties();
                foreach (var prop in props)
                {
                    var serializeAs = prop.GetCustomAttributes(false)
                        .OfType<SerializeAsAttribute>()
                        .FirstOrDefault();

                    if (serializeAs != null)
                    {
                        object expectedValue = prop.GetValue(testOptions, null);

                        if (expectedValue == null)
                        {
                            Assert.False(parameters.ContainsKey(serializeAs.Value));
                        }
                        else
                        {
                            Assert.AreEqual(expectedValue, parameters[serializeAs.Value]);
                        }
                    }
                }
            };

            var clientBuilder = new IRestClientBuilder { Op = "send", RequestAsserts = requestAsserts };
            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build());

            var testFile = BinaryFixtures.getTestPdfFile();

            var faxId = phaxio.SendFax(testToNumber, testFile, testOptions);

            Assert.AreEqual("1234", faxId, "FaxId should be the same.");
        }
示例#13
0
        public void UnitTests_Fax_SendMultipleFilesNoOptions()
        {
            var testToNumber = "8088675309";

            Action<IRestRequest> requestAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(testToNumber, parameters["to[]"]);

                Assert.AreEqual(3, parameters.Count());
            };

            var clientBuilder = new IRestClientBuilder { Op = "send", RequestAsserts = requestAsserts };
            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build());

            var testFile = BinaryFixtures.getTestPdfFile();

            var faxId = phaxio.SendFax(testToNumber, new List<FileInfo> { testFile, testFile });

            Assert.AreEqual("1234", faxId, "FaxId should be the same.");
        }
示例#14
0
        public void UnitTests_Fax_SendSingleWithTags()
        {
            var testToNumber = "8088675309";
            var testOptions = new FaxOptions
            {
                Tags = new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } }
            };

            Action<IRestRequest> requestAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(testToNumber, parameters["to[]"]);

                foreach (var pair in testOptions.Tags)
                {
                    var tagKey = "tag[" + pair.Key + "]";
                    Assert.IsTrue(parameters.ContainsKey(tagKey));
                    Assert.AreEqual(pair.Value, parameters[tagKey]);
                }
            };

            var clientBuilder = new IRestClientBuilder { Op = "send", RequestAsserts = requestAsserts };
            var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build());

            var testFile = BinaryFixtures.getTestPdfFile();

            var faxId = phaxio.SendFax(testToNumber, testFile, testOptions);

            Assert.AreEqual("1234", faxId, "FaxId should be the same.");
        }
示例#15
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.");
        }