Ejemplo n.º 1
0
        public void UnitTests_Fax_DownloadFax_WithOptions()
        {
            Action <IRestRequest> requestAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(parameters["id"], "1234");
                Assert.AreEqual(parameters["type"], "l");
            };

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

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

            var testPdf = BinaryFixtures.getTestPdfFile();

            var pdfBytes = phaxio.DownloadFax("1234", "l");

            Assert.IsNotEmpty(pdfBytes);

            var expectedPdf = BinaryFixtures.GetTestPdf();

            Assert.AreEqual(expectedPdf, pdfBytes, "PDFs should be the same.");
        }
Ejemplo n.º 2
0
        public void UnitTests_GetHostedDocument_WithMetadata()
        {
            var metadata = "key";
            var filename = "hostedoc.pdf";

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

                Assert.AreEqual(parameters["name"], filename);
                Assert.AreEqual(parameters["metadata"], metadata);
            };

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

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

            var testPdf = BinaryFixtures.getTestPdfFile();

            var pdfBytes = phaxio.GetHostedDocument(filename, metadata: metadata);

            Assert.IsNotEmpty(pdfBytes);

            var expectedPdf = BinaryFixtures.GetTestPdf();

            Assert.AreEqual(expectedPdf, pdfBytes, "PDFs should be the same.");
        }
Ejemplo n.º 3
0
        public void UnitTests_Fax_SendSingleBinaryNoOptions()
        {
            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 testPdf     = BinaryFixtures.GetTestPdf();
            var testPdfFile = BinaryFixtures.getTestPdfFile();

            var fax    = phaxio.CreateFax();
            var result = fax.Send("8088675309", testPdf, testPdfFile.Name);

            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.");
        }
Ejemplo n.º 4
0
        public IRestClient BuildUntyped()
        {
            var mockIRestClient = new Mock <IRestClient>();

            if (Op == "createPhaxCodeDownload")
            {
                mockIRestClient.Setup(x => x.Execute(It.IsAny <IRestRequest>()))
                .Returns <IRestRequest>(req =>
                {
                    var response   = new RestResponse();
                    var authFailed = false;

                    checks(req, () =>
                    {
                        authFailed = true;
                    });

                    if (authFailed)
                    {
                        response.ContentType = "application/json";
                        response.Content     = JsonResponseFixtures.Fixtures["authFail"];
                    }
                    else
                    {
                        response.ContentType = "image/png";
                        response.RawBytes    = BinaryFixtures.GetTestPhaxCode();
                    }

                    return(response);
                });
            }
            else if (Op == "attachPhaxCodeToPdf")
            {
                mockIRestClient.Setup(x => x.Execute(It.IsAny <IRestRequest>()))
                .Returns <IRestRequest>(req =>
                {
                    var response   = new RestResponse();
                    var authFailed = false;

                    checks(req, () =>
                    {
                        authFailed = true;
                    });

                    if (authFailed)
                    {
                        response.ContentType = "application/json";
                        response.Content     = JsonResponseFixtures.Fixtures["authFail"];
                    }
                    else
                    {
                        response.ContentType = "application/pdf";
                        response.RawBytes    = BinaryFixtures.GetTestPdf();
                    }

                    return(response);
                });
            }
            else if (Op == "attachPhaxCodeToPdfStream")
            {
                mockIRestClient.Setup(x => x.Execute(It.IsAny <IRestRequest>()))
                .Returns <IRestRequest>(req =>
                {
                    var response   = new RestResponse();
                    var authFailed = false;

                    checks(req, () =>
                    {
                        authFailed = true;
                    });

                    if (authFailed)
                    {
                        response.ContentType = "application/json";
                        response.Content     = JsonResponseFixtures.Fixtures["authFail"];
                    }
                    else
                    {
                        response.ContentType = "application/pdf";
                        var writer           = req.ResponseWriter;
                        var testPdf          = BinaryFixtures.getTestPdfFile();
                        writer(testPdf.OpenRead());
                    }

                    return(response);
                });
            }
            else if (Op == "faxFile")
            {
                mockIRestClient.Setup(x => x.Execute(It.IsAny <IRestRequest>()))
                .Returns <IRestRequest>(req =>
                {
                    var response   = new RestResponse();
                    var authFailed = false;

                    checks(req, () =>
                    {
                        authFailed = true;
                    });

                    if (authFailed)
                    {
                        response.ContentType = "application/json";
                        response.Content     = JsonResponseFixtures.Fixtures["authFail"];
                    }
                    else
                    {
                        response.ContentType = "application/pdf";
                        response.RawBytes    = BinaryFixtures.GetTestPdf();
                    }

                    return(response);
                });
            }
            else if (Op == "getHostedDocument")
            {
                mockIRestClient.Setup(x => x.Execute(It.IsAny <IRestRequest>()))
                .Returns <IRestRequest>(req =>
                {
                    var response   = new RestResponse();
                    var authFailed = false;

                    checks(req, () =>
                    {
                        authFailed = true;
                    });

                    if (authFailed)
                    {
                        response.ContentType = "application/json";
                        response.Content     = JsonResponseFixtures.Fixtures["authFail"];
                    }
                    else
                    {
                        response.ContentType = "application/pdf";
                        response.RawBytes    = BinaryFixtures.GetTestPdf();
                    }

                    return(response);
                });
            }

            return(mockIRestClient.Object);
        }