public void UnitTests_Phaxio_InvalidSecretThrowsException() { var clientBuilder = new IRestClientBuilder { Op = "accountStatus" }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, "bad_secret", clientBuilder.Build()); Assert.Throws(typeof(ApplicationException), () => phaxio.GetAccountStatus()); }
public void UnitTests_TestRecieveCallback_WithOptions() { var testPdf = BinaryFixtures.getTestPdfFile(); var testFromNumber = "8088675309"; var testToNumber = "2125552368"; 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(parameters["from_number"], testFromNumber); Assert.AreEqual(parameters["to_number"], testToNumber); }; var clientBuilder = new IRestClientBuilder { Op = "testReceive", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var result = phaxio.TestRecieveCallback(testPdf, fromNumber: testFromNumber, toNumber: testToNumber); Assert.IsTrue(result.Success, "Result should be Success = true."); }
public void UnitTests_Phaxio_InvalidKeyThrowsException() { var clientBuilder = new IRestClientBuilder { Op = "accountStatus" }; var phaxio = new PhaxioClient("bad_key", IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); Assert.Throws( typeof(ApplicationException), () => phaxio.GetAccountStatus()); }
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."); }
public void IntegrationTests_AccountStatus_Get() { var config = new KeyManager(); var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]); var account = phaxio.GetAccountStatus(); }
public void UnitTests_Phaxio_ValidKeys() { var clientBuilder = new IRestClientBuilder { Op = "accountStatus" }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var account = phaxio.GetAccountStatus(); var expectedAccount = PocoFixtures.GetTestAccount(); }
public void IntegrationTests_GetHostedDocument() { var config = new KeyManager(); var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]); var filename = "hostedoc.pdf"; Assert.Throws(typeof(ApplicationException), () => phaxio.GetHostedDocument(filename)); }
public void IntegrationTests_PhaxCode_GetCodeBytes() { var config = new KeyManager(); var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]); var code = phaxio.DownloadPhaxCodePng(); Assert.IsNotEmpty(code); }
public bool Get(string key, string secret) { var phaxio = new PhaxioClient(key, secret); var filepath = HostingEnvironment.MapPath("~/App_Data/test.pdf"); phaxio.TestRecieveCallback(new FileInfo(filepath)); return true; }
public void IntegrationTests_Numbers_GetAreaCodes() { var config = new KeyManager(); var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]); var areaCodes = phaxio.ListAreaCodes(state:"HI"); Assert.Greater(areaCodes.Count(), 0, "There should be some area codes"); }
public void UnitTests_PhaxCode_BadDownloadGetsErrorMessage() { var clientBuilder = new IRestClientBuilder { Op = "createPhaxCodeDownload" }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY + "bad stuff", IRestClientBuilder.TEST_SECRET, clientBuilder.BuildUntyped()); var exception = Assert.Throws(typeof(ApplicationException), () => phaxio.DownloadPhaxCodePng()); Assert.AreEqual("That key or secret is not correct.", exception.Message, "Exception message should be about the auth failure."); }
public void IntegrationTests_SupportedCountries() { var config = new KeyManager(); var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]); var countries = phaxio.ListSupportedCountries(); Assert.Greater(countries.Count(), 0, "There should be some countries"); }
public void IntegrationTests_PhaxCode_GetCodeUrl() { var config = new KeyManager(); var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]); var code = phaxio.CreatePhaxCode(); Assert.IsNotEmpty(code.AbsoluteUri); }
public void UnitTests_Numbers_ListNumbers() { var clientBuilder = new IRestClientBuilder { Op = "numberList" }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var actualNumbers = phaxio.ListNumbers(); var expectedNumbers = PocoFixtures.GetTestPhoneNumbers(); Assert.AreEqual(expectedNumbers.Count, actualNumbers.Count, "Number should be the same"); }
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); }
public void UnitTests_PhaxCode_DownloadPng() { var clientBuilder = new IRestClientBuilder { Op = "createPhaxCodeDownload" }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.BuildUntyped()); var imageBytes = phaxio.DownloadPhaxCodePng(); var expectedImageBytes = BinaryFixtures.GetTestPhaxCode(); Assert.AreEqual(expectedImageBytes, imageBytes, "Images should be the same."); }
public void UnitTests_PhaxCode_CreateWithUrl_NoOption() { var clientBuilder = new IRestClientBuilder { Op = "createPhaxCodeUrl" }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var phaxCodeUrl = phaxio.CreatePhaxCode(); var expectedPhaxCodeUrl = PocoFixtures.GetTestPhaxCodeUrl(); Assert.AreEqual(expectedPhaxCodeUrl, phaxCodeUrl, "URLs should be the same."); }
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); }
public void UnitTests_AreaCodes_WithState() { Action<IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[0].Value, "ID"); }; var clientBuilder = new IRestClientBuilder { Op = "areaCodes", NoAuth = true, RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var codes = phaxio.ListAreaCodes(state: "ID"); }
public void UnitTests_SupportedCountries() { var clientBuilder = new IRestClientBuilder { Op = "supportedCountries", NoAuth = true }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var countries = phaxio.ListSupportedCountries(); var expectedCountries = PocoFixtures.GetTestSupportedCountries(); Assert.AreEqual(expectedCountries.Count(), countries.Count(), "Number should be the same"); Assert.AreEqual(expectedCountries["Canada"].PricePerPage, countries["Canada"].PricePerPage, "PricePerPage should be the same"); }
public void UnitTests_AccountStatus () { var clientBuilder = new IRestClientBuilder { Op = "accountStatus" }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var account = phaxio.GetAccountStatus(); var expectedAccount = PocoFixtures.GetTestAccount(); Assert.AreEqual(expectedAccount.FaxesSentThisMonth, account.FaxesSentThisMonth, "FaxesSentThisMonth should be the same."); Assert.AreEqual(expectedAccount.FaxesSentToday, account.FaxesSentToday, "FaxesSentThisWeek should be the same."); Assert.AreEqual(expectedAccount.Balance, account.Balance, "Balance should be the same."); }
public void UnitTests_AreaCodes_NoOptions() { var clientBuilder = new IRestClientBuilder { Op = "areaCodes", NoAuth = true }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var codes = phaxio.ListAreaCodes(tollFree: true); var expectedCodes = PocoFixtures.GetTestAreaCodes(); Assert.AreEqual(expectedCodes.Count(), codes.Count(), "Number should be the same"); Assert.AreEqual(expectedCodes["201"].City, codes["201"].City, "City should be the same"); Assert.AreEqual(expectedCodes["201"].State, codes["201"].State, "State should be the same"); }
public void IntegrationTests_FaxClass_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 fax = phaxio.CreateFax(); fax.Send(testToNumber, testFile, testOptions); Assert.AreEqual("1234", fax.Id, "FaxId should be the same."); }
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); }
public void UnitTests_AreaCodes_WithState() { Action <IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[0].Value, "ID"); }; var clientBuilder = new IRestClientBuilder { Op = "areaCodes", NoAuth = true, RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var codes = phaxio.ListAreaCodes(state: "ID"); }
public void UnitTests_SupportedCountries() { var clientBuilder = new IRestClientBuilder { Op = "supportedCountries", NoAuth = true }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var countries = phaxio.ListSupportedCountries(); var expectedCountries = PocoFixtures.GetTestSupportedCountries(); Assert.AreEqual(expectedCountries.Count(), countries.Count(), "Number should be the same"); Assert.AreEqual(expectedCountries["Canada"].PricePerPage, countries["Canada"].PricePerPage, "PricePerPage should be the same"); }
public void UnitTests_AccountStatus() { var clientBuilder = new IRestClientBuilder { Op = "accountStatus" }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var account = phaxio.GetAccountStatus(); var expectedAccount = PocoFixtures.GetTestAccount(); Assert.AreEqual(expectedAccount.FaxesSentThisMonth, account.FaxesSentThisMonth, "FaxesSentThisMonth should be the same."); Assert.AreEqual(expectedAccount.FaxesSentToday, account.FaxesSentToday, "FaxesSentThisWeek should be the same."); Assert.AreEqual(expectedAccount.Balance, account.Balance, "Balance should be the same."); }
public void UnitTests_V2_Fax_Create_With_Byte_Arrays_No_File_Names() { var testPdfBytes = BinaryFixtures.GetTestPdf(); var restClient = new RestClientBuilder() .AsJson() .Content(JsonResponseFixtures.FromFile("V2/fax_send")) .Ok() .Build <Response <Fax> >(); var phaxio = new PhaxioClient(RestClientBuilder.TEST_KEY, RestClientBuilder.TEST_SECRET, restClient); Assert.Throws <ArgumentException>( () => { phaxio.Fax.Create(to: "123", byteArrays: new byte[][] { testPdfBytes }); }); }
public void UnitTests_AreaCodes_NoOptions() { var clientBuilder = new IRestClientBuilder { Op = "areaCodes", NoAuth = true }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var codes = phaxio.ListAreaCodes(tollFree: true); var expectedCodes = PocoFixtures.GetTestAreaCodes(); Assert.AreEqual(expectedCodes.Count(), codes.Count(), "Number should be the same"); Assert.AreEqual(expectedCodes["201"].City, codes["201"].City, "City should be the same"); Assert.AreEqual(expectedCodes["201"].State, codes["201"].State, "State should be the same"); }
public void UnitTests_Fax_Resend() { Action <IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[2].Value, "123"); }; var clientBuilder = new IRestClientBuilder { Op = "resendFax", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var result = phaxio.ResendFax("123"); Assert.True(result.Success, "Should be success."); }
public void IntegrationTests_FaxClass_Cancel() { Action <IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[2].Value, "123"); }; var clientBuilder = new IRestClientBuilder { Op = "faxCancel", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var fax = phaxio.CreateFax("123"); var result = fax.Cancel(); Assert.True(result.Success, "Should be success."); }
public ActionResult Index() { string key = Request.Form["key"]; string secret = Request.Form["secret"]; var phaxio = new PhaxioClient(key, secret); var filepath = HostingEnvironment.MapPath("~/App_Data/test.pdf"); var result = phaxio.Fax.TestRecieveCallback(new FileInfo(filepath)); if (!result.Success) { return(Content("Trigger did not work, unfortunately: " + result.Message)); } return(RedirectToAction(nameof(HomeController.Index), "Home")); }
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); }
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("sent", faxInfo.Direction, ""); Assert.AreEqual(3, faxInfo.PageCount, ""); Assert.AreEqual("success", faxInfo.Status, ""); Assert.IsTrue(faxInfo.IsTest, ""); Assert.AreEqual(completedAt, faxInfo.CompletedAt.Value, ""); Assert.AreEqual(21, faxInfo.CostInCents, ""); 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(completedAt, recipient.CompletedAt.Value, ""); Assert.AreEqual("success", recipient.Status, ""); Assert.AreEqual(41, recipient.ErrorId.Value, ""); Assert.AreEqual("recipient_error_type", recipient.ErrorType, ""); Assert.AreEqual("recipient_error_message", recipient.ErrorMessage, ""); }
public void IntegrationTests_V2_PhaxCode_BasicScenario() { var config = new KeyManager(); var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]); var code1 = phaxio.PhaxCode.Create("phil"); Thread.Sleep(1000); var code2 = phaxio.PhaxCode.Retrieve(code1.Identifier); Assert.AreEqual("phil", code2.Metadata); Thread.Sleep(1000); Assert.IsNotEmpty(code2.Png); }
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."); }
public void IntegrationTests_V2_Fax_List() { var config = new KeyManager(); var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]); var testPdf = BinaryFixtures.getTestPdfFile(); var fax = phaxio.Fax.Create(to: "+18088675309", file: testPdf); Assert.NotZero(fax.Id); Thread.Sleep(1000); var faxes = phaxio.Fax.List(); Assert.Greater(faxes.Count(), 0, "There should be some faxes."); }
public void UnitTests_TestRecieveCallback_NoOptions() { var testPdf = BinaryFixtures.getTestPdfFile(); Action<IRestRequest> requestAsserts = req => { Assert.AreEqual(1, req.Files.Count); Assert.AreEqual("filename", req.Files[0].Name); }; var clientBuilder = new IRestClientBuilder { Op = "testReceive", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var result = phaxio.TestRecieveCallback(testPdf); Assert.IsTrue(result.Success, "Result should be Success = true."); }
public void UnitTests_Numbers_Release() { var number = "8088675309"; Action <IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[2].Value, number); }; var clientBuilder = new IRestClientBuilder { Op = "releaseNumber", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var result = phaxio.ReleaseNumber(number); Assert.True(result.Success, "Should be success."); }
public void UnitTests_Numbers_Provision() { var areaCode = "808"; Action<IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[2].Value, areaCode); }; var clientBuilder = new IRestClientBuilder { Op = "provisionNumber", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var actualNumber = phaxio.ProvisionNumber(areaCode); var expectedNumber = PocoFixtures.GetTestPhoneNumber(); Assert.AreEqual(expectedNumber.Number, actualNumber.Number, "Number should be the same"); }
public void IntegrationTests_Numbers_BasicScenario() { if (!canProvision) { return; } var config = new KeyManager(); var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]); // Find area codes to provision a number in var areaCodes = phaxio.ListAreaCodes(state: "DE"); Assert.Greater(areaCodes.Count(), 0, "There should be some area codes"); var areaCode = areaCodes.First(); // Provision a number var provisionedNumber = phaxio.ProvisionNumber(areaCode.Key); // Check to see if the number's listed on the account var accountNumbers = phaxio.ListNumbers(); if (!accountNumbers.Any(n => n.Number == provisionedNumber.Number)) { throw new AssertionException("ListNumbers should return newly provisioned number."); } Thread.Sleep(1000); // Release the number phaxio.ReleaseNumber(provisionedNumber.Number); Thread.Sleep(1000); // Check to see if the number's still listed on the account accountNumbers = phaxio.ListNumbers(); if (accountNumbers.Any(n => n.Number == provisionedNumber.Number)) { throw new AssertionException("ListNumbers should not return released number."); } }
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)); }
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)); }
public void UnitTests_PhaxCode_CreateWithUrlAndOptions() { var metadata = "key=value"; Action<IRestRequest> requestAsserts = req => { var parameters = ParametersHelper.ToDictionary(req.Parameters); Assert.AreEqual(metadata, parameters["metadata"], "y's should be the same."); }; var clientBuilder = new IRestClientBuilder { Op = "createPhaxCodeUrl", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var phaxCodeUrl = phaxio.CreatePhaxCode(metadata); var expectedPhaxCodeUrl = PocoFixtures.GetTestPhaxCodeUrl(); Assert.AreEqual(expectedPhaxCodeUrl, phaxCodeUrl, "URLs should be the same."); }
public void UnitTests_Numbers_Provision() { var areaCode = "808"; Action <IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[2].Value, areaCode); }; var clientBuilder = new IRestClientBuilder { Op = "provisionNumber", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var actualNumber = phaxio.ProvisionNumber(areaCode); var expectedNumber = PocoFixtures.GetTestPhoneNumber(); Assert.AreEqual(expectedNumber.Number, actualNumber.Number, "Number should be the same"); }
public void UnitTests_TestRecieveCallback_NoOptions() { var testPdf = BinaryFixtures.getTestPdfFile(); Action <IRestRequest> requestAsserts = req => { Assert.AreEqual(1, req.Files.Count); Assert.AreEqual("filename", req.Files[0].Name); }; var clientBuilder = new IRestClientBuilder { Op = "testReceive", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var result = phaxio.TestRecieveCallback(testPdf); Assert.IsTrue(result.Success, "Result should be Success = true."); }
public void UnitTests_Numbers_ListNumbersWithOptions() { var areaCode = "808"; var number = "8088675309"; Action<IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[2].Value, areaCode); Assert.AreEqual(req.Parameters[3].Value, number); }; var clientBuilder = new IRestClientBuilder { Op = "numberList", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var actualNumbers = phaxio.ListNumbers(areaCode, number); var expectedNumbers = PocoFixtures.GetTestPhoneNumbers(); Assert.AreEqual(expectedNumbers.Count, actualNumbers.Count, "Number should be the same"); }
static void Main(string[] args) { var parser = new FileIniDataParser(); IniData config = parser.ReadFile(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "keys.ini"); var phaxio = new PhaxioClient(config["Phaxio"]["api_key"], config["Phaxio"]["api_secret"]); //var account = phaxio.GetAccountStatus(); //Console.WriteLine(account.Balance); var pdf = new FileInfo("C:\\temp\\test.pdf"); var faxId = phaxio.Fax.Create(to: "+18088675309", file: pdf); Console.WriteLine(faxId); Console.ReadKey(); }
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); }
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); }
public void IntegrationTests_Numbers_BasicScenario() { var config = new KeyManager(); var phaxio = new PhaxioClient(config["api_key"], config["api_secret"]); // Find area codes to provision a number in var areaCodes = phaxio.ListAreaCodes(state: "DE"); Assert.Greater(areaCodes.Count(), 0, "There should be some area codes"); var areaCode = areaCodes.First(); // Provision a number var provisionedNumber = phaxio.ProvisionNumber(areaCode.Key); // Check to see if the number's listed on the account var accountNumbers = phaxio.ListNumbers(); if (!accountNumbers.Any(n => n.Number == provisionedNumber.Number)) { throw new AssertionException("ListNumbers should return newly provisioned number."); } Thread.Sleep(1000); // Release the number phaxio.ReleaseNumber(provisionedNumber.Number); Thread.Sleep(1000); // Check to see if the number's still listed on the account accountNumbers = phaxio.ListNumbers(); if (accountNumbers.Any(n => n.Number == provisionedNumber.Number)) { throw new AssertionException("ListNumbers should not return released number."); } }
public void IntegrationTests_FaxClass_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 fax = phaxio.CreateFax(); fax.Send(testToNumber, testFile); Assert.AreEqual("1234", fax.Id, "FaxId should be the same."); }
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); }
public void UnitTests_Numbers_ListNumbersWithOptions() { var areaCode = "808"; var number = "8088675309"; Action <IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[2].Value, areaCode); Assert.AreEqual(req.Parameters[3].Value, number); }; var clientBuilder = new IRestClientBuilder { Op = "numberList", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var actualNumbers = phaxio.ListNumbers(areaCode, number); var expectedNumbers = PocoFixtures.GetTestPhoneNumbers(); Assert.AreEqual(expectedNumbers.Count, actualNumbers.Count, "Number should be the same"); }
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."); }
public void UnitTests_PhaxCode_CreateWithUrlAndOptions() { var metadata = "key=value"; Action <IRestRequest> requestAsserts = req => { var parameters = ParametersHelper.ToDictionary(req.Parameters); Assert.AreEqual(metadata, parameters["metadata"], "y's should be the same."); }; var clientBuilder = new IRestClientBuilder { Op = "createPhaxCodeUrl", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var phaxCodeUrl = phaxio.CreatePhaxCode(metadata); var expectedPhaxCodeUrl = PocoFixtures.GetTestPhaxCodeUrl(); Assert.AreEqual(expectedPhaxCodeUrl, phaxCodeUrl, "URLs should be the same."); }
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(); }
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(); }
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(); }
public void UnitTests_Numbers_Release() { var number = "8088675309"; Action<IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[2].Value, number); }; var clientBuilder = new IRestClientBuilder { Op = "releaseNumber", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var result = phaxio.ReleaseNumber(number); Assert.True(result.Success, "Should be success."); }