Пример #1
0
        public void UnitTests_V2_PhoneNumber_Retrieve()
        {
            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Resource("phone_numbers/+18475551234")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/provision_number"))
                             .Ok()
                             .Build <Response <PhoneNumber> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var number = phaxio.PhoneNumber.Retrieve("+18475551234");

            var lastBilledAt  = Convert.ToDateTime("2016-06-16T15:45:32.000-06:00");
            var provisionedAt = Convert.ToDateTime("2016-06-16T15:45:32.000-06:00");

            Assert.AreEqual("+18475551234", number.Number);
            Assert.AreEqual("Northbrook", number.City);
            Assert.AreEqual("Illinois", number.State);
            Assert.AreEqual("United States", number.Country);
            Assert.AreEqual(200, number.Cost);
            Assert.AreEqual(lastBilledAt, number.LastBilledAt);
            Assert.AreEqual(provisionedAt, number.ProvisionedAt);
            Assert.AreEqual("http://example.com", number.CallbackUrl);
        }
Пример #2
0
        public void UnitTests_V2_PhaxCode_RetrievePngWithIdentifier()
        {
            var pngBytes = BinaryFixtures.GetTestPhaxCode();

            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Resource("phax_codes/1234.png")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsPng()
                             .RawBytes(pngBytes)
                             .Ok()
                             .Build();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var phaxCode = new PhaxCode {
                Identifier = "1234", PhaxioClient = phaxio
            };

            Assert.AreEqual(pngBytes, phaxCode.Png);
        }
Пример #3
0
        public void UnitTests_V2_Fax_Download()
        {
            var pdfInBytes = BinaryFixtures.GetTestPdf();

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

                Assert.AreEqual(parameters["thumbnail"], "l");
            };

            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Custom(parameterAsserts)
                                 .Resource("faxes/123456/file")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsPdf()
                             .RawBytes(pdfInBytes)
                             .Ok()
                             .Build();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var fax = new FaxFile(123456, thumbnail: "l");

            fax.PhaxioClient = phaxio;

            var faxBytes = fax.Bytes;

            Assert.AreEqual(pdfInBytes, faxBytes, "Fax bytes should be the same");
        }
Пример #4
0
        public void UnitTests_V2_Fax_Create_With_Byte_Arrays()
        {
            var testPdfBytes = BinaryFixtures.GetTestPdf();
            var testPdfName  = "FileName";

            Action <IRestRequest> parameterAsserts = req =>
            {
                Assert.AreEqual(1, req.Files.Count);
                Assert.AreEqual(testPdfName, req.Files.First().FileName);
                Assert.AreEqual(testPdfBytes, req.Files.First().Bytes);
            };

            var requestAsserts = new RequestAsserts()
                                 .Post()
                                 .Custom(parameterAsserts)
                                 .Resource("faxes")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/fax_send"))
                             .Ok()
                             .Build <Response <Fax> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var fax = phaxio.Fax.Create(to: "123",
                                        byteArrays: new byte[][] { testPdfBytes },
                                        fileNames: new string[] { testPdfName });
        }
Пример #5
0
        public void UnitTests_V2_PhaxCode_Create()
        {
            Action <IRestRequest> parameterAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

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

            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Post()
                                 .Custom(parameterAsserts)
                                 .Resource("phax_codes.json")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/phax_code"))
                             .Ok()
                             .Build <Response <PhaxCode> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var code = phaxio.PhaxCode.Create("stuff");

            Assert.AreEqual("1234", code.Identifier);
        }
Пример #6
0
        public void UnitTests_V2_Fax_Retrieve()
        {
            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Resource("faxes/123456")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/fax_info"))
                             .Ok()
                             .Build <Response <Fax> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var faxInfo = phaxio.Fax.Retrieve(123456);

            DateTime completedAt = Convert.ToDateTime("2015-09-02T11:28:54.000-05:00");

            Assert.AreEqual(123456, faxInfo.Id, "");
            Assert.AreEqual("Alice", faxInfo.CallerName, "");
            Assert.AreEqual(2, faxInfo.Barcodes.Count(), "");

            var barcode = faxInfo.Barcodes.First();

            Assert.AreEqual("barcode-type-1", barcode.Type, "");
            Assert.AreEqual(1, barcode.Page, "");
            Assert.AreEqual("barcode-value-1", barcode.Value, "");
            Assert.AreEqual("phax-code-id-1", barcode.Identifier, "");
            Assert.AreEqual("phax-code-metadata-1", barcode.Metadata, "");

            Assert.AreEqual("sent", faxInfo.Direction, "");
            Assert.AreEqual(3, faxInfo.NumPages, "");
            Assert.AreEqual("success", faxInfo.Status, "");
            Assert.IsTrue(faxInfo.IsTest, "");
            Assert.AreEqual(completedAt, faxInfo.CompletedAt.Value, "");
            Assert.AreEqual(21, faxInfo.Cost, "");
            Assert.AreEqual("123", faxInfo.FromNumber, "");
            Assert.AreEqual("order_id", faxInfo.Tags.First().Key, "");
            Assert.AreEqual("1234", faxInfo.Tags.First().Value, "");
            Assert.AreEqual("321", faxInfo.ToNumber, "");
            Assert.AreEqual(42, faxInfo.ErrorId.Value, "");
            Assert.AreEqual("error_type", faxInfo.ErrorType, "");
            Assert.AreEqual("error_message", faxInfo.ErrorMessage, "");

            var recipient = faxInfo.Recipients.First();

            Assert.AreEqual("+14141234567", recipient.PhoneNumber);
            Assert.AreEqual("success", recipient.Status, "");
            Assert.AreEqual(0, recipient.RetryCount);
            Assert.AreEqual(completedAt, recipient.CompletedAt.Value, "");
            Assert.AreEqual(14400, recipient.Bitrate);
            Assert.AreEqual(8040, recipient.Resolution);
            Assert.AreEqual(41, recipient.ErrorId.Value, "");
            Assert.AreEqual("recipient_error_type", recipient.ErrorType, "");
            Assert.AreEqual("recipient_error_message", recipient.ErrorMessage, "");
        }
Пример #7
0
        public void UnitTests_V2_Fax_Create()
        {
            var testPdf = BinaryFixtures.getTestPdfFile();

            Action <IRestRequest> parameterAsserts = req =>
            {
                Assert.AreEqual(1, req.Files.Count);
                Assert.AreEqual(testPdf.Name, req.Files.First().FileName);

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

                Assert.AreEqual("123", parameters["to"]);
                Assert.AreEqual("http://example.com", parameters["content_url"]);
                Assert.AreEqual("blah", parameters["header_text"]);
                Assert.AreEqual(10, parameters["batch_delay"]);
                Assert.AreEqual(true, parameters["batch_collision_avoidance"]);
                Assert.AreEqual("http://example.org", parameters["callback_url"]);
                Assert.AreEqual(30, parameters["cancel_timeout"]);
                Assert.AreEqual("value", parameters["tag[key]"]);
                Assert.AreEqual("Bob", parameters["caller_id"]);
                Assert.AreEqual("Send failure", parameters["test_fail"]);
            };

            var requestAsserts = new RequestAsserts()
                                 .Post()
                                 .Custom(parameterAsserts)
                                 .Resource("faxes")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/fax_send"))
                             .Ok()
                             .Build <Response <Fax> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var fax = phaxio.Fax.Create(to: "123",
                                        file: testPdf,
                                        contentUrl: "http://example.com",
                                        headerText: "blah",
                                        batchDelay: 10,
                                        batchCollisionAvoidance: true,
                                        callbackUrl: "http://example.org",
                                        cancelTimeout: 30,
                                        tags: new Dictionary <string, string>()
            {
                { "key", "value" }
            },
                                        callerId: "Bob",
                                        testFail: "Send failure");

            Assert.AreEqual(1234, fax.Id);
        }
Пример #8
0
            protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
            {
                RequestAsserts?.Invoke(request);
                var content = request.Content as MultipartFormDataContent;

                Assert.IsType <MultipartFormDataContent>(content);
                Assert.NotNull(Asserts);

                await Asserts(content);

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
Пример #9
0
        public void UnitTests_V2_Fax_List()
        {
            var createdBeforeTxt = "2016-02-01T00:00:00Z";
            var createdBefore    = DateTime.Parse(createdBeforeTxt).ToUniversalTime();

            var createdAfterTxt = "2016-01-01T00:00:00Z";
            var createdAfter    = DateTime.Parse(createdAfterTxt).ToUniversalTime();

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

                Assert.AreEqual(createdBeforeTxt, parameters["created_before"]);
                Assert.AreEqual(createdAfterTxt, parameters["created_after"]);
                Assert.AreEqual("sent", parameters["direction"]);
                Assert.AreEqual("finished", parameters["status"]);
                Assert.AreEqual("1234", parameters["phone_number"]);
                Assert.AreEqual("value", parameters["tag[key]"]);
                Assert.AreEqual(25, parameters["per_page"]);
                Assert.AreEqual(1, parameters["page"]);
            };

            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Custom(parameterAsserts)
                                 .Resource("faxes")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/fax_list"))
                             .Ok()
                             .Build <Response <List <Fax> > >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var list = phaxio.Fax.List(
                createdBefore: createdBefore,
                createdAfter: createdAfter,
                direction: "sent",
                status: "finished",
                phoneNumber: "1234",
                tagName: "key",
                tagValue: "value",
                page: 1,
                perPage: 25
                );

            Assert.AreEqual(3, list.Count());
        }
Пример #10
0
        public void UnitTests_V2_Numbers_ListAreaCodes()
        {
            Action <IRestRequest> parameterAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(true, parameters["toll_free"]);
                Assert.AreEqual("1", parameters["country_code"]);
                Assert.AreEqual("US", parameters["country"]);
                Assert.AreEqual("WA", parameters["state"]);
                Assert.AreEqual(25, parameters["per_page"]);
                Assert.AreEqual(1, parameters["page"]);
            };

            var requestAsserts = new RequestAsserts()
                                 .Get()
                                 .Custom(parameterAsserts)
                                 .Resource("public/area_codes")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/list_area_codes"))
                             .Ok()
                             .Build <Response <List <AreaCode> > >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var list = phaxio.Public.AreaCode.List(
                countryCode: "1",
                tollFree: true,
                country: "US",
                state: "WA",
                page: 1,
                perPage: 25
                );

            Assert.AreEqual(3, list.Count());

            var areaCode = list.First();

            Assert.AreEqual("1", areaCode.CountryCode);
            Assert.AreEqual("201", areaCode.AreaCodeNumber);
            Assert.AreEqual("Bayonne, Jersey City, Union City", areaCode.City);
            Assert.AreEqual("New Jersey", areaCode.State);
            Assert.AreEqual("United States", areaCode.Country);
            Assert.IsFalse(areaCode.TollFree);
        }
Пример #11
0
        public void UnitTests_V2_PhoneNumber_Create()
        {
            Action <IRestRequest> parameterAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual("1", parameters["country_code"]);
                Assert.AreEqual("808", parameters["area_code"]);
                Assert.AreEqual("http://example.com", parameters["callback_url"]);
            };

            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Post()
                                 .Custom(parameterAsserts)
                                 .Resource("phone_numbers")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/provision_number"))
                             .Ok()
                             .Build <Response <PhoneNumber> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var number = phaxio.PhoneNumber.Create(
                countryCode: "1",
                areaCode: "808",
                callbackUrl: "http://example.com"
                );

            var lastBilledAt  = Convert.ToDateTime("2016-06-16T15:45:32.000-06:00");
            var provisionedAt = Convert.ToDateTime("2016-06-16T15:45:32.000-06:00");

            Assert.AreEqual("+18475551234", number.Number);
            Assert.AreEqual("Northbrook", number.City);
            Assert.AreEqual("Illinois", number.State);
            Assert.AreEqual("United States", number.Country);
            Assert.AreEqual(200, number.Cost);
            Assert.AreEqual(lastBilledAt, number.LastBilledAt);
            Assert.AreEqual(provisionedAt, number.ProvisionedAt);
            Assert.AreEqual("http://example.com", number.CallbackUrl);
        }
Пример #12
0
        public void UnitTests_V2_InvalidRequestException()
        {
            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Resource("account/status")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/error_invalid_entity"))
                             .InvalidEntity()
                             .Build <Response <AccountStatus> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            Assert.Throws(typeof(InvalidRequestException), () => Console.Write(phaxio.Account.Status.Balance));
        }
Пример #13
0
        public void UnitTests_V2_NonJsonErrorHandled()
        {
            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Resource("account/status")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsText()
                             .Content("There was an error")
                             .InternalServerError()
                             .Build <Response <AccountStatus> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            Assert.Throws(typeof(ServiceException), () => Console.Write(phaxio.Account.Status.Balance));
        }
Пример #14
0
        public void UnitTests_V2_PhoneNumber_List()
        {
            Action <IRestRequest> parameterAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual("1", parameters["country_code"]);
                Assert.AreEqual("808", parameters["area_code"]);
                Assert.AreEqual(25, parameters["per_page"]);
                Assert.AreEqual(1, parameters["page"]);
            };

            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Custom(parameterAsserts)
                                 .Resource("phone_numbers")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/list_numbers"))
                             .Ok()
                             .Build <Response <List <PhoneNumber> > >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var list = phaxio.PhoneNumber.List(
                countryCode: "1",
                areaCode: "808",
                page: 1,
                perPage: 25
                );

            Assert.AreEqual(2, list.Count());

            var number = list.First();

            Assert.AreEqual("+18475551234", number.Number);
        }
Пример #15
0
        public void UnitTests_V2_PhaxCode_RetrieveWithId()
        {
            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Resource("phax_codes/1234.json")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/phax_code"))
                             .Ok()
                             .Build <Response <PhaxCode> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var code = phaxio.PhaxCode.Retrieve("1234");

            Assert.AreEqual("1234", code.Identifier);
        }
Пример #16
0
        public void UnitTests_V2_SupportedCountries()
        {
            Action <IRestRequest> parameterAsserts = req =>
            {
                var parameters = ParametersHelper.ToDictionary(req.Parameters);

                Assert.AreEqual(25, parameters["per_page"]);
                Assert.AreEqual(1, parameters["page"]);
            };

            var requestAsserts = new RequestAsserts()
                                 .Get()
                                 .Custom(parameterAsserts)
                                 .Resource("public/countries")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/supported_countries"))
                             .Ok()
                             .Build <Response <List <Country> > >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var list = phaxio.Public.SupportedCountry.List(
                page: 1,
                perPage: 25
                );

            var country = list.First();

            Assert.AreEqual("United States", country.Name);
            Assert.AreEqual("US", country.Alpha2);
            Assert.AreEqual("1", country.CountryCode);
            Assert.AreEqual(7, country.PricePerPage);
            Assert.AreEqual("full", country.SendSupport);
            Assert.AreEqual("fullest", country.ReceiveSupport);
        }
Пример #17
0
        public void UnitTests_V2_Fax_DeleteFiles()
        {
            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Delete()
                                 .Resource("faxes/123456/file")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsPdf()
                             .Content(JsonResponseFixtures.FromFile("V2/generic_success"))
                             .Ok()
                             .Build <Response <object> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var file = new FaxFile(123456);

            file.PhaxioClient = phaxio;

            file.Delete();
        }
Пример #18
0
        public void UnitTests_V2_FileDownloadThrowsError()
        {
            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Resource("faxes/123456/file")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/error_rate_limited"))
                             .RateLimited()
                             .Build();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var fax = new FaxFile(123456);

            fax.PhaxioClient = phaxio;

            Assert.Throws(typeof(RateLimitException), () => Console.Write(fax.Pdf.Bytes));
        }
Пример #19
0
        public void UnitTests_V2_Fax_Resend()
        {
            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Post()
                                 .Resource("faxes/123456/resend")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/fax_resend"))
                             .Ok()
                             .Build <Response <object> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var fax = new Fax(123456);

            fax.PhaxioClient = phaxio;

            fax.Resend();
        }
Пример #20
0
        public void UnitTests_V2_Numbers_Release()
        {
            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Delete()
                                 .Resource("phone_numbers/+18475551234")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/generic_success"))
                             .Ok()
                             .Build <Response <Object> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var number = new PhoneNumber {
                Number = "+18475551234", PhaxioClient = phaxio
            };

            number.Release();
        }
Пример #21
0
        public void UnitTests_V2_AccountStatus()
        {
            var requestAsserts = new RequestAsserts()
                                 .Auth()
                                 .Get()
                                 .Resource("account/status")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/account_status"))
                             .Ok()
                             .Build <Response <AccountStatus> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var account = phaxio.Account.Status;

            Assert.AreEqual(15, account.FaxesThisMonth.Sent, "FaxesThisMonth.Sent should be the same.");
            Assert.AreEqual(2, account.FaxesToday.Received, "FaxesToday.Received should be the same.");
            Assert.AreEqual(5050, account.Balance, "Balance should be the same.");
        }
Пример #22
0
        public void UnitTests_V2_TestRecieveCallback()
        {
            var testPdf = BinaryFixtures.getTestPdfFile();

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

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

                Assert.AreEqual((string)parameters["direction"], "received");
                Assert.AreEqual((string)parameters["from_number"], "1");
                Assert.AreEqual((string)parameters["to_number"], "2");
            };

            var requestAsserts = new RequestAsserts()
                                 .Custom(parameterAsserts)
                                 .Auth()
                                 .Post()
                                 .Resource("faxes")
                                 .Build();

            var restClient = new RestClientBuilder()
                             .WithRequestAsserts(requestAsserts)
                             .AsJson()
                             .Content(JsonResponseFixtures.FromFile("V2/generic_success"))
                             .Ok()
                             .Build <Response <Object> >();

            var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient);

            var result = phaxio.Fax.TestRecieveCallback(testPdf, fromNumber: "1", toNumber: "2");

            Assert.IsTrue(result.Success, "Result should be Success = true.");
        }