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 IntegrationTests_FaxClass_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 fax = phaxio.CreateFax("1234"); var pdfBytes = fax.DownloadFile("l"); Assert.IsNotEmpty(pdfBytes); var expectedPdf = BinaryFixtures.GetTestPdf(); Assert.AreEqual(expectedPdf, pdfBytes, "PDFs should be the same."); }
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_FaxClass_SendMultipleFilesNoOptions() { var testToNumber = "8088675309"; Action <IRestRequest> requestAsserts = req => { var parameters = ParametersHelper.ToDictionary(req.Parameters); Assert.AreEqual(testToNumber, parameters["to[]"]); Assert.AreEqual(3, parameters.Count()); Assert.AreEqual(2, req.Files.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 fax = phaxio.CreateFax(); fax.Send(testToNumber, new List <FileInfo> { testFile, testFile }); Assert.AreEqual("1234", fax.Id, "FaxId should be the same."); }
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_PhaxCode_AttachNoOptions() { var testPdf = BinaryFixtures.getTestPdfFile(); Action <IRestRequest> requestAsserts = req => { Assert.AreEqual(1, req.Files.Count); Assert.AreEqual("filename", req.Files[0].Name); var parameters = ParametersHelper.ToDictionary(req.Parameters); Assert.AreEqual(1, parameters["x"], "x's should be the same."); Assert.AreEqual(2, parameters["y"], "y's should be the same."); }; var clientBuilder = new IRestClientBuilder { Op = "attachPhaxCodeToPdf", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.BuildUntyped()); var pdfBytes = phaxio.AttachPhaxCodeToPdf(1, 2, testPdf); Assert.IsNotEmpty(pdfBytes); var expectedPdf = BinaryFixtures.GetTestPdf(); Assert.AreEqual(expectedPdf, pdfBytes, "PDFs should be the same."); }
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_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."); }
static async Task Test(IRestClientBuilder builder) { var client = builder .WithSerializer(new JsonSerializer()) //.WithExtenders(new ) .Build(); var response = await client.PostAsync <Request, Response>(new Uri(""), new Request()); }
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 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 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_FaxClass_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 fax = phaxio.CreateFax(); fax.Send(testToNumber, testFile, testOptions); Assert.AreEqual("1234", fax.Id, "FaxId 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 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 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_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_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 IntegrationTests_FaxClass_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 fax = phaxio.CreateFax("123"); var result = fax.Resend(); Assert.True(result.Success, "Should be success."); }
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 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_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_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_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_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 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_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 IntegrationTests_FaxClass_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 fax = phaxio.CreateFax(); fax.Send(testToNumber, testFile, testOptions); Assert.AreEqual("1234", fax.Id, "FaxId should be the same."); }
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 IntegrationTests_FaxClass_Delete() { Action<IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[2].Value, "123"); Assert.AreEqual(req.Parameters[3].Value, false); }; var clientBuilder = new IRestClientBuilder { Op = "deleteFax", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var fax = phaxio.CreateFax("123"); var result = fax.Delete(); Assert.True(result.Success, "Should be success."); }
public void UnitTests_PhaxCode_AttachNoOptions() { var testPdf = BinaryFixtures.getTestPdfFile(); Action<IRestRequest> requestAsserts = req => { Assert.AreEqual(1, req.Files.Count); Assert.AreEqual("filename", req.Files[0].Name); var parameters = ParametersHelper.ToDictionary(req.Parameters); Assert.AreEqual(1, parameters["x"], "x's should be the same."); Assert.AreEqual(2, parameters["y"], "y's should be the same."); }; var clientBuilder = new IRestClientBuilder { Op = "attachPhaxCodeToPdf", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.BuildUntyped()); var pdfBytes = phaxio.AttachPhaxCodeToPdf(1, 2, testPdf); Assert.IsNotEmpty(pdfBytes); var expectedPdf = BinaryFixtures.GetTestPdf(); Assert.AreEqual(expectedPdf, pdfBytes, "PDFs should be the same."); }
public RestBuilderTests() { builder = new RestClientBuilder(); }
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."); }
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."); }
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."); }
public void UnitTests_Fax_DeleteWithOptions() { Action<IRestRequest> requestAsserts = req => { Assert.AreEqual(req.Parameters[2].Value, "123"); Assert.AreEqual(req.Parameters[3].Value, true); }; var clientBuilder = new IRestClientBuilder { Op = "deleteFax", RequestAsserts = requestAsserts }; var phaxio = new PhaxioClient(IRestClientBuilder.TEST_KEY, IRestClientBuilder.TEST_SECRET, clientBuilder.Build()); var result = phaxio.DeleteFax("123", true); Assert.True(result.Success, "Should be success."); }
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."); }