From 8a83ad2b5f9360c0cf641ba30b412820873f47de Mon Sep 17 00:00:00 2001 From: lvukadinovic-ib Date: Thu, 7 Nov 2024 17:22:43 +0100 Subject: [PATCH] Applied resharper. --- ApiClient.Tests/Api/ApiTest.cs | 385 ++-- ApiClient.Tests/Api/EmailApiTest.cs | 1763 +++++++++--------- ApiClient.Tests/Api/SmsApiTest.cs | 1515 +++++++-------- ApiClient.Tests/Api/TfaApiTest.cs | 1571 ++++++++-------- ApiClient.Tests/ApiExceptionTest.cs | 133 +- ApiClient.Tests/DateTimeSerializationTest.cs | 129 +- ApiClient.Tests/GeneralSetupTest.cs | 61 +- 7 files changed, 2853 insertions(+), 2704 deletions(-) diff --git a/ApiClient.Tests/Api/ApiTest.cs b/ApiClient.Tests/Api/ApiTest.cs index 3659481..8f42536 100644 --- a/ApiClient.Tests/Api/ApiTest.cs +++ b/ApiClient.Tests/Api/ApiTest.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; using System.Net; using Infobip.Api.Client; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -10,241 +7,247 @@ using WireMock.Server; using WireMock.Types; -namespace ApiClient.Tests.Api +namespace ApiClient.Tests.Api; + +public class ApiTest { - public class ApiTest + protected const string API_KEY_PREFIX = "App"; + protected const string API_KEY = "003026bbc133714df1834b8638bb496e-8f4b3d9a-e931-478d-a994-28a725159ab9"; + protected const string API_KEY_HEADER_VALUE = API_KEY_PREFIX + " " + API_KEY; + protected const string CONTENT_TYPE_HEADER_VALUE = "application/json; charset=utf-8"; + protected const string USER_AGENT_HEADER_VALUE = "infobip-api-client-csharp/" + Configuration.Version; + protected const string ACCEPT_HEADER_VALUE = "application/json"; + protected const string SERVER_HEADER_VALUE = "SMS API"; + protected const string SERVER_HEADER_VALUE_COMMA = "SMS,API"; + protected const string X_REQUEST_ID_HEADER_VALUE = "1608758729810312842"; + + protected Configuration? configuration; + + protected WireMockServer? wireMockServer; + + [TestInitialize] + public void StartMockServer() { - protected const string API_KEY_PREFIX = "App"; - protected const string API_KEY = "003026bbc133714df1834b8638bb496e-8f4b3d9a-e931-478d-a994-28a725159ab9"; - protected const string API_KEY_HEADER_VALUE = API_KEY_PREFIX + " " + API_KEY; - protected const string CONTENT_TYPE_HEADER_VALUE = "application/json; charset=utf-8"; - protected const string USER_AGENT_HEADER_VALUE = "infobip-api-client-csharp/" + Configuration.Version; - protected const string ACCEPT_HEADER_VALUE = "application/json"; - protected const string SERVER_HEADER_VALUE = "SMS API"; - protected const string SERVER_HEADER_VALUE_COMMA = "SMS,API"; - protected const string X_REQUEST_ID_HEADER_VALUE = "1608758729810312842"; - - protected Configuration? configuration; - - protected WireMockServer? wireMockServer; + wireMockServer = WireMockServer.Start(); - [TestInitialize] - public void StartMockServer() + configuration = new Configuration { - wireMockServer = WireMockServer.Start(); - - configuration = new Configuration - { - ApiKey = API_KEY, - BasePath = "http://localhost:" + wireMockServer.Ports[0] - }; - } + ApiKey = API_KEY, + BasePath = "http://localhost:" + wireMockServer.Ports[0] + }; + } - [TestCleanup] - public void TearDown() - { - wireMockServer!.Stop(); - } + [TestCleanup] + public void TearDown() + { + wireMockServer!.Stop(); + } - protected void SetUpGetRequest(string url, string expectedResponse, int statusCode) - { - SetUpGetRequest(url, new Dictionary(), expectedResponse, statusCode); - } + protected void SetUpGetRequest(string url, string expectedResponse, int statusCode) + { + SetUpGetRequest(url, new Dictionary(), expectedResponse, statusCode); + } - protected void SetUpPostRequest(string url, string givenRequest, string expectedResponse, int statusCode) - { - SetUpPostRequest(url, new Dictionary(), givenRequest, expectedResponse, statusCode); - } + protected void SetUpPostRequest(string url, string givenRequest, string expectedResponse, int statusCode) + { + SetUpPostRequest(url, new Dictionary(), givenRequest, expectedResponse, statusCode); + } - protected void SetUpPutRequest(string url, string givenRequest, string expectedResponse, int statusCode) - { - SetUpPutRequest(url, new Dictionary(), givenRequest, expectedResponse, statusCode); - } + protected void SetUpPutRequest(string url, string givenRequest, string expectedResponse, int statusCode) + { + SetUpPutRequest(url, new Dictionary(), givenRequest, expectedResponse, statusCode); + } - protected void SetUpDeleteRequest(string url, int statusCode) - { - SetUpDeleteRequest(url, new Dictionary(), statusCode); - } + protected void SetUpDeleteRequest(string url, int statusCode) + { + SetUpDeleteRequest(url, new Dictionary(), statusCode); + } - protected void SetUpGetRequest(string url, Dictionary givenParameters, string expectedResponse, int statusCode) - { - wireMockServer!.Given(Request.Create().UsingGet().WithPath(url) + protected void SetUpGetRequest(string url, Dictionary givenParameters, string expectedResponse, + int statusCode) + { + wireMockServer!.Given(Request.Create().UsingGet().WithPath(url) .WithHeader("Authorization", new ExactMatcher(API_KEY_HEADER_VALUE)) .WithHeader("Accept", new ExactMatcher(ACCEPT_HEADER_VALUE)) .WithHeader("User-Agent", new ExactMatcher(USER_AGENT_HEADER_VALUE)) .WithParam(EqualToParams(givenParameters)) - ) - .RespondWith(Response.Create() - .WithStatusCode(statusCode) - .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) - .WithHeader("Server", SERVER_HEADER_VALUE) - .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) - .WithBody(expectedResponse) - ); - } - - protected void SetUpPostRequest(string url, Dictionary givenParameters, string givenRequest, string expectedResponse, int statusCode) - { - wireMockServer!.Given(Request.Create().UsingPost().WithPath(url) + ) + .RespondWith(Response.Create() + .WithStatusCode(statusCode) + .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) + .WithHeader("Server", SERVER_HEADER_VALUE) + .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) + .WithBody(expectedResponse) + ); + } + + protected void SetUpPostRequest(string url, Dictionary givenParameters, string givenRequest, + string expectedResponse, int statusCode) + { + wireMockServer!.Given(Request.Create().UsingPost().WithPath(url) .WithHeader("Authorization", new ExactMatcher(API_KEY_HEADER_VALUE)) .WithHeader("Content-Type", new ExactMatcher(CONTENT_TYPE_HEADER_VALUE)) .WithHeader("Accept", new ExactMatcher(ACCEPT_HEADER_VALUE)) .WithHeader("User-Agent", new ExactMatcher(USER_AGENT_HEADER_VALUE)) .WithParam(EqualToParams(givenParameters)) - .WithBody(new JsonMatcher(givenRequest, true, false)) - ) - .RespondWith(Response.Create() - .WithStatusCode(statusCode) - .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) - .WithHeader("Server", SERVER_HEADER_VALUE) - .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) - .WithBody(expectedResponse) - ); - } - - protected void SetUpPostRequestBinary(string url, Dictionary givenParameters, byte[] givenRequest, string expectedResponse, int statusCode) - { - wireMockServer!.Given(Request.Create().UsingPost().WithPath(url) + .WithBody(new JsonMatcher(givenRequest, true)) + ) + .RespondWith(Response.Create() + .WithStatusCode(statusCode) + .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) + .WithHeader("Server", SERVER_HEADER_VALUE) + .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) + .WithBody(expectedResponse) + ); + } + + protected void SetUpPostRequestBinary(string url, Dictionary givenParameters, byte[] givenRequest, + string expectedResponse, int statusCode) + { + wireMockServer!.Given(Request.Create().UsingPost().WithPath(url) .WithHeader("Authorization", new ExactMatcher(API_KEY_HEADER_VALUE)) .WithHeader("Content-Type", new ExactMatcher("application/octet-stream")) .WithHeader("Accept", new ExactMatcher(ACCEPT_HEADER_VALUE)) .WithHeader("User-Agent", new ExactMatcher(USER_AGENT_HEADER_VALUE)) .WithParam(EqualToParams(givenParameters)) .WithBody(givenRequest) - ) - .RespondWith(Response.Create() - .WithStatusCode(statusCode) - .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) - .WithHeader("Server", SERVER_HEADER_VALUE) - .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) - .WithBody(expectedResponse) - ); - } - - protected void SetUpNoRequestBodyNoResponseBodyPostRequest(string url, int statusCode) - { - wireMockServer!.Given(Request.Create().UsingPost().WithPath(url) + ) + .RespondWith(Response.Create() + .WithStatusCode(statusCode) + .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) + .WithHeader("Server", SERVER_HEADER_VALUE) + .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) + .WithBody(expectedResponse) + ); + } + + protected void SetUpNoRequestBodyNoResponseBodyPostRequest(string url, int statusCode) + { + wireMockServer!.Given(Request.Create().UsingPost().WithPath(url) .WithHeader("Authorization", new ExactMatcher(API_KEY_HEADER_VALUE)) .WithHeader("Accept", new ExactMatcher(ACCEPT_HEADER_VALUE)) .WithHeader("User-Agent", new ExactMatcher(USER_AGENT_HEADER_VALUE)) - ) - .RespondWith(Response.Create() - .WithStatusCode(statusCode) - .WithHeader("Server", SERVER_HEADER_VALUE) - .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) - ); - } - - protected void SetUpPutRequest(string url, Dictionary givenParameters, string givenRequest, string expectedResponse, int statusCode) - { - wireMockServer!.Given(Request.Create().UsingPut().WithPath(url) + ) + .RespondWith(Response.Create() + .WithStatusCode(statusCode) + .WithHeader("Server", SERVER_HEADER_VALUE) + .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) + ); + } + + protected void SetUpPutRequest(string url, Dictionary givenParameters, string givenRequest, + string expectedResponse, int statusCode) + { + wireMockServer!.Given(Request.Create().UsingPut().WithPath(url) .WithHeader("Authorization", new ExactMatcher(API_KEY_HEADER_VALUE)) .WithHeader("Content-Type", new ExactMatcher(CONTENT_TYPE_HEADER_VALUE)) .WithHeader("Accept", new ExactMatcher(ACCEPT_HEADER_VALUE)) .WithHeader("User-Agent", new ExactMatcher(USER_AGENT_HEADER_VALUE)) .WithParam(EqualToParams(givenParameters)) - .WithBody(new JsonMatcher(givenRequest, true, false)) - ) - .RespondWith(Response.Create() - .WithStatusCode(statusCode) - .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) - .WithHeader("Server", SERVER_HEADER_VALUE) - .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) - .WithBody(expectedResponse) - ); - } - - protected void SetUpDeleteRequest(string url, Dictionary givenParameters, int statusCode) - { - wireMockServer!.Given(Request.Create().UsingDelete().WithPath(url) + .WithBody(new JsonMatcher(givenRequest, true)) + ) + .RespondWith(Response.Create() + .WithStatusCode(statusCode) + .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) + .WithHeader("Server", SERVER_HEADER_VALUE) + .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) + .WithBody(expectedResponse) + ); + } + + protected void SetUpDeleteRequest(string url, Dictionary givenParameters, int statusCode) + { + wireMockServer!.Given(Request.Create().UsingDelete().WithPath(url) .WithHeader("Authorization", new ExactMatcher(API_KEY_HEADER_VALUE)) .WithHeader("Accept", new ExactMatcher(ACCEPT_HEADER_VALUE)) .WithParam(EqualToParams(givenParameters)) - ) - .RespondWith(Response.Create() - .WithStatusCode(statusCode) - .WithHeader("Server", SERVER_HEADER_VALUE) - .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) - ); - } - - protected void SetUpDeleteRequestWithResponseBody(string url, Dictionary givenParameters, string expectedResponse, int statusCode) - { - wireMockServer!.Given(Request.Create().UsingDelete().WithPath(url) + ) + .RespondWith(Response.Create() + .WithStatusCode(statusCode) + .WithHeader("Server", SERVER_HEADER_VALUE) + .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) + ); + } + + protected void SetUpDeleteRequestWithResponseBody(string url, Dictionary givenParameters, + string expectedResponse, int statusCode) + { + wireMockServer!.Given(Request.Create().UsingDelete().WithPath(url) .WithHeader("Authorization", new ExactMatcher(API_KEY_HEADER_VALUE)) .WithHeader("Accept", new ExactMatcher(ACCEPT_HEADER_VALUE)) .WithParam(EqualToParams(givenParameters)) - ) - .RespondWith(Response.Create() - .WithStatusCode(statusCode) - .WithHeader("Server", SERVER_HEADER_VALUE) - .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) - .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) - .WithBody(expectedResponse) - ); - } - - protected void SetUpMultipartFormRequest(string url, Multimap givenParts, string expectedResponse, int statusCode = 200) - { - var req = Request.Create().UsingPost().WithPath(url) - .WithHeader("Authorization", new ExactMatcher(API_KEY_HEADER_VALUE)) - .WithHeader("Content-Type", new WildcardMatcher("multipart/form-data; boundary=\"---------*", true)) - .WithHeader("Accept", new ExactMatcher(ACCEPT_HEADER_VALUE)) - .WithHeader("User-Agent", new ExactMatcher(USER_AGENT_HEADER_VALUE)); + ) + .RespondWith(Response.Create() + .WithStatusCode(statusCode) + .WithHeader("Server", SERVER_HEADER_VALUE) + .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) + .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) + .WithBody(expectedResponse) + ); + } - req.WithBody((body) => + protected void SetUpMultipartFormRequest(string url, Multimap givenParts, string expectedResponse, + int statusCode = 200) + { + var req = Request.Create().UsingPost().WithPath(url) + .WithHeader("Authorization", new ExactMatcher(API_KEY_HEADER_VALUE)) + .WithHeader("Content-Type", new WildcardMatcher("multipart/form-data; boundary=\"---------*", true)) + .WithHeader("Accept", new ExactMatcher(ACCEPT_HEADER_VALUE)) + .WithHeader("User-Agent", new ExactMatcher(USER_AGENT_HEADER_VALUE)); + + req.WithBody(body => + { + var allKeysFound = givenParts.All(kvp => + body.Contains($"name={kvp.Key}", StringComparison.InvariantCultureIgnoreCase)); + var allValuesFound = givenParts.All(kvp => + kvp.Value.All(value => body.Contains(value, StringComparison.InvariantCultureIgnoreCase))); + return allValuesFound && allKeysFound; + }); + + var resp = Response.Create() + .WithStatusCode(statusCode) + .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) + .WithHeader("Server", SERVER_HEADER_VALUE) + .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) + .WithBody(expectedResponse); + + wireMockServer!.Given(req).RespondWith(resp); + } + + private Func>, bool>[] EqualToParams(Dictionary parameters) + { + var funcs = new List>, bool>>(); + foreach (var param in parameters) + funcs.Add(delegate(IDictionary> inputParams) { - var allKeysFound = givenParts.All(kvp => body.Contains($"name={kvp.Key}", StringComparison.InvariantCultureIgnoreCase)); - var allValuesFound = givenParts.All(kvp => kvp.Value.All(value => body.Contains(value, StringComparison.InvariantCultureIgnoreCase))); - return allValuesFound && allKeysFound; + return inputParams[param.Key][0] == param.Value; }); + if (funcs.Count == 0) funcs.Add(x => true); + return funcs.ToArray(); + } - var resp = Response.Create() - .WithStatusCode(statusCode) - .WithHeader("Content-Type", CONTENT_TYPE_HEADER_VALUE) - .WithHeader("Server", SERVER_HEADER_VALUE) - .WithHeader("X-Request-Id", X_REQUEST_ID_HEADER_VALUE) - .WithBody(expectedResponse); - - wireMockServer!.Given(req).RespondWith(resp); - } - - private Func>, bool>[] EqualToParams(Dictionary parameters) - { - var funcs = new List>, bool>>(); - foreach (var param in parameters) - { - funcs.Add(delegate (IDictionary> inputParams) - { - return inputParams[param.Key][0] == param.Value; - }); - } - if (funcs.Count == 0) funcs.Add(x => true); - return funcs.ToArray(); - } - - public static void AssertResponse(T apiResponse, Action assertion) - { - assertion.Invoke(apiResponse); - } + public static void AssertResponse(T apiResponse, Action assertion) + { + assertion.Invoke(apiResponse); + } - public static void AssertResponseWithHttpInfo(ApiResponse apiResponse, Action assertion) - { - Assert.AreEqual(HttpStatusCode.OK, apiResponse.StatusCode); + public static void AssertResponseWithHttpInfo(ApiResponse apiResponse, Action assertion) + { + Assert.AreEqual(HttpStatusCode.OK, apiResponse.StatusCode); - Assert.AreEqual(SERVER_HEADER_VALUE_COMMA, apiResponse.Headers["Server"][0]); - Assert.AreEqual(X_REQUEST_ID_HEADER_VALUE, apiResponse.Headers["X-Request-ID"][0]); - Assert.AreEqual(CONTENT_TYPE_HEADER_VALUE, apiResponse.Headers["Content-Type"][0]); + Assert.AreEqual(SERVER_HEADER_VALUE_COMMA, apiResponse.Headers["Server"][0]); + Assert.AreEqual(X_REQUEST_ID_HEADER_VALUE, apiResponse.Headers["X-Request-ID"][0]); + Assert.AreEqual(CONTENT_TYPE_HEADER_VALUE, apiResponse.Headers["Content-Type"][0]); - assertion.Invoke(apiResponse.Data); - } + assertion.Invoke(apiResponse.Data); + } - public static void AssertNoBodyResponseWithHttpInfo(ApiResponse apiResponse, HttpStatusCode expectedHttpStatusCode) - { - Assert.AreEqual(expectedHttpStatusCode, apiResponse.StatusCode); + public static void AssertNoBodyResponseWithHttpInfo(ApiResponse apiResponse, + HttpStatusCode expectedHttpStatusCode) + { + Assert.AreEqual(expectedHttpStatusCode, apiResponse.StatusCode); - Assert.AreEqual(SERVER_HEADER_VALUE_COMMA, apiResponse.Headers["Server"][0]); - Assert.AreEqual(X_REQUEST_ID_HEADER_VALUE, apiResponse.Headers["X-Request-ID"][0]); - } + Assert.AreEqual(SERVER_HEADER_VALUE_COMMA, apiResponse.Headers["Server"][0]); + Assert.AreEqual(X_REQUEST_ID_HEADER_VALUE, apiResponse.Headers["X-Request-ID"][0]); } } \ No newline at end of file diff --git a/ApiClient.Tests/Api/EmailApiTest.cs b/ApiClient.Tests/Api/EmailApiTest.cs index 7689640..8149546 100644 --- a/ApiClient.Tests/Api/EmailApiTest.cs +++ b/ApiClient.Tests/Api/EmailApiTest.cs @@ -1,75 +1,73 @@ -using Infobip.Api.Client; +using System.Globalization; +using System.Net; +using System.Text; +using Infobip.Api.Client; using Infobip.Api.Client.Api; +using Infobip.Api.Client.Client; using Infobip.Api.Client.Model; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Net; -using System.Text; using static Infobip.Api.Client.Model.EmailAddDomainRequest; -namespace ApiClient.Tests.Api +namespace ApiClient.Tests.Api; + +[TestClass] +public class EmailApiTest : ApiTest { - [TestClass] - public class EmailApiTest : ApiTest + protected const string EMAIL_SEND_FULLY_FEATURED_ENDPOINT = "/email/3/send"; + protected const string EMAIL_VALIDATE_ADDRESSES_ENDPOINT = "/email/2/validation"; + protected const string EMAIL_LOGS_ENDPOINT = "/email/1/reports"; + protected const string EMAIL_REPORTS_ENDPOINT = "/email/1/logs"; + protected const string EMAIL_BULKS_ENDPOINT = "/email/1/bulks"; + protected const string EMAIL_BULKS_STATUS_ENDPOINT = "/email/1/bulks/status"; + + protected const string EMAIL_DOMAINS = "/email/1/domains"; + protected const string EMAIL_DOMAIN = "/email/1/domains/{domainName}"; + protected const string EMAIL_DOMAIN_TRACKING = "/email/1/domains/{domainName}/tracking"; + protected const string EMAIL_DOMAIN_RETURN_PATH = "/email/1/domains/{domainName}/return-path"; + protected const string EMAIL_DOMAIN_VERIFY = "/email/1/domains/{domainName}/verify"; + protected const string EMAIL_IPS = "/email/1/ips"; + protected const string EMAIL_DOMAIN_IPS = "/email/1/domain-ips"; + + protected const string DATE_FORMAT = "yyyy-MM-ddTHH:mm:ss.fffzzz"; + + internal static readonly Tuple[] ErrorResponses = { - protected const string EMAIL_SEND_FULLY_FEATURED_ENDPOINT = "/email/3/send"; - protected const string EMAIL_VALIDATE_ADDRESSES_ENDPOINT = "/email/2/validation"; - protected const string EMAIL_LOGS_ENDPOINT = "/email/1/reports"; - protected const string EMAIL_REPORTS_ENDPOINT = "/email/1/logs"; - protected const string EMAIL_BULKS_ENDPOINT = "/email/1/bulks"; - protected const string EMAIL_BULKS_STATUS_ENDPOINT = "/email/1/bulks/status"; - - protected const string EMAIL_DOMAINS = "/email/1/domains"; - protected const string EMAIL_DOMAIN = "/email/1/domains/{domainName}"; - protected const string EMAIL_DOMAIN_TRACKING = "/email/1/domains/{domainName}/tracking"; - protected const string EMAIL_DOMAIN_RETURN_PATH = "/email/1/domains/{domainName}/return-path"; - protected const string EMAIL_DOMAIN_VERIFY = "/email/1/domains/{domainName}/verify"; - protected const string EMAIL_IPS = "/email/1/ips"; - protected const string EMAIL_DOMAIN_IPS = "/email/1/domain-ips"; - - protected const string DATE_FORMAT = "yyyy-MM-ddTHH:mm:ss.fffzzz"; - - internal static readonly Tuple[] ErrorResponses = - { - Tuple.Create(400, "BAD_REQUEST", "Bad Request", "[subject : may not be null]"), - Tuple.Create(500, "GENERAL_ERROR", "Internal Server Error", "Something went wrong. Please contact support."), - }; + Tuple.Create(400, "BAD_REQUEST", "Bad Request", "[subject : may not be null]"), + Tuple.Create(500, "GENERAL_ERROR", "Internal Server Error", "Something went wrong. Please contact support.") + }; - internal static readonly Tuple[] DeliveryReportErrorResponses = - { - Tuple.Create(400, "BAD_REQUEST", "Bad Request", "request.message.content.media.file.url: [is not a valid url]"), - Tuple.Create(500, "BAD_REQUEST", "Internal Server Error", "request.message.content.media.file.url: [is not a valid url]"), - }; + internal static readonly Tuple[] DeliveryReportErrorResponses = + { + Tuple.Create(400, "BAD_REQUEST", "Bad Request", "request.message.content.media.file.url: [is not a valid url]"), + Tuple.Create(500, "BAD_REQUEST", "Internal Server Error", + "request.message.content.media.file.url: [is not a valid url]") + }; - [TestMethod] - public void ShouldSendEmailTest() - { - string expectedFrom = "Jane Doe parts = new Multimap - { - { "from", expectedFrom }, - { "to", expectedTo }, - { "to", expectedTo2 }, - { "cc", expectedCc }, - { "cc", expectedCc2 }, - { "bcc", expectedBcc }, - { "bcc", expectedBcc2 }, - { "text", expectedText }, - { "html", expectedHtml }, - { "replyTo", expectedReplyTo }, - { "subject", expectedSubject } - }; - - SetUpMultipartFormRequest(EMAIL_SEND_FULLY_FEATURED_ENDPOINT, parts, expectedResponse); - - var sendEmailApi = new EmailApi(configuration); - - var expectedToList = new List - { - expectedTo, - expectedTo2 - }; - - var expectedCcList = new List - { - expectedCc, - expectedCc2 - }; - - var expectedBccList = new List - { - expectedBcc, - expectedBcc2 - }; - - var response = sendEmailApi.SendEmail( - from: expectedFrom, - to: expectedToList, - subject: expectedSubject, - cc: expectedCcList, - bcc: expectedBccList, - text: expectedText, - bulkId: expectedBulkId, - messageId: expectedMessageId, - html: expectedHtml, - replyTo: expectedReplyTo - ); - - Assert.AreEqual(expectedMessageCount, response.Messages.Count); - Assert.AreEqual(expectedMessageId, response.Messages[0].MessageId); - Assert.AreEqual(expectedTo, response.Messages[0].To); - Assert.AreEqual(expectedStatusId, response.Messages[0].Status.Id); - Assert.AreEqual(expectedStatusName, response.Messages[0].Status.Name); - Assert.AreEqual(expectedStatusGroupId, response.Messages[0].Status.GroupId); - Assert.AreEqual(expectedStatusDescription, response.Messages[0].Status.Description); - Assert.AreEqual(expectedStatusGroupId, response.Messages[0].Status.GroupId); - Assert.AreEqual(expectedMessageId2, response.Messages[1].MessageId); - Assert.AreEqual(expectedTo2, response.Messages[1].To); - Assert.AreEqual(expectedStatusId, response.Messages[1].Status.Id); - Assert.AreEqual(expectedStatusName, response.Messages[1].Status.Name); - Assert.AreEqual(expectedStatusGroupId, response.Messages[1].Status.GroupId); - Assert.AreEqual(expectedStatusDescription, response.Messages[1].Status.Description); - Assert.AreEqual(expectedStatusGroupId, response.Messages[1].Status.GroupId); - } + var parts = new Multimap + { + { "from", expectedFrom }, + { "to", expectedTo }, + { "to", expectedTo2 }, + { "cc", expectedCc }, + { "cc", expectedCc2 }, + { "bcc", expectedBcc }, + { "bcc", expectedBcc2 }, + { "text", expectedText }, + { "html", expectedHtml }, + { "replyTo", expectedReplyTo }, + { "subject", expectedSubject } + }; + + SetUpMultipartFormRequest(EMAIL_SEND_FULLY_FEATURED_ENDPOINT, parts, expectedResponse); + + var sendEmailApi = new EmailApi(configuration); + + var expectedToList = new List + { + expectedTo, + expectedTo2 + }; + + var expectedCcList = new List + { + expectedCc, + expectedCc2 + }; - [TestMethod] - public void ShouldSendEmailWithAttachmentTest() + var expectedBccList = new List { - string expectedFrom = "Jane Doe parts = new Multimap - { - { "from", expectedFrom }, - { "to", expectedTo }, - { "text", expectedText }, - { "html", expectedHtml }, - { "replyTo", expectedReplyTo }, - { "subject", expectedSubject }, - { "attachment", expectedAttachmentText }, - { "attachment", expectedAttachmentText2 } - }; - - SetUpMultipartFormRequest(EMAIL_SEND_FULLY_FEATURED_ENDPOINT, parts, expectedResponse); - - var sendEmailApi = new EmailApi(configuration); - - var expectedToList = new List - { - expectedTo - }; - - var attachmentList = new List - { - attachmentStream, - attachmentStream2 - }; - - var response = sendEmailApi.SendEmail( - from: expectedFrom, - to: expectedToList, - subject: expectedSubject, - text: expectedText, - bulkId: expectedBulkId, - messageId: expectedMessageId, - attachment: attachmentList, - html: expectedHtml, - replyTo: expectedReplyTo - ); - - Assert.AreEqual(expectedMessageCount, response.Messages.Count); - Assert.AreEqual(expectedMessageId, response.Messages[0].MessageId); - Assert.AreEqual(expectedTo, response.Messages[0].To); - Assert.AreEqual(expectedStatusId, response.Messages[0].Status.Id); - Assert.AreEqual(expectedStatusName, response.Messages[0].Status.Name); - Assert.AreEqual(expectedStatusGroupId, response.Messages[0].Status.GroupId); - Assert.AreEqual(expectedStatusDescription, response.Messages[0].Status.Description); - Assert.AreEqual(expectedStatusGroupId, response.Messages[0].Status.GroupId); - } + var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(expectedAttachmentText)); + var attachmentStream = new FileParameter(memoryStream); + + var memoryStream2 = new MemoryStream(Encoding.UTF8.GetBytes(expectedAttachmentText2)); + var attachmentStream2 = new FileParameter(memoryStream2); + + var parts = new Multimap + { + { "from", expectedFrom }, + { "to", expectedTo }, + { "text", expectedText }, + { "html", expectedHtml }, + { "replyTo", expectedReplyTo }, + { "subject", expectedSubject }, + { "attachment", expectedAttachmentText }, + { "attachment", expectedAttachmentText2 } + }; + + SetUpMultipartFormRequest(EMAIL_SEND_FULLY_FEATURED_ENDPOINT, parts, expectedResponse); - [TestMethod] - public void ShouldGetEmailDeliveryReportsTest() + var sendEmailApi = new EmailApi(configuration); + + var expectedToList = new List + { + expectedTo + }; + + var attachmentList = new List { - string expectedTo = "john.smith@somedomain.com"; - int expectedMessageCount = 1; - string expectedMessageId = "MSG-1234"; - string expectedBulkId = "BULK-1234"; - DateTimeOffset expectedSentAt = new DateTimeOffset(2021, 9, 2, 9, 57, 56, TimeSpan.FromHours(0)); - DateTimeOffset expectedDoneAt = new DateTimeOffset(2021, 9, 2, 9, 58, 33, TimeSpan.FromHours(0)); - string expectedCurrency = "EUR"; - decimal expectedPricePerMessage = 0.0M; - string expectedStatusName = "DELIVERED_TO_HANDSET"; - int expectedStatusId = 5; - string expectedStatusDescription = "Message delivered to handset"; - int expectedStatusGroupId = 3; - string expectedStatusGroupName = "DELIVERED"; - string expectedErrorName = "NO_ERROR"; - int expectedErrorId = 5; - string expectedErrorDescription = "No Error"; - int expectedErrorGroupId = 0; - string expectedErrorGroupName = "OK"; - bool expectedErrorPermanent = false; - string expectedChannel = "EMAIL"; - - string expectedResponse = $@" + attachmentStream, + attachmentStream2 + }; + + var response = sendEmailApi.SendEmail( + from: expectedFrom, + to: expectedToList, + subject: expectedSubject, + text: expectedText, + bulkId: expectedBulkId, + messageId: expectedMessageId, + attachment: attachmentList, + html: expectedHtml, + replyTo: expectedReplyTo + ); + + Assert.AreEqual(expectedMessageCount, response.Messages.Count); + Assert.AreEqual(expectedMessageId, response.Messages[0].MessageId); + Assert.AreEqual(expectedTo, response.Messages[0].To); + Assert.AreEqual(expectedStatusId, response.Messages[0].Status.Id); + Assert.AreEqual(expectedStatusName, response.Messages[0].Status.Name); + Assert.AreEqual(expectedStatusGroupId, response.Messages[0].Status.GroupId); + Assert.AreEqual(expectedStatusDescription, response.Messages[0].Status.Description); + Assert.AreEqual(expectedStatusGroupId, response.Messages[0].Status.GroupId); + } + + [TestMethod] + public void ShouldGetEmailDeliveryReportsTest() + { + var expectedTo = "john.smith@somedomain.com"; + var expectedMessageCount = 1; + var expectedMessageId = "MSG-1234"; + var expectedBulkId = "BULK-1234"; + var expectedSentAt = new DateTimeOffset(2021, 9, 2, 9, 57, 56, TimeSpan.FromHours(0)); + var expectedDoneAt = new DateTimeOffset(2021, 9, 2, 9, 58, 33, TimeSpan.FromHours(0)); + var expectedCurrency = "EUR"; + var expectedPricePerMessage = 0.0M; + var expectedStatusName = "DELIVERED_TO_HANDSET"; + var expectedStatusId = 5; + var expectedStatusDescription = "Message delivered to handset"; + var expectedStatusGroupId = 3; + var expectedStatusGroupName = "DELIVERED"; + var expectedErrorName = "NO_ERROR"; + var expectedErrorId = 5; + var expectedErrorDescription = "No Error"; + var expectedErrorGroupId = 0; + var expectedErrorGroupName = "OK"; + var expectedErrorPermanent = false; + var expectedChannel = "EMAIL"; + + var expectedResponse = $@" {{ ""results"": [ {{ @@ -314,57 +312,57 @@ public void ShouldGetEmailDeliveryReportsTest() ] }}"; - SetUpGetRequest(EMAIL_LOGS_ENDPOINT, expectedResponse, 200); + SetUpGetRequest(EMAIL_LOGS_ENDPOINT, expectedResponse, 200); - var sendEmailApi = new EmailApi(configuration); + var sendEmailApi = new EmailApi(configuration); - EmailReportsResult response = sendEmailApi.GetEmailDeliveryReports(bulkId: expectedBulkId, messageId: expectedMessageId, limit: 2); + var response = sendEmailApi.GetEmailDeliveryReports(expectedBulkId, expectedMessageId, limit: 2); - Assert.AreEqual(1, response.Results.Count); - Assert.AreEqual(expectedBulkId, response.Results[0].BulkId); - Assert.AreEqual(expectedMessageId, response.Results[0].MessageId); + Assert.AreEqual(1, response.Results.Count); + Assert.AreEqual(expectedBulkId, response.Results[0].BulkId); + Assert.AreEqual(expectedMessageId, response.Results[0].MessageId); - Assert.AreEqual(expectedSentAt, response.Results[0].SentAt); - Assert.AreEqual(expectedDoneAt, response.Results[0].DoneAt); - Assert.AreEqual(expectedMessageCount, response.Results[0].MessageCount); + Assert.AreEqual(expectedSentAt, response.Results[0].SentAt); + Assert.AreEqual(expectedDoneAt, response.Results[0].DoneAt); + Assert.AreEqual(expectedMessageCount, response.Results[0].MessageCount); - Assert.AreEqual(expectedStatusDescription, response.Results[0].Status.Description); - Assert.AreEqual(expectedStatusGroupId, response.Results[0].Status.GroupId); - Assert.AreEqual(expectedStatusGroupName, response.Results[0].Status.GroupName); - Assert.AreEqual(expectedStatusId, response.Results[0].Status.Id); - Assert.AreEqual(expectedStatusName, response.Results[0].Status.Name); + Assert.AreEqual(expectedStatusDescription, response.Results[0].Status.Description); + Assert.AreEqual(expectedStatusGroupId, response.Results[0].Status.GroupId); + Assert.AreEqual(expectedStatusGroupName, response.Results[0].Status.GroupName); + Assert.AreEqual(expectedStatusId, response.Results[0].Status.Id); + Assert.AreEqual(expectedStatusName, response.Results[0].Status.Name); - Assert.AreEqual(expectedPricePerMessage, response.Results[0].Price.PricePerMessage); + Assert.AreEqual(expectedPricePerMessage, response.Results[0].Price.PricePerMessage); - Assert.AreEqual(expectedErrorDescription, response.Results[0].Error.Description); - Assert.AreEqual(expectedErrorGroupId, response.Results[0].Error.GroupId); - Assert.AreEqual(expectedErrorGroupName, response.Results[0].Error.GroupName); - Assert.AreEqual(expectedErrorId, response.Results[0].Error.Id); - Assert.AreEqual(expectedErrorName, response.Results[0].Error.Name); - Assert.AreEqual(expectedErrorPermanent, response.Results[0].Error.Permanent); - } + Assert.AreEqual(expectedErrorDescription, response.Results[0].Error.Description); + Assert.AreEqual(expectedErrorGroupId, response.Results[0].Error.GroupId); + Assert.AreEqual(expectedErrorGroupName, response.Results[0].Error.GroupName); + Assert.AreEqual(expectedErrorId, response.Results[0].Error.Id); + Assert.AreEqual(expectedErrorName, response.Results[0].Error.Name); + Assert.AreEqual(expectedErrorPermanent, response.Results[0].Error.Permanent); + } - [TestMethod] - public void ShouldGetEmailLogsTest() - { - string expectedFrom = "Jane Doe { - { "size", expectedSize.ToString() }, - { "page", expectedPage.ToString() } - }; - - SetUpGetRequest(EMAIL_DOMAINS, expectedQueryParameters, expectedResponse, 200); - - var emailApi = new EmailApi(configuration); - - void AssertEmailAllDomainsResponse(EmailAllDomainsResponse emailAllDomainsResponse) - { - Assert.IsNotNull(emailAllDomainsResponse.Paging); - Assert.AreEqual(expectedPage, emailAllDomainsResponse.Paging.Page); - Assert.AreEqual(expectedSize, emailAllDomainsResponse.Paging.Size); - Assert.AreEqual(expectedTotalPages, emailAllDomainsResponse.Paging.TotalPages); - Assert.AreEqual(expectedTotalResults, emailAllDomainsResponse.Paging.TotalResults); - - Assert.IsNotNull(emailAllDomainsResponse.Results); - Assert.AreEqual(expectedDomainId, emailAllDomainsResponse.Results[0].DomainId); - Assert.AreEqual(expectedDomainName, emailAllDomainsResponse.Results[0].DomainName); - Assert.AreEqual(expectedActive, emailAllDomainsResponse.Results[0].Active); - Assert.AreEqual(expectedClicks, emailAllDomainsResponse.Results[0].Tracking.Clicks); - Assert.AreEqual(expectedOpens, emailAllDomainsResponse.Results[0].Tracking.Opens); - Assert.AreEqual(expectedUnsubscribe, emailAllDomainsResponse.Results[0].Tracking.Unsubscribe); - Assert.AreEqual(expectedRecordType, emailAllDomainsResponse.Results[0].DnsRecords[0].RecordType); - Assert.AreEqual(expectedName, emailAllDomainsResponse.Results[0].DnsRecords[0].Name); - Assert.AreEqual(expectedExpectedValue, emailAllDomainsResponse.Results[0].DnsRecords[0].ExpectedValue); - Assert.AreEqual(expectedVerified, emailAllDomainsResponse.Results[0].DnsRecords[0].Verified); - Assert.AreEqual(expectedBlocked, emailAllDomainsResponse.Results[0].Blocked); - Assert.AreEqual(expectedCreatedAt, emailAllDomainsResponse.Results[0].CreatedAt); - Assert.AreEqual(expectedReturnPathAddress, emailAllDomainsResponse.Results[0].ReturnPathAddress); - } - - AssertResponse(emailApi.GetAllDomains(expectedSize, expectedPage), AssertEmailAllDomainsResponse); - AssertResponse(emailApi.GetAllDomainsAsync(expectedSize, expectedPage).Result, AssertEmailAllDomainsResponse); - - AssertResponseWithHttpInfo(emailApi.GetAllDomainsWithHttpInfo(expectedSize, expectedPage), AssertEmailAllDomainsResponse); - AssertResponseWithHttpInfo(emailApi.GetAllDomainsWithHttpInfoAsync(expectedSize, expectedPage).Result, AssertEmailAllDomainsResponse); - } + var expectedQueryParameters = new Dictionary + { + { "size", expectedSize.ToString() }, + { "page", expectedPage.ToString() } + }; + + SetUpGetRequest(EMAIL_DOMAINS, expectedQueryParameters, expectedResponse, 200); + + var emailApi = new EmailApi(configuration); - [TestMethod] - public void ShouldAddNewDomain() + void AssertEmailAllDomainsResponse(EmailAllDomainsResponse emailAllDomainsResponse) { - int givenDkimKeyLength = 1024; - long givenTargetedDailyTraffic = 1000; - string givenApplicationId = "string"; - string givenEntityId = "string"; - - int expectedDomainId = 1; - string expectedDomainName = "example.com"; - bool expectedActive = false; - bool expectedClicks = true; - bool expectedOpens = true; - bool expectedUnsubscribe = true; - string expectedRecordType = "string"; - string expectedName = "string"; - string expectedExpectedValue = "string"; - bool expectedVerified = true; - bool expectedBlocked = false; - DateTimeOffset expectedCreatedAt = new DateTimeOffset(2021, 1, 2, 1, 0, 0, 123, TimeSpan.FromHours(0)); - string expectedReturnPathAddress = "returnpath@example.com"; - - string givenRequest = $@" + Assert.IsNotNull(emailAllDomainsResponse.Paging); + Assert.AreEqual(expectedPage, emailAllDomainsResponse.Paging.Page); + Assert.AreEqual(expectedSize, emailAllDomainsResponse.Paging.Size); + Assert.AreEqual(expectedTotalPages, emailAllDomainsResponse.Paging.TotalPages); + Assert.AreEqual(expectedTotalResults, emailAllDomainsResponse.Paging.TotalResults); + + Assert.IsNotNull(emailAllDomainsResponse.Results); + Assert.AreEqual(expectedDomainId, emailAllDomainsResponse.Results[0].DomainId); + Assert.AreEqual(expectedDomainName, emailAllDomainsResponse.Results[0].DomainName); + Assert.AreEqual(expectedActive, emailAllDomainsResponse.Results[0].Active); + Assert.AreEqual(expectedClicks, emailAllDomainsResponse.Results[0].Tracking.Clicks); + Assert.AreEqual(expectedOpens, emailAllDomainsResponse.Results[0].Tracking.Opens); + Assert.AreEqual(expectedUnsubscribe, emailAllDomainsResponse.Results[0].Tracking.Unsubscribe); + Assert.AreEqual(expectedRecordType, emailAllDomainsResponse.Results[0].DnsRecords[0].RecordType); + Assert.AreEqual(expectedName, emailAllDomainsResponse.Results[0].DnsRecords[0].Name); + Assert.AreEqual(expectedExpectedValue, emailAllDomainsResponse.Results[0].DnsRecords[0].ExpectedValue); + Assert.AreEqual(expectedVerified, emailAllDomainsResponse.Results[0].DnsRecords[0].Verified); + Assert.AreEqual(expectedBlocked, emailAllDomainsResponse.Results[0].Blocked); + Assert.AreEqual(expectedCreatedAt, emailAllDomainsResponse.Results[0].CreatedAt); + Assert.AreEqual(expectedReturnPathAddress, emailAllDomainsResponse.Results[0].ReturnPathAddress); + } + + AssertResponse(emailApi.GetAllDomains(expectedSize, expectedPage), AssertEmailAllDomainsResponse); + AssertResponse(emailApi.GetAllDomainsAsync(expectedSize, expectedPage).Result, AssertEmailAllDomainsResponse); + + AssertResponseWithHttpInfo(emailApi.GetAllDomainsWithHttpInfo(expectedSize, expectedPage), + AssertEmailAllDomainsResponse); + AssertResponseWithHttpInfo(emailApi.GetAllDomainsWithHttpInfoAsync(expectedSize, expectedPage).Result, + AssertEmailAllDomainsResponse); + } + + [TestMethod] + public void ShouldAddNewDomain() + { + var givenDkimKeyLength = 1024; + long givenTargetedDailyTraffic = 1000; + var givenApplicationId = "string"; + var givenEntityId = "string"; + + var expectedDomainId = 1; + var expectedDomainName = "example.com"; + var expectedActive = false; + var expectedClicks = true; + var expectedOpens = true; + var expectedUnsubscribe = true; + var expectedRecordType = "string"; + var expectedName = "string"; + var expectedExpectedValue = "string"; + var expectedVerified = true; + var expectedBlocked = false; + var expectedCreatedAt = new DateTimeOffset(2021, 1, 2, 1, 0, 0, 123, TimeSpan.FromHours(0)); + var expectedReturnPathAddress = "returnpath@example.com"; + + var givenRequest = $@" {{ ""domainName"": ""{expectedDomainName}"", ""dkimKeyLength"": {givenDkimKeyLength}, @@ -720,7 +721,7 @@ public void ShouldAddNewDomain() ""returnPathAddress"": ""{expectedReturnPathAddress}"" }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""domainId"": {expectedDomainId}, ""domainName"": ""{expectedDomainName}"", @@ -743,62 +744,63 @@ public void ShouldAddNewDomain() ""returnPathAddress"": ""{expectedReturnPathAddress}"" }}"; - SetUpPostRequest(EMAIL_DOMAINS, givenRequest, expectedResponse, 200); - - var emailApi = new EmailApi(configuration); - - var emailAddDomainRequest = new EmailAddDomainRequest( - domainName: expectedDomainName, - dkimKeyLength: DkimKeyLengthEnum.NUMBER1024, - targetedDailyTraffic: givenTargetedDailyTraffic, - applicationId: givenApplicationId, - entityId: givenEntityId, - returnPathAddress: expectedReturnPathAddress - ); - - void AssertEmailDomainResponse(EmailDomainResponse emailDomainResponse) - { - Assert.IsNotNull(emailDomainResponse); - Assert.AreEqual(expectedDomainId, emailDomainResponse.DomainId); - Assert.AreEqual(expectedDomainName, emailDomainResponse.DomainName); - Assert.AreEqual(expectedActive, emailDomainResponse.Active); - Assert.AreEqual(expectedClicks, emailDomainResponse.Tracking.Clicks); - Assert.AreEqual(expectedOpens, emailDomainResponse.Tracking.Opens); - Assert.AreEqual(expectedUnsubscribe, emailDomainResponse.Tracking.Unsubscribe); - Assert.AreEqual(expectedRecordType, emailDomainResponse.DnsRecords[0].RecordType); - Assert.AreEqual(expectedName, emailDomainResponse.DnsRecords[0].Name); - Assert.AreEqual(expectedExpectedValue, emailDomainResponse.DnsRecords[0].ExpectedValue); - Assert.AreEqual(expectedVerified, emailDomainResponse.DnsRecords[0].Verified); - Assert.AreEqual(expectedBlocked, emailDomainResponse.Blocked); - Assert.AreEqual(expectedCreatedAt, emailDomainResponse.CreatedAt); - Assert.AreEqual(expectedReturnPathAddress, emailDomainResponse.ReturnPathAddress); - } - - AssertResponse(emailApi.AddDomain(emailAddDomainRequest), AssertEmailDomainResponse); - AssertResponse(emailApi.AddDomainAsync(emailAddDomainRequest).Result, AssertEmailDomainResponse); - - AssertResponseWithHttpInfo(emailApi.AddDomainWithHttpInfo(emailAddDomainRequest), AssertEmailDomainResponse); - AssertResponseWithHttpInfo(emailApi.AddDomainWithHttpInfoAsync(emailAddDomainRequest).Result, AssertEmailDomainResponse); - } + SetUpPostRequest(EMAIL_DOMAINS, givenRequest, expectedResponse, 200); + + var emailApi = new EmailApi(configuration); - [TestMethod] - public void ShouldGetDomainDetails() + var emailAddDomainRequest = new EmailAddDomainRequest( + expectedDomainName, + DkimKeyLengthEnum.NUMBER1024, + givenTargetedDailyTraffic, + givenApplicationId, + givenEntityId, + expectedReturnPathAddress + ); + + void AssertEmailDomainResponse(EmailDomainResponse emailDomainResponse) { - int expectedDomainId = 1; - string expectedDomainName = "example.com"; - bool expectedActive = false; - bool expectedClicks = true; - bool expectedOpens = true; - bool expectedUnsubscribe = true; - string expectedRecordType = "string"; - string expectedName = "string"; - string expectedExpectedValue = "string"; - bool expectedVerified = true; - bool expectedBlocked = false; - DateTimeOffset expectedCreatedAt = new DateTimeOffset(2021, 1, 2, 1, 0, 0, 123, TimeSpan.FromHours(0)); - string expectedReturnPathAddress = "returnpath@example.com"; - - string expectedResponse = $@" + Assert.IsNotNull(emailDomainResponse); + Assert.AreEqual(expectedDomainId, emailDomainResponse.DomainId); + Assert.AreEqual(expectedDomainName, emailDomainResponse.DomainName); + Assert.AreEqual(expectedActive, emailDomainResponse.Active); + Assert.AreEqual(expectedClicks, emailDomainResponse.Tracking.Clicks); + Assert.AreEqual(expectedOpens, emailDomainResponse.Tracking.Opens); + Assert.AreEqual(expectedUnsubscribe, emailDomainResponse.Tracking.Unsubscribe); + Assert.AreEqual(expectedRecordType, emailDomainResponse.DnsRecords[0].RecordType); + Assert.AreEqual(expectedName, emailDomainResponse.DnsRecords[0].Name); + Assert.AreEqual(expectedExpectedValue, emailDomainResponse.DnsRecords[0].ExpectedValue); + Assert.AreEqual(expectedVerified, emailDomainResponse.DnsRecords[0].Verified); + Assert.AreEqual(expectedBlocked, emailDomainResponse.Blocked); + Assert.AreEqual(expectedCreatedAt, emailDomainResponse.CreatedAt); + Assert.AreEqual(expectedReturnPathAddress, emailDomainResponse.ReturnPathAddress); + } + + AssertResponse(emailApi.AddDomain(emailAddDomainRequest), AssertEmailDomainResponse); + AssertResponse(emailApi.AddDomainAsync(emailAddDomainRequest).Result, AssertEmailDomainResponse); + + AssertResponseWithHttpInfo(emailApi.AddDomainWithHttpInfo(emailAddDomainRequest), AssertEmailDomainResponse); + AssertResponseWithHttpInfo(emailApi.AddDomainWithHttpInfoAsync(emailAddDomainRequest).Result, + AssertEmailDomainResponse); + } + + [TestMethod] + public void ShouldGetDomainDetails() + { + var expectedDomainId = 1; + var expectedDomainName = "example.com"; + var expectedActive = false; + var expectedClicks = true; + var expectedOpens = true; + var expectedUnsubscribe = true; + var expectedRecordType = "string"; + var expectedName = "string"; + var expectedExpectedValue = "string"; + var expectedVerified = true; + var expectedBlocked = false; + var expectedCreatedAt = new DateTimeOffset(2021, 1, 2, 1, 0, 0, 123, TimeSpan.FromHours(0)); + var expectedReturnPathAddress = "returnpath@example.com"; + + var expectedResponse = $@" {{ ""domainId"": {expectedDomainId}, ""domainName"": ""{expectedDomainName}"", @@ -821,73 +823,76 @@ public void ShouldGetDomainDetails() ""returnPathAddress"": ""{expectedReturnPathAddress}"" }}"; - SetUpGetRequest(EMAIL_DOMAIN.Replace("{domainName}", expectedDomainName), expectedResponse, 200); - - var emailApi = new EmailApi(configuration); - - void AssertEmailDomainResponse(EmailDomainResponse emailDomainResponse) - { - Assert.IsNotNull(emailDomainResponse); - Assert.AreEqual(expectedDomainId, emailDomainResponse.DomainId); - Assert.AreEqual(expectedDomainName, emailDomainResponse.DomainName); - Assert.AreEqual(expectedActive, emailDomainResponse.Active); - Assert.AreEqual(expectedClicks, emailDomainResponse.Tracking.Clicks); - Assert.AreEqual(expectedOpens, emailDomainResponse.Tracking.Opens); - Assert.AreEqual(expectedUnsubscribe, emailDomainResponse.Tracking.Unsubscribe); - Assert.AreEqual(expectedRecordType, emailDomainResponse.DnsRecords[0].RecordType); - Assert.AreEqual(expectedName, emailDomainResponse.DnsRecords[0].Name); - Assert.AreEqual(expectedExpectedValue, emailDomainResponse.DnsRecords[0].ExpectedValue); - Assert.AreEqual(expectedVerified, emailDomainResponse.DnsRecords[0].Verified); - Assert.AreEqual(expectedBlocked, emailDomainResponse.Blocked); - Assert.AreEqual(expectedCreatedAt, emailDomainResponse.CreatedAt); - Assert.AreEqual(expectedReturnPathAddress, emailDomainResponse.ReturnPathAddress); - } - - AssertResponse(emailApi.GetDomainDetails(expectedDomainName), AssertEmailDomainResponse); - AssertResponse(emailApi.GetDomainDetailsAsync(expectedDomainName).Result, AssertEmailDomainResponse); - - AssertResponseWithHttpInfo(emailApi.GetDomainDetailsWithHttpInfo(expectedDomainName), AssertEmailDomainResponse); - AssertResponseWithHttpInfo(emailApi.GetDomainDetailsWithHttpInfoAsync(expectedDomainName).Result, AssertEmailDomainResponse); - } + SetUpGetRequest(EMAIL_DOMAIN.Replace("{domainName}", expectedDomainName), expectedResponse, 200); - [TestMethod] - public void ShouldDeleteExistingDomain() + var emailApi = new EmailApi(configuration); + + void AssertEmailDomainResponse(EmailDomainResponse emailDomainResponse) { - string givenDomainName = "domainName"; + Assert.IsNotNull(emailDomainResponse); + Assert.AreEqual(expectedDomainId, emailDomainResponse.DomainId); + Assert.AreEqual(expectedDomainName, emailDomainResponse.DomainName); + Assert.AreEqual(expectedActive, emailDomainResponse.Active); + Assert.AreEqual(expectedClicks, emailDomainResponse.Tracking.Clicks); + Assert.AreEqual(expectedOpens, emailDomainResponse.Tracking.Opens); + Assert.AreEqual(expectedUnsubscribe, emailDomainResponse.Tracking.Unsubscribe); + Assert.AreEqual(expectedRecordType, emailDomainResponse.DnsRecords[0].RecordType); + Assert.AreEqual(expectedName, emailDomainResponse.DnsRecords[0].Name); + Assert.AreEqual(expectedExpectedValue, emailDomainResponse.DnsRecords[0].ExpectedValue); + Assert.AreEqual(expectedVerified, emailDomainResponse.DnsRecords[0].Verified); + Assert.AreEqual(expectedBlocked, emailDomainResponse.Blocked); + Assert.AreEqual(expectedCreatedAt, emailDomainResponse.CreatedAt); + Assert.AreEqual(expectedReturnPathAddress, emailDomainResponse.ReturnPathAddress); + } - SetUpDeleteRequest(EMAIL_DOMAIN.Replace("{domainName}", givenDomainName), 204); + AssertResponse(emailApi.GetDomainDetails(expectedDomainName), AssertEmailDomainResponse); + AssertResponse(emailApi.GetDomainDetailsAsync(expectedDomainName).Result, AssertEmailDomainResponse); - var emailApi = new EmailApi(configuration); + AssertResponseWithHttpInfo(emailApi.GetDomainDetailsWithHttpInfo(expectedDomainName), + AssertEmailDomainResponse); + AssertResponseWithHttpInfo(emailApi.GetDomainDetailsWithHttpInfoAsync(expectedDomainName).Result, + AssertEmailDomainResponse); + } - AssertNoBodyResponseWithHttpInfo(emailApi.DeleteDomainWithHttpInfo(givenDomainName), HttpStatusCode.NoContent); - AssertNoBodyResponseWithHttpInfo(emailApi.DeleteDomainWithHttpInfoAsync(givenDomainName).Result, HttpStatusCode.NoContent); - } + [TestMethod] + public void ShouldDeleteExistingDomain() + { + var givenDomainName = "domainName"; - [TestMethod] - public void ShouldUpdateTrackingEvents() - { - int expectedDomainId = 1; - string expectedDomainName = "example.com"; - bool expectedActive = false; - bool expectedClicks = true; - bool expectedOpens = true; - bool expectedUnsubscribe = true; - string expectedRecordType = "string"; - string expectedName = "string"; - string expectedExpectedValue = "string"; - bool expectedVerified = true; - bool expectedBlocked = false; - DateTimeOffset expectedCreatedAt = new DateTimeOffset(2021, 1, 2, 1, 0, 0, 123, TimeSpan.FromHours(0)); - string expectedReturnPathAddress = "returnpath@example.com"; - - string givenRequest = $@" + SetUpDeleteRequest(EMAIL_DOMAIN.Replace("{domainName}", givenDomainName), 204); + + var emailApi = new EmailApi(configuration); + + AssertNoBodyResponseWithHttpInfo(emailApi.DeleteDomainWithHttpInfo(givenDomainName), HttpStatusCode.NoContent); + AssertNoBodyResponseWithHttpInfo(emailApi.DeleteDomainWithHttpInfoAsync(givenDomainName).Result, + HttpStatusCode.NoContent); + } + + [TestMethod] + public void ShouldUpdateTrackingEvents() + { + var expectedDomainId = 1; + var expectedDomainName = "example.com"; + var expectedActive = false; + var expectedClicks = true; + var expectedOpens = true; + var expectedUnsubscribe = true; + var expectedRecordType = "string"; + var expectedName = "string"; + var expectedExpectedValue = "string"; + var expectedVerified = true; + var expectedBlocked = false; + var expectedCreatedAt = new DateTimeOffset(2021, 1, 2, 1, 0, 0, 123, TimeSpan.FromHours(0)); + var expectedReturnPathAddress = "returnpath@example.com"; + + var givenRequest = $@" {{ ""open"": {expectedOpens.ToString().ToLower()}, ""clicks"": {expectedClicks.ToString().ToLower()}, ""unsubscribe"": {expectedUnsubscribe.ToString().ToLower()} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""domainId"": {expectedDomainId}, ""domainName"": ""{expectedDomainName}"", @@ -910,64 +915,71 @@ public void ShouldUpdateTrackingEvents() ""returnPathAddress"": ""{expectedReturnPathAddress}"" }}"; - SetUpPutRequest(EMAIL_DOMAIN_TRACKING.Replace("{domainName}", expectedDomainName), givenRequest, expectedResponse, 200); - - var emailApi = new EmailApi(configuration); - - var emailTrackingEventRequest = new EmailTrackingEventRequest( - open: expectedOpens, - clicks: expectedClicks, - unsubscribe: expectedUnsubscribe - ); - - void AssertEmailDomainResponse(EmailDomainResponse emailDomainResponse) - { - Assert.IsNotNull(emailDomainResponse); - Assert.AreEqual(expectedDomainId, emailDomainResponse.DomainId); - Assert.AreEqual(expectedDomainName, emailDomainResponse.DomainName); - Assert.AreEqual(expectedActive, emailDomainResponse.Active); - Assert.AreEqual(expectedClicks, emailDomainResponse.Tracking.Clicks); - Assert.AreEqual(expectedOpens, emailDomainResponse.Tracking.Opens); - Assert.AreEqual(expectedUnsubscribe, emailDomainResponse.Tracking.Unsubscribe); - Assert.AreEqual(expectedRecordType, emailDomainResponse.DnsRecords[0].RecordType); - Assert.AreEqual(expectedName, emailDomainResponse.DnsRecords[0].Name); - Assert.AreEqual(expectedExpectedValue, emailDomainResponse.DnsRecords[0].ExpectedValue); - Assert.AreEqual(expectedVerified, emailDomainResponse.DnsRecords[0].Verified); - Assert.AreEqual(expectedBlocked, emailDomainResponse.Blocked); - Assert.AreEqual(expectedCreatedAt, emailDomainResponse.CreatedAt); - Assert.AreEqual(expectedReturnPathAddress, emailDomainResponse.ReturnPathAddress); - } - - AssertResponse(emailApi.UpdateTrackingEvents(expectedDomainName, emailTrackingEventRequest), AssertEmailDomainResponse); - AssertResponse(emailApi.UpdateTrackingEventsAsync(expectedDomainName, emailTrackingEventRequest).Result, AssertEmailDomainResponse); - - AssertResponseWithHttpInfo(emailApi.UpdateTrackingEventsWithHttpInfo(expectedDomainName, emailTrackingEventRequest), AssertEmailDomainResponse); - AssertResponseWithHttpInfo(emailApi.UpdateTrackingEventsWithHttpInfoAsync(expectedDomainName, emailTrackingEventRequest).Result, AssertEmailDomainResponse); - } + SetUpPutRequest(EMAIL_DOMAIN_TRACKING.Replace("{domainName}", expectedDomainName), givenRequest, + expectedResponse, 200); + + var emailApi = new EmailApi(configuration); + + var emailTrackingEventRequest = new EmailTrackingEventRequest( + expectedOpens, + expectedClicks, + expectedUnsubscribe + ); - [TestMethod] - public void ShouldUpdateReturnPath() + void AssertEmailDomainResponse(EmailDomainResponse emailDomainResponse) { - int expectedDomainId = 1; - string expectedDomainName = "example.com"; - bool expectedActive = false; - bool expectedClicks = true; - bool expectedOpens = true; - bool expectedUnsubscribe = true; - string expectedRecordType = "string"; - string expectedName = "string"; - string expectedExpectedValue = "string"; - bool expectedVerified = true; - bool expectedBlocked = false; - DateTimeOffset expectedCreatedAt = new DateTimeOffset(2021, 1, 2, 1, 0, 0, 123, TimeSpan.FromHours(0)); - string expectedReturnPathAddress = "returnpath@example.com"; - - string givenRequest = $@" + Assert.IsNotNull(emailDomainResponse); + Assert.AreEqual(expectedDomainId, emailDomainResponse.DomainId); + Assert.AreEqual(expectedDomainName, emailDomainResponse.DomainName); + Assert.AreEqual(expectedActive, emailDomainResponse.Active); + Assert.AreEqual(expectedClicks, emailDomainResponse.Tracking.Clicks); + Assert.AreEqual(expectedOpens, emailDomainResponse.Tracking.Opens); + Assert.AreEqual(expectedUnsubscribe, emailDomainResponse.Tracking.Unsubscribe); + Assert.AreEqual(expectedRecordType, emailDomainResponse.DnsRecords[0].RecordType); + Assert.AreEqual(expectedName, emailDomainResponse.DnsRecords[0].Name); + Assert.AreEqual(expectedExpectedValue, emailDomainResponse.DnsRecords[0].ExpectedValue); + Assert.AreEqual(expectedVerified, emailDomainResponse.DnsRecords[0].Verified); + Assert.AreEqual(expectedBlocked, emailDomainResponse.Blocked); + Assert.AreEqual(expectedCreatedAt, emailDomainResponse.CreatedAt); + Assert.AreEqual(expectedReturnPathAddress, emailDomainResponse.ReturnPathAddress); + } + + AssertResponse(emailApi.UpdateTrackingEvents(expectedDomainName, emailTrackingEventRequest), + AssertEmailDomainResponse); + AssertResponse(emailApi.UpdateTrackingEventsAsync(expectedDomainName, emailTrackingEventRequest).Result, + AssertEmailDomainResponse); + + AssertResponseWithHttpInfo( + emailApi.UpdateTrackingEventsWithHttpInfo(expectedDomainName, emailTrackingEventRequest), + AssertEmailDomainResponse); + AssertResponseWithHttpInfo( + emailApi.UpdateTrackingEventsWithHttpInfoAsync(expectedDomainName, emailTrackingEventRequest).Result, + AssertEmailDomainResponse); + } + + [TestMethod] + public void ShouldUpdateReturnPath() + { + var expectedDomainId = 1; + var expectedDomainName = "example.com"; + var expectedActive = false; + var expectedClicks = true; + var expectedOpens = true; + var expectedUnsubscribe = true; + var expectedRecordType = "string"; + var expectedName = "string"; + var expectedExpectedValue = "string"; + var expectedVerified = true; + var expectedBlocked = false; + var expectedCreatedAt = new DateTimeOffset(2021, 1, 2, 1, 0, 0, 123, TimeSpan.FromHours(0)); + var expectedReturnPathAddress = "returnpath@example.com"; + + var givenRequest = $@" {{ ""returnPathAddress"": ""{expectedReturnPathAddress}"", }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""domainId"": {expectedDomainId}, ""domainName"": ""{expectedDomainName}"", @@ -990,61 +1002,69 @@ public void ShouldUpdateReturnPath() ""returnPathAddress"": ""{expectedReturnPathAddress}"" }}"; - SetUpPutRequest(EMAIL_DOMAIN_RETURN_PATH.Replace("{domainName}", expectedDomainName), givenRequest, expectedResponse, 200); - - var emailApi = new EmailApi(configuration); - - var emailReturnPathAddressRequest = new EmailReturnPathAddressRequest( - returnPathAddress: expectedReturnPathAddress - ); - - void AssertEmailDomainResponse(EmailDomainResponse emailDomainResponse) - { - Assert.IsNotNull(emailDomainResponse); - Assert.AreEqual(expectedDomainId, emailDomainResponse.DomainId); - Assert.AreEqual(expectedDomainName, emailDomainResponse.DomainName); - Assert.AreEqual(expectedActive, emailDomainResponse.Active); - Assert.AreEqual(expectedClicks, emailDomainResponse.Tracking.Clicks); - Assert.AreEqual(expectedOpens, emailDomainResponse.Tracking.Opens); - Assert.AreEqual(expectedUnsubscribe, emailDomainResponse.Tracking.Unsubscribe); - Assert.AreEqual(expectedRecordType, emailDomainResponse.DnsRecords[0].RecordType); - Assert.AreEqual(expectedName, emailDomainResponse.DnsRecords[0].Name); - Assert.AreEqual(expectedExpectedValue, emailDomainResponse.DnsRecords[0].ExpectedValue); - Assert.AreEqual(expectedVerified, emailDomainResponse.DnsRecords[0].Verified); - Assert.AreEqual(expectedBlocked, emailDomainResponse.Blocked); - Assert.AreEqual(expectedCreatedAt, emailDomainResponse.CreatedAt); - Assert.AreEqual(expectedReturnPathAddress, emailDomainResponse.ReturnPathAddress); - } - - AssertResponse(emailApi.UpdateReturnPath(expectedDomainName, emailReturnPathAddressRequest), AssertEmailDomainResponse); - AssertResponse(emailApi.UpdateReturnPathAsync(expectedDomainName, emailReturnPathAddressRequest).Result, AssertEmailDomainResponse); - - AssertResponseWithHttpInfo(emailApi.UpdateReturnPathWithHttpInfo(expectedDomainName, emailReturnPathAddressRequest), AssertEmailDomainResponse); - AssertResponseWithHttpInfo(emailApi.UpdateReturnPathWithHttpInfoAsync(expectedDomainName, emailReturnPathAddressRequest).Result, AssertEmailDomainResponse); - } + SetUpPutRequest(EMAIL_DOMAIN_RETURN_PATH.Replace("{domainName}", expectedDomainName), givenRequest, + expectedResponse, 200); + + var emailApi = new EmailApi(configuration); + + var emailReturnPathAddressRequest = new EmailReturnPathAddressRequest( + expectedReturnPathAddress + ); - [TestMethod] - public void ShouldVerifyDomain() + void AssertEmailDomainResponse(EmailDomainResponse emailDomainResponse) { - string givenDomainName = "domainName"; + Assert.IsNotNull(emailDomainResponse); + Assert.AreEqual(expectedDomainId, emailDomainResponse.DomainId); + Assert.AreEqual(expectedDomainName, emailDomainResponse.DomainName); + Assert.AreEqual(expectedActive, emailDomainResponse.Active); + Assert.AreEqual(expectedClicks, emailDomainResponse.Tracking.Clicks); + Assert.AreEqual(expectedOpens, emailDomainResponse.Tracking.Opens); + Assert.AreEqual(expectedUnsubscribe, emailDomainResponse.Tracking.Unsubscribe); + Assert.AreEqual(expectedRecordType, emailDomainResponse.DnsRecords[0].RecordType); + Assert.AreEqual(expectedName, emailDomainResponse.DnsRecords[0].Name); + Assert.AreEqual(expectedExpectedValue, emailDomainResponse.DnsRecords[0].ExpectedValue); + Assert.AreEqual(expectedVerified, emailDomainResponse.DnsRecords[0].Verified); + Assert.AreEqual(expectedBlocked, emailDomainResponse.Blocked); + Assert.AreEqual(expectedCreatedAt, emailDomainResponse.CreatedAt); + Assert.AreEqual(expectedReturnPathAddress, emailDomainResponse.ReturnPathAddress); + } - SetUpNoRequestBodyNoResponseBodyPostRequest(EMAIL_DOMAIN_VERIFY.Replace("{domainName}", givenDomainName), 202); + AssertResponse(emailApi.UpdateReturnPath(expectedDomainName, emailReturnPathAddressRequest), + AssertEmailDomainResponse); + AssertResponse(emailApi.UpdateReturnPathAsync(expectedDomainName, emailReturnPathAddressRequest).Result, + AssertEmailDomainResponse); + + AssertResponseWithHttpInfo( + emailApi.UpdateReturnPathWithHttpInfo(expectedDomainName, emailReturnPathAddressRequest), + AssertEmailDomainResponse); + AssertResponseWithHttpInfo( + emailApi.UpdateReturnPathWithHttpInfoAsync(expectedDomainName, emailReturnPathAddressRequest).Result, + AssertEmailDomainResponse); + } - var emailApi = new EmailApi(configuration); + [TestMethod] + public void ShouldVerifyDomain() + { + var givenDomainName = "domainName"; - AssertNoBodyResponseWithHttpInfo(emailApi.VerifyDomainWithHttpInfo(givenDomainName), HttpStatusCode.Accepted); - AssertNoBodyResponseWithHttpInfo(emailApi.VerifyDomainWithHttpInfoAsync(givenDomainName).Result, HttpStatusCode.Accepted); - } + SetUpNoRequestBodyNoResponseBodyPostRequest(EMAIL_DOMAIN_VERIFY.Replace("{domainName}", givenDomainName), 202); - [TestMethod] - public void ShouldListAllDedicatedIpsForProvidedAccountId() - { - string expectedIpAddress = "11.11.11.1"; - bool expectedDedicated = true; - int expectedAssignedDomainCount = 1; - string expectedStatus = "ASSIGNABLE"; + var emailApi = new EmailApi(configuration); + + AssertNoBodyResponseWithHttpInfo(emailApi.VerifyDomainWithHttpInfo(givenDomainName), HttpStatusCode.Accepted); + AssertNoBodyResponseWithHttpInfo(emailApi.VerifyDomainWithHttpInfoAsync(givenDomainName).Result, + HttpStatusCode.Accepted); + } + + [TestMethod] + public void ShouldListAllDedicatedIpsForProvidedAccountId() + { + var expectedIpAddress = "11.11.11.1"; + var expectedDedicated = true; + var expectedAssignedDomainCount = 1; + var expectedStatus = "ASSIGNABLE"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""result"": [ {{ @@ -1056,38 +1076,38 @@ public void ShouldListAllDedicatedIpsForProvidedAccountId() ] }}"; - SetUpGetRequest(EMAIL_IPS, expectedResponse, 200); + SetUpGetRequest(EMAIL_IPS, expectedResponse, 200); - var emailApi = new EmailApi(configuration); + var emailApi = new EmailApi(configuration); - void AssertEmailDomainIpResponse(EmailDomainIpResponse emailDomainIpResponse) - { - Assert.IsNotNull(emailDomainIpResponse); - Assert.IsNotNull(emailDomainIpResponse.Result[0]); - Assert.AreEqual(expectedIpAddress, emailDomainIpResponse.Result[0].IpAddress); - Assert.AreEqual(expectedDedicated, emailDomainIpResponse.Result[0].Dedicated); - Assert.AreEqual(expectedAssignedDomainCount, emailDomainIpResponse.Result[0].AssignedDomainCount); - Assert.AreEqual(expectedStatus, emailDomainIpResponse.Result[0].Status); - } + void AssertEmailDomainIpResponse(EmailDomainIpResponse emailDomainIpResponse) + { + Assert.IsNotNull(emailDomainIpResponse); + Assert.IsNotNull(emailDomainIpResponse.Result[0]); + Assert.AreEqual(expectedIpAddress, emailDomainIpResponse.Result[0].IpAddress); + Assert.AreEqual(expectedDedicated, emailDomainIpResponse.Result[0].Dedicated); + Assert.AreEqual(expectedAssignedDomainCount, emailDomainIpResponse.Result[0].AssignedDomainCount); + Assert.AreEqual(expectedStatus, emailDomainIpResponse.Result[0].Status); + } - AssertResponse(emailApi.GetAllIps(), AssertEmailDomainIpResponse); - AssertResponse(emailApi.GetAllIpsAsync().Result, AssertEmailDomainIpResponse); + AssertResponse(emailApi.GetAllIps(), AssertEmailDomainIpResponse); + AssertResponse(emailApi.GetAllIpsAsync().Result, AssertEmailDomainIpResponse); - AssertResponseWithHttpInfo(emailApi.GetAllIpsWithHttpInfo(), AssertEmailDomainIpResponse); - AssertResponseWithHttpInfo(emailApi.GetAllIpsWithHttpInfoAsync().Result, AssertEmailDomainIpResponse); - } + AssertResponseWithHttpInfo(emailApi.GetAllIpsWithHttpInfo(), AssertEmailDomainIpResponse); + AssertResponseWithHttpInfo(emailApi.GetAllIpsWithHttpInfoAsync().Result, AssertEmailDomainIpResponse); + } - [TestMethod] - public void ShouldListAllDedicatedIpsForDomainAndForProvidedAccountId() - { - string expectedIpAddress = "11.11.11.1"; - bool expectedDedicated = true; - int expectedAssignedDomainCount = 1; - string expectedStatus = "ASSIGNABLE"; + [TestMethod] + public void ShouldListAllDedicatedIpsForDomainAndForProvidedAccountId() + { + var expectedIpAddress = "11.11.11.1"; + var expectedDedicated = true; + var expectedAssignedDomainCount = 1; + var expectedStatus = "ASSIGNABLE"; - string expectedDomainName = "domainName"; + var expectedDomainName = "domainName"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""result"": [ {{ @@ -1099,132 +1119,139 @@ public void ShouldListAllDedicatedIpsForDomainAndForProvidedAccountId() ] }}"; - var queryParameters = new Dictionary() - { - { "domainName", expectedDomainName } - }; + var queryParameters = new Dictionary + { + { "domainName", expectedDomainName } + }; - SetUpGetRequest(EMAIL_DOMAIN_IPS, queryParameters, expectedResponse, 200); + SetUpGetRequest(EMAIL_DOMAIN_IPS, queryParameters, expectedResponse, 200); - var emailApi = new EmailApi(configuration); + var emailApi = new EmailApi(configuration); - void AssertEmailDomainIpResponse(EmailDomainIpResponse emailDomainIpResponse) - { - Assert.IsNotNull(emailDomainIpResponse); - Assert.IsNotNull(emailDomainIpResponse.Result[0]); - Assert.AreEqual(expectedIpAddress, emailDomainIpResponse.Result[0].IpAddress); - Assert.AreEqual(expectedDedicated, emailDomainIpResponse.Result[0].Dedicated); - Assert.AreEqual(expectedAssignedDomainCount, emailDomainIpResponse.Result[0].AssignedDomainCount); - Assert.AreEqual(expectedStatus, emailDomainIpResponse.Result[0].Status); - } + void AssertEmailDomainIpResponse(EmailDomainIpResponse emailDomainIpResponse) + { + Assert.IsNotNull(emailDomainIpResponse); + Assert.IsNotNull(emailDomainIpResponse.Result[0]); + Assert.AreEqual(expectedIpAddress, emailDomainIpResponse.Result[0].IpAddress); + Assert.AreEqual(expectedDedicated, emailDomainIpResponse.Result[0].Dedicated); + Assert.AreEqual(expectedAssignedDomainCount, emailDomainIpResponse.Result[0].AssignedDomainCount); + Assert.AreEqual(expectedStatus, emailDomainIpResponse.Result[0].Status); + } - AssertResponse(emailApi.GetAllDomainIps(expectedDomainName), AssertEmailDomainIpResponse); - AssertResponse(emailApi.GetAllDomainIpsAsync(expectedDomainName).Result, AssertEmailDomainIpResponse); + AssertResponse(emailApi.GetAllDomainIps(expectedDomainName), AssertEmailDomainIpResponse); + AssertResponse(emailApi.GetAllDomainIpsAsync(expectedDomainName).Result, AssertEmailDomainIpResponse); - AssertResponseWithHttpInfo(emailApi.GetAllDomainIpsWithHttpInfo(expectedDomainName), AssertEmailDomainIpResponse); - AssertResponseWithHttpInfo(emailApi.GetAllDomainIpsWithHttpInfoAsync(expectedDomainName).Result, AssertEmailDomainIpResponse); - } + AssertResponseWithHttpInfo(emailApi.GetAllDomainIpsWithHttpInfo(expectedDomainName), + AssertEmailDomainIpResponse); + AssertResponseWithHttpInfo(emailApi.GetAllDomainIpsWithHttpInfoAsync(expectedDomainName).Result, + AssertEmailDomainIpResponse); + } - [TestMethod] - public void ShouldAssignDedicatedIpAddressToProvidedDomainForTheAccountId() - { - string givenDomainName = "domain.com"; - string givenIpAddress = "11.11.11.11"; + [TestMethod] + public void ShouldAssignDedicatedIpAddressToProvidedDomainForTheAccountId() + { + var givenDomainName = "domain.com"; + var givenIpAddress = "11.11.11.11"; - string expectedResult = "OK"; + var expectedResult = "OK"; - string givenRequest = $@" + var givenRequest = $@" {{ ""domainName"": ""{givenDomainName}"", ""ipAddress"": ""{givenIpAddress}"" }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""result"": ""{expectedResult}"" }}"; - SetUpPostRequest(EMAIL_DOMAIN_IPS, givenRequest, expectedResponse, 200); - - var emailApi = new EmailApi(configuration); - - var emailDomainIpRequest = new EmailDomainIpRequest( - domainName: givenDomainName, - ipAddress: givenIpAddress - ); + SetUpPostRequest(EMAIL_DOMAIN_IPS, givenRequest, expectedResponse, 200); - void AssertEmailSimpleApiResponse(EmailSimpleApiResponse emailSimpleApiResponse) - { - Assert.IsNotNull(emailSimpleApiResponse); - Assert.AreEqual(expectedResult, emailSimpleApiResponse.Result); - } + var emailApi = new EmailApi(configuration); - AssertResponse(emailApi.AssignIpToDomain(emailDomainIpRequest), AssertEmailSimpleApiResponse); - AssertResponse(emailApi.AssignIpToDomainAsync(emailDomainIpRequest).Result, AssertEmailSimpleApiResponse); + var emailDomainIpRequest = new EmailDomainIpRequest( + givenDomainName, + givenIpAddress + ); - AssertResponseWithHttpInfo(emailApi.AssignIpToDomainWithHttpInfo(emailDomainIpRequest), AssertEmailSimpleApiResponse); - AssertResponseWithHttpInfo(emailApi.AssignIpToDomainWithHttpInfoAsync(emailDomainIpRequest).Result, AssertEmailSimpleApiResponse); + void AssertEmailSimpleApiResponse(EmailSimpleApiResponse emailSimpleApiResponse) + { + Assert.IsNotNull(emailSimpleApiResponse); + Assert.AreEqual(expectedResult, emailSimpleApiResponse.Result); } - [TestMethod] - public void ShouldRemoveDedicatedIpAddressFromTheProvidedDomain() - { + AssertResponse(emailApi.AssignIpToDomain(emailDomainIpRequest), AssertEmailSimpleApiResponse); + AssertResponse(emailApi.AssignIpToDomainAsync(emailDomainIpRequest).Result, AssertEmailSimpleApiResponse); - string givenDomainName = "domain.com"; - string givenIpAddress = "11.11.11.11"; + AssertResponseWithHttpInfo(emailApi.AssignIpToDomainWithHttpInfo(emailDomainIpRequest), + AssertEmailSimpleApiResponse); + AssertResponseWithHttpInfo(emailApi.AssignIpToDomainWithHttpInfoAsync(emailDomainIpRequest).Result, + AssertEmailSimpleApiResponse); + } + + [TestMethod] + public void ShouldRemoveDedicatedIpAddressFromTheProvidedDomain() + { + var givenDomainName = "domain.com"; + var givenIpAddress = "11.11.11.11"; - string expectedResult = "OK"; + var expectedResult = "OK"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""result"": ""{expectedResult}"" }}"; - var givenQueryParameters = new Dictionary { - { "domainName", givenDomainName }, - { "ipAddress", givenIpAddress } - }; + var givenQueryParameters = new Dictionary + { + { "domainName", givenDomainName }, + { "ipAddress", givenIpAddress } + }; - SetUpDeleteRequestWithResponseBody(EMAIL_DOMAIN_IPS, givenQueryParameters, expectedResponse, 200); + SetUpDeleteRequestWithResponseBody(EMAIL_DOMAIN_IPS, givenQueryParameters, expectedResponse, 200); - var emailApi = new EmailApi(configuration); + var emailApi = new EmailApi(configuration); - void AssertEmailSimpleApiResponse(EmailSimpleApiResponse emailSimpleApiResponse) - { - Assert.IsNotNull(emailSimpleApiResponse); - Assert.AreEqual(expectedResult, emailSimpleApiResponse.Result); - } + void AssertEmailSimpleApiResponse(EmailSimpleApiResponse emailSimpleApiResponse) + { + Assert.IsNotNull(emailSimpleApiResponse); + Assert.AreEqual(expectedResult, emailSimpleApiResponse.Result); + } - AssertResponse(emailApi.RemoveIpFromDomain(givenDomainName, givenIpAddress), AssertEmailSimpleApiResponse); - AssertResponse(emailApi.RemoveIpFromDomainAsync(givenDomainName, givenIpAddress).Result, AssertEmailSimpleApiResponse); + AssertResponse(emailApi.RemoveIpFromDomain(givenDomainName, givenIpAddress), AssertEmailSimpleApiResponse); + AssertResponse(emailApi.RemoveIpFromDomainAsync(givenDomainName, givenIpAddress).Result, + AssertEmailSimpleApiResponse); - AssertResponseWithHttpInfo(emailApi.RemoveIpFromDomainWithHttpInfo(givenDomainName, givenIpAddress), AssertEmailSimpleApiResponse); - AssertResponseWithHttpInfo(emailApi.RemoveIpFromDomainWithHttpInfoAsync(givenDomainName, givenIpAddress).Result, AssertEmailSimpleApiResponse); - } + AssertResponseWithHttpInfo(emailApi.RemoveIpFromDomainWithHttpInfo(givenDomainName, givenIpAddress), + AssertEmailSimpleApiResponse); + AssertResponseWithHttpInfo(emailApi.RemoveIpFromDomainWithHttpInfoAsync(givenDomainName, givenIpAddress).Result, + AssertEmailSimpleApiResponse); + } - [DataTestMethod] - [DataRow(0)] - [DataRow(1)] - public void SendEmailErrorResponseTest(int errorResponseIndex) - { - int expectedHttpCode = ErrorResponses[errorResponseIndex].Item1; - string expectedMessageId = ErrorResponses[errorResponseIndex].Item2; - string expectedErrorText = ErrorResponses[errorResponseIndex].Item4; - string expectedErrorPhrase = ErrorResponses[errorResponseIndex].Item3; - - string givenTo = "john.smith@somedomain.com"; - int givenMessageCount = 1; - string givenMessageId = "somexternalMessageId"; - int givenGroupId = 1; - string givenGroupName = "PENDING"; - int givenId = 7; - string givenName = "PENDING_ENROUTE"; - string givenDescription = "Message sent to next instance"; - string givenFrom = "jane.smith@somecompany.com"; - string givenSubject = "Mail subject text"; - string givenMailText = "Mail text"; - - string givenRequest = $@" + [DataTestMethod] + [DataRow(0)] + [DataRow(1)] + public void SendEmailErrorResponseTest(int errorResponseIndex) + { + var expectedHttpCode = ErrorResponses[errorResponseIndex].Item1; + var expectedMessageId = ErrorResponses[errorResponseIndex].Item2; + var expectedErrorText = ErrorResponses[errorResponseIndex].Item4; + var expectedErrorPhrase = ErrorResponses[errorResponseIndex].Item3; + + var givenTo = "john.smith@somedomain.com"; + var givenMessageCount = 1; + var givenMessageId = "somexternalMessageId"; + var givenGroupId = 1; + var givenGroupName = "PENDING"; + var givenId = 7; + var givenName = "PENDING_ENROUTE"; + var givenDescription = "Message sent to next instance"; + var givenFrom = "jane.smith@somecompany.com"; + var givenSubject = "Mail subject text"; + var givenMailText = "Mail text"; + + var givenRequest = $@" {{ ""messages"": [ {{ @@ -1242,7 +1269,7 @@ public void SendEmailErrorResponseTest(int errorResponseIndex) ] }}"; - string expectedJson = $@" + var expectedJson = $@" {{ ""requestError"": {{ ""serviceException"": {{ @@ -1252,61 +1279,62 @@ public void SendEmailErrorResponseTest(int errorResponseIndex) }} }}"; - Dictionary responseHeaders = new Dictionary() - { - { "Server", "SMS,API" }, - { "X-Request-ID", "1608758729810312842" }, - { "Content-Type", "application/json; charset=utf-8" } - }; - - Multimap givenParts = new Multimap - { - { "from", givenFrom }, - { "to", givenTo }, - { "subject", givenSubject }, - { "text", givenMailText}, - }; - - SetUpMultipartFormRequest(EMAIL_SEND_FULLY_FEATURED_ENDPOINT, givenParts, expectedJson, expectedHttpCode); - - var emailApi = new EmailApi(configuration); - - var toList = new List - { - givenTo - }; - - try - { - var result = emailApi.SendEmail(from: givenFrom, to: toList, subject: givenSubject, text: givenMailText); - } - catch (ApiException ex) - { - Assert.AreEqual(expectedHttpCode, ex.ErrorCode); - Assert.AreEqual(expectedJson, ex.ErrorContent); - Assert.IsInstanceOfType(ex, typeof(ApiException)); - Assert.IsTrue(ex.Message.Contains(expectedErrorPhrase)); - Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(expectedMessageId) == true); - Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(expectedErrorText) == true); - Assert.IsTrue(responseHeaders.All(h => ex.Headers.ContainsKey(h.Key) && ex.Headers[h.Key].First().Equals(h.Value))); - } - } + var responseHeaders = new Dictionary + { + { "Server", "SMS,API" }, + { "X-Request-ID", "1608758729810312842" }, + { "Content-Type", "application/json; charset=utf-8" } + }; - [DataTestMethod] - [DataRow(0)] - [DataRow(1)] - public void GetEmailDeliveryReportsResponseTest(int errorResponseIndex) + var givenParts = new Multimap { - int expectedHttpCode = DeliveryReportErrorResponses[errorResponseIndex].Item1; - string expectedMessageId = DeliveryReportErrorResponses[errorResponseIndex].Item2; - string expectedErrorPhrase = DeliveryReportErrorResponses[errorResponseIndex].Item3; - string expectedErrorText = DeliveryReportErrorResponses[errorResponseIndex].Item4; + { "from", givenFrom }, + { "to", givenTo }, + { "subject", givenSubject }, + { "text", givenMailText } + }; + + SetUpMultipartFormRequest(EMAIL_SEND_FULLY_FEATURED_ENDPOINT, givenParts, expectedJson, expectedHttpCode); + + var emailApi = new EmailApi(configuration); + + var toList = new List + { + givenTo + }; + + try + { + var result = emailApi.SendEmail(from: givenFrom, to: toList, subject: givenSubject, text: givenMailText); + } + catch (ApiException ex) + { + Assert.AreEqual(expectedHttpCode, ex.ErrorCode); + Assert.AreEqual(expectedJson, ex.ErrorContent); + Assert.IsInstanceOfType(ex, typeof(ApiException)); + Assert.IsTrue(ex.Message.Contains(expectedErrorPhrase)); + Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(expectedMessageId) == true); + Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(expectedErrorText) == true); + Assert.IsTrue(responseHeaders.All(h => + ex.Headers.ContainsKey(h.Key) && ex.Headers[h.Key].First().Equals(h.Value))); + } + } + + [DataTestMethod] + [DataRow(0)] + [DataRow(1)] + public void GetEmailDeliveryReportsResponseTest(int errorResponseIndex) + { + var expectedHttpCode = DeliveryReportErrorResponses[errorResponseIndex].Item1; + var expectedMessageId = DeliveryReportErrorResponses[errorResponseIndex].Item2; + var expectedErrorPhrase = DeliveryReportErrorResponses[errorResponseIndex].Item3; + var expectedErrorText = DeliveryReportErrorResponses[errorResponseIndex].Item4; - string givenMessageId = "MSG-TEST-123"; - string givenBulkId = "BULK-1234"; - int givenLimit = 2; + var givenMessageId = "MSG-TEST-123"; + var givenBulkId = "BULK-1234"; + var givenLimit = 2; - string expectedJson = $@" + var expectedJson = $@" {{ ""requestError"": {{ ""serviceException"": {{ @@ -1317,31 +1345,32 @@ public void GetEmailDeliveryReportsResponseTest(int errorResponseIndex) }} }}"; - Dictionary responseHeaders = new Dictionary() - { - { "Server", SERVER_HEADER_VALUE_COMMA }, - { "X-Request-ID", X_REQUEST_ID_HEADER_VALUE }, - { "Content-Type", CONTENT_TYPE_HEADER_VALUE } - }; - - SetUpGetRequest(EMAIL_LOGS_ENDPOINT, expectedJson, expectedHttpCode); - - var emailApi = new EmailApi(configuration); - - try - { - var result = emailApi.GetEmailDeliveryReports(messageId: givenMessageId, bulkId: givenBulkId, limit: givenLimit); - } - catch (ApiException ex) - { - Assert.AreEqual(expectedHttpCode, ex.ErrorCode); - Assert.AreEqual(expectedJson, ex.ErrorContent); - Assert.IsInstanceOfType(ex, typeof(ApiException)); - Assert.IsTrue(ex.Message.Contains(expectedErrorPhrase)); - Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(expectedMessageId) == true); - Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(expectedErrorText) == true); - Assert.IsTrue(responseHeaders.All(h => ex.Headers.ContainsKey(h.Key) && ex.Headers[h.Key].First().Equals(h.Value))); - } + var responseHeaders = new Dictionary + { + { "Server", SERVER_HEADER_VALUE_COMMA }, + { "X-Request-ID", X_REQUEST_ID_HEADER_VALUE }, + { "Content-Type", CONTENT_TYPE_HEADER_VALUE } + }; + + SetUpGetRequest(EMAIL_LOGS_ENDPOINT, expectedJson, expectedHttpCode); + + var emailApi = new EmailApi(configuration); + + try + { + var result = + emailApi.GetEmailDeliveryReports(messageId: givenMessageId, bulkId: givenBulkId, limit: givenLimit); + } + catch (ApiException ex) + { + Assert.AreEqual(expectedHttpCode, ex.ErrorCode); + Assert.AreEqual(expectedJson, ex.ErrorContent); + Assert.IsInstanceOfType(ex, typeof(ApiException)); + Assert.IsTrue(ex.Message.Contains(expectedErrorPhrase)); + Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(expectedMessageId) == true); + Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(expectedErrorText) == true); + Assert.IsTrue(responseHeaders.All(h => + ex.Headers.ContainsKey(h.Key) && ex.Headers[h.Key].First().Equals(h.Value))); } } -} +} \ No newline at end of file diff --git a/ApiClient.Tests/Api/SmsApiTest.cs b/ApiClient.Tests/Api/SmsApiTest.cs index e0af6f2..d079f0d 100644 --- a/ApiClient.Tests/Api/SmsApiTest.cs +++ b/ApiClient.Tests/Api/SmsApiTest.cs @@ -1,58 +1,57 @@ -using Infobip.Api.Client.Api; +using System.Globalization; +using Infobip.Api.Client.Api; using Infobip.Api.Client.Model; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -namespace ApiClient.Tests.Api +namespace ApiClient.Tests.Api; + +[TestClass] +public class SmsApiTest : ApiTest { - [TestClass] - public class SmsApiTest : ApiTest + protected const string SMS_SEND_TEXT_ADVANCED_ENDPOINT = "/sms/2/text/advanced"; + protected const string SMS_SEND_BINARY_ADVANCED_ENDPOINT = "/sms/2/binary/advanced"; + protected const string SMS_LOGS_ENDPOINT = "/sms/1/logs"; + protected const string SMS_REPORTS_ENDPOINT = "/sms/1/reports"; + protected const string SMS_INBOX_REPORTS_ENDPOINT = "/sms/1/inbox/reports"; + protected const string SMS_SEND_PREVIEW_ENDPOINT = "/sms/1/preview"; + protected const string SMS_BULKS_ENDPOINT = "/sms/1/bulks"; + protected const string SMS_BULKS_STATUS_ENDPOINT = "/sms/1/bulks/status"; + + protected const int PENDING_STATUS_GROUP_ID = 1; + protected const string PENDING_STATUS_GROUP_NAME = "PENDING"; + protected const int PENDING_STATUS_ID = 26; + protected const string PENDING_STATUS_NAME = "MESSAGE_ACCEPTED"; + protected const string PENDING_STATUS_DESCRIPTION = "Message sent to next instance"; + + protected const int DELIVERED_STATUS_GROUP_ID = 3; + protected const string DELIVERED_STATUS_GROUP_NAME = "DELIVERED"; + protected const int DELIVERED_STATUS_ID = 5; + protected const string DELIVERED_STATUS_NAME = "DELIVERED_TO_HANDSET"; + protected const string DELIVERED_STATUS_DESCRIPTION = "Message delivered to handset"; + + protected const int NO_ERROR_GROUP_ID = 0; + protected const string NO_ERROR_GROUP_NAME = "Ok"; + protected const int NO_ERROR_ID = 0; + protected const string NO_ERROR_NAME = "NO_ERROR"; + protected const string NO_ERROR_DESCRIPTION = "No Error"; + protected const bool NO_ERROR_IS_PERMANENT = false; + + protected const string GIVEN_BULK_ID = "BULK-ID-123-xyz"; + protected const string GIVEN_BULK_STATUS_STRING = "PAUSED"; + protected const SmsBulkStatus GIVEN_BULK_STATUS = SmsBulkStatus.Paused; + protected const string GIVEN_SEND_AT = "2021-02-22T17:42:05.390+0100"; + protected const string GIVEN_SEND_AT_WITH_COLON = "2021-02-22T17:42:05.390+01:00"; + + [TestMethod] + public void ShouldSendSimpleSms() { - protected const string SMS_SEND_TEXT_ADVANCED_ENDPOINT = "/sms/2/text/advanced"; - protected const string SMS_SEND_BINARY_ADVANCED_ENDPOINT = "/sms/2/binary/advanced"; - protected const string SMS_LOGS_ENDPOINT = "/sms/1/logs"; - protected const string SMS_REPORTS_ENDPOINT = "/sms/1/reports"; - protected const string SMS_INBOX_REPORTS_ENDPOINT = "/sms/1/inbox/reports"; - protected const string SMS_SEND_PREVIEW_ENDPOINT = "/sms/1/preview"; - protected const string SMS_BULKS_ENDPOINT = "/sms/1/bulks"; - protected const string SMS_BULKS_STATUS_ENDPOINT = "/sms/1/bulks/status"; - - protected const int PENDING_STATUS_GROUP_ID = 1; - protected const string PENDING_STATUS_GROUP_NAME = "PENDING"; - protected const int PENDING_STATUS_ID = 26; - protected const string PENDING_STATUS_NAME = "MESSAGE_ACCEPTED"; - protected const string PENDING_STATUS_DESCRIPTION = "Message sent to next instance"; - - protected const int DELIVERED_STATUS_GROUP_ID = 3; - protected const string DELIVERED_STATUS_GROUP_NAME = "DELIVERED"; - protected const int DELIVERED_STATUS_ID = 5; - protected const string DELIVERED_STATUS_NAME = "DELIVERED_TO_HANDSET"; - protected const string DELIVERED_STATUS_DESCRIPTION = "Message delivered to handset"; - - protected const int NO_ERROR_GROUP_ID = 0; - protected const string NO_ERROR_GROUP_NAME = "Ok"; - protected const int NO_ERROR_ID = 0; - protected const string NO_ERROR_NAME = "NO_ERROR"; - protected const string NO_ERROR_DESCRIPTION = "No Error"; - protected const bool NO_ERROR_IS_PERMANENT = false; - - protected const string GIVEN_BULK_ID = "BULK-ID-123-xyz"; - protected const string GIVEN_BULK_STATUS_STRING = "PAUSED"; - protected const SmsBulkStatus GIVEN_BULK_STATUS = SmsBulkStatus.Paused; - protected const string GIVEN_SEND_AT = "2021-02-22T17:42:05.390+0100"; - protected const string GIVEN_SEND_AT_WITH_COLON = "2021-02-22T17:42:05.390+01:00"; - - [TestMethod] - public void ShouldSendSimpleSms() - { - string givenDestination = "41793026727"; - string givenFrom = "InfoSMS"; - string givenText = "This is a sample message"; - string givenMessageId = "This is a sample message"; - string givenBulkId = "2034072219640523072"; + var givenDestination = "41793026727"; + var givenFrom = "InfoSMS"; + var givenText = "This is a sample message"; + var givenMessageId = "This is a sample message"; + var givenBulkId = "2034072219640523072"; - string expectedRequest = $@" + var expectedRequest = $@" {{ ""messages"": [ {{ @@ -70,50 +69,50 @@ public void ShouldSendSimpleSms() ""includeSmsCountInResponse"":false }}"; - string expectedResponse = PreparePendingResponse(givenBulkId, givenDestination, givenMessageId); + var expectedResponse = PreparePendingResponse(givenBulkId, givenDestination, givenMessageId); - SetUpPostRequest(SMS_SEND_TEXT_ADVANCED_ENDPOINT, expectedRequest, expectedResponse, 200); + SetUpPostRequest(SMS_SEND_TEXT_ADVANCED_ENDPOINT, expectedRequest, expectedResponse, 200); - var smsApi = new SmsApi(configuration); + var smsApi = new SmsApi(configuration); - var destination = new SmsDestination(to: givenDestination); + var destination = new SmsDestination(to: givenDestination); - var smsMessage = new SmsTextualMessage( - from: givenFrom, - destinations: new List { destination }, - text: givenText - ); + var smsMessage = new SmsTextualMessage( + from: givenFrom, + destinations: new List { destination }, + text: givenText + ); - var smsRequest = new SmsAdvancedTextualRequest( - messages: new List { smsMessage } - ); + var smsRequest = new SmsAdvancedTextualRequest( + messages: new List { smsMessage } + ); - void SmsResponseAssertion(SmsResponse smsResponse) - { - Assert.IsNotNull(smsResponse); - Assert.AreEqual(givenBulkId, smsResponse.BulkId); - Assert.AreEqual(1, smsResponse.Messages.Count); - Assert.AreEqual(givenMessageId, smsResponse.Messages[0].MessageId); - } + void SmsResponseAssertion(SmsResponse smsResponse) + { + Assert.IsNotNull(smsResponse); + Assert.AreEqual(givenBulkId, smsResponse.BulkId); + Assert.AreEqual(1, smsResponse.Messages.Count); + Assert.AreEqual(givenMessageId, smsResponse.Messages[0].MessageId); + } - AssertResponse(smsApi.SendSmsMessage(smsRequest), SmsResponseAssertion); - AssertResponse(smsApi.SendSmsMessageAsync(smsRequest).Result, SmsResponseAssertion); + AssertResponse(smsApi.SendSmsMessage(smsRequest), SmsResponseAssertion); + AssertResponse(smsApi.SendSmsMessageAsync(smsRequest).Result, SmsResponseAssertion); - AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfo(smsRequest), SmsResponseAssertion); - AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfoAsync(smsRequest).Result, SmsResponseAssertion); - } + AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfo(smsRequest), SmsResponseAssertion); + AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfoAsync(smsRequest).Result, SmsResponseAssertion); + } - [TestMethod] - public void ShouldSendFlashSms() - { - string givenDestination = "41793026727"; - string givenFrom = "InfoSMS"; - string givenText = "This is a sample message"; - string givenMessageId = "This is a sample message"; - string givenBulkId = "2034072219640523072"; + [TestMethod] + public void ShouldSendFlashSms() + { + var givenDestination = "41793026727"; + var givenFrom = "InfoSMS"; + var givenText = "This is a sample message"; + var givenMessageId = "This is a sample message"; + var givenBulkId = "2034072219640523072"; - string expectedRequest = $@" + var expectedRequest = $@" {{ ""messages"": [ {{ @@ -131,58 +130,59 @@ public void ShouldSendFlashSms() ""includeSmsCountInResponse"": false }}"; - string expectedResponse = PreparePendingResponse(givenBulkId, givenDestination, givenMessageId); + var expectedResponse = PreparePendingResponse(givenBulkId, givenDestination, givenMessageId); - SetUpPostRequest(SMS_SEND_TEXT_ADVANCED_ENDPOINT, expectedRequest, expectedResponse, 200); + SetUpPostRequest(SMS_SEND_TEXT_ADVANCED_ENDPOINT, expectedRequest, expectedResponse, 200); - var smsApi = new SmsApi(configuration); + var smsApi = new SmsApi(configuration); - var destination = new SmsDestination(to: givenDestination); + var destination = new SmsDestination(to: givenDestination); - var smsMessage = new SmsTextualMessage( - from: givenFrom, - destinations: new List { destination }, - text: givenText, - flash: true - ); + var smsMessage = new SmsTextualMessage( + from: givenFrom, + destinations: new List { destination }, + text: givenText, + flash: true + ); - var smsRequest = new SmsAdvancedTextualRequest( - messages: new List { smsMessage } - ); + var smsRequest = new SmsAdvancedTextualRequest( + messages: new List { smsMessage } + ); - void SmsResponseAssertion(SmsResponse smsResponse) - { - Assert.IsNotNull(smsResponse); - Assert.AreEqual(givenBulkId, smsResponse.BulkId); - Assert.AreEqual(1, smsResponse.Messages.Count); - Assert.AreEqual(givenMessageId, smsResponse.Messages[0].MessageId); - } + void SmsResponseAssertion(SmsResponse smsResponse) + { + Assert.IsNotNull(smsResponse); + Assert.AreEqual(givenBulkId, smsResponse.BulkId); + Assert.AreEqual(1, smsResponse.Messages.Count); + Assert.AreEqual(givenMessageId, smsResponse.Messages[0].MessageId); + } - AssertResponse(smsApi.SendSmsMessage(smsRequest), SmsResponseAssertion); - AssertResponse(smsApi.SendSmsMessageAsync(smsRequest).Result, SmsResponseAssertion); + AssertResponse(smsApi.SendSmsMessage(smsRequest), SmsResponseAssertion); + AssertResponse(smsApi.SendSmsMessageAsync(smsRequest).Result, SmsResponseAssertion); - AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfo(smsRequest), SmsResponseAssertion); - AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfoAsync(smsRequest).Result, SmsResponseAssertion); - } + AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfo(smsRequest), SmsResponseAssertion); + AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfoAsync(smsRequest).Result, SmsResponseAssertion); + } - [TestMethod] - public void ShouldSendFullyFeaturedSmsMessage() - { - string givenFromMessage1 = "InfoSMS"; - string givenToMessage1 = "41793026727"; - string givenMessageIdMessage1 = "MESSAGE-ID-123-xyz"; - string givenAnotherToMessage1 = "41793026834"; - string givenTextMessage1 = "Artık Ulusal Dil Tanımlayıcısı ile Türkçe karakterli smslerinizi rahatlıkla iletebilirsiniz."; - bool givenFlashMessage1 = false; - string givenLanguageCodeMessage1 = "TR"; - string givenTransliterationMessage1 = "TURKISH"; - bool givenIntermediateReportMessage1 = true; - string givenNotifyUrlMessage1 = "https://www.example.com/sms/advanced"; - string givenNotifyContentTypeMessage1 = "application/json"; - string givenCallbackDataMessage1 = "DLR callback data"; - long givenValidityPeriodMessage1 = 720L; - - string expectedMessage1 = $@" + [TestMethod] + public void ShouldSendFullyFeaturedSmsMessage() + { + var givenFromMessage1 = "InfoSMS"; + var givenToMessage1 = "41793026727"; + var givenMessageIdMessage1 = "MESSAGE-ID-123-xyz"; + var givenAnotherToMessage1 = "41793026834"; + var givenTextMessage1 = + "Artık Ulusal Dil Tanımlayıcısı ile Türkçe karakterli smslerinizi rahatlıkla iletebilirsiniz."; + var givenFlashMessage1 = false; + var givenLanguageCodeMessage1 = "TR"; + var givenTransliterationMessage1 = "TURKISH"; + var givenIntermediateReportMessage1 = true; + var givenNotifyUrlMessage1 = "https://www.example.com/sms/advanced"; + var givenNotifyContentTypeMessage1 = "application/json"; + var givenCallbackDataMessage1 = "DLR callback data"; + var givenValidityPeriodMessage1 = 720L; + + var expectedMessage1 = $@" {{ ""destinations"": [ {{ @@ -207,18 +207,18 @@ public void ShouldSendFullyFeaturedSmsMessage() ""validityPeriod"": {givenValidityPeriodMessage1} }}"; - string givenFromMessage2 = "41793026700"; - string givenToMessage2 = "41793026700"; - string givenTextMessage2 = "A long time ago, in a galaxy far, far away..."; - string givenSendAtMessage2 = "2021-08-25T16:10:00.000+05:30"; - int givenDeliveryTimeFromHourMessage2 = 6; - int givenDeliveryTimeFromMinuteMessage2 = 0; - int givenDeliveryTimeToHourMessage2 = 15; - int givenDeliveryTimeToMinuteMessage2 = 30; - string givenContentTemplateIdMessage2 = "contentTemplateId"; - string givenPrincipalEntityIdMessage2 = "givenPrincipalEntityId"; - - string expectedMessage2 = $@" + var givenFromMessage2 = "41793026700"; + var givenToMessage2 = "41793026700"; + var givenTextMessage2 = "A long time ago, in a galaxy far, far away..."; + var givenSendAtMessage2 = "2021-08-25T16:10:00.000+05:30"; + var givenDeliveryTimeFromHourMessage2 = 6; + var givenDeliveryTimeFromMinuteMessage2 = 0; + var givenDeliveryTimeToHourMessage2 = 15; + var givenDeliveryTimeToMinuteMessage2 = 30; + var givenContentTemplateIdMessage2 = "contentTemplateId"; + var givenPrincipalEntityIdMessage2 = "givenPrincipalEntityId"; + + var expectedMessage2 = $@" {{ ""destinations"": [ {{ @@ -252,13 +252,13 @@ public void ShouldSendFullyFeaturedSmsMessage() }} }}"; - string givenBulkId = "BULK-ID-123-xyz"; - string givenTracking = "SMS"; - string givenTrackingType = "MY_CAMPAIGN"; - int givenSendingSpeedLimitAmount = 10; - string givenSendingSpeedLimitTimeUnitString = "HOUR"; + var givenBulkId = "BULK-ID-123-xyz"; + var givenTracking = "SMS"; + var givenTrackingType = "MY_CAMPAIGN"; + var givenSendingSpeedLimitAmount = 10; + var givenSendingSpeedLimitTimeUnitString = "HOUR"; - string expectedRequest = $@" + var expectedRequest = $@" {{ ""messages"": [ {expectedMessage1}, @@ -276,104 +276,97 @@ public void ShouldSendFullyFeaturedSmsMessage() ""includeSmsCountInResponse"":false }}"; - string givenMessageIdMessage2 = "2033247207850523792"; - - string expectedResponse = PreparePendingResponse(givenBulkId, givenToMessage1, givenMessageIdMessage1, givenToMessage2, givenMessageIdMessage2); - SetUpPostRequest(SMS_SEND_TEXT_ADVANCED_ENDPOINT, expectedRequest, expectedResponse, 200); - - var smsApi = new SmsApi(configuration); - - var destination1 = new SmsDestination(messageId: givenMessageIdMessage1, to: givenToMessage1); - var anotherDestination1 = new SmsDestination(to: givenAnotherToMessage1); - - var destination2 = new SmsDestination(to: givenToMessage2); - - var smsMessage1 = new SmsTextualMessage( - from: givenFromMessage1, - destinations: new List { destination1, anotherDestination1 }, - text: givenTextMessage1, - flash: givenFlashMessage1, - language: new SmsLanguage(givenLanguageCodeMessage1), - transliteration: givenTransliterationMessage1, - intermediateReport: givenIntermediateReportMessage1, - notifyUrl: givenNotifyUrlMessage1, - notifyContentType: givenNotifyContentTypeMessage1, - callbackData: givenCallbackDataMessage1, - validityPeriod: givenValidityPeriodMessage1 - ); - - var smsMessage2 = new SmsTextualMessage( - from: givenFromMessage2, - destinations: new List { destination2 }, - text: givenTextMessage2, - sendAt: DateTimeOffset.Parse(givenSendAtMessage2), - deliveryTimeWindow: new SmsDeliveryTimeWindow( - days: new List { SmsDeliveryDay.Monday, SmsDeliveryDay.Tuesday, SmsDeliveryDay.Wednesday }, - from: new SmsDeliveryTimeFrom(givenDeliveryTimeFromHourMessage2, givenDeliveryTimeFromMinuteMessage2), - to: new SmsDeliveryTimeTo(givenDeliveryTimeToHourMessage2, givenDeliveryTimeToMinuteMessage2) - ), - regional: new SmsRegionalOptions( - indiaDlt: new SmsIndiaDltOptions(givenContentTemplateIdMessage2, givenPrincipalEntityIdMessage2) - ) - ); - - var smsRequest = new SmsAdvancedTextualRequest( - messages: new List { smsMessage1, smsMessage2 }, - bulkId: givenBulkId, - tracking: new SmsTracking( - track: givenTracking, - type: givenTrackingType - ), - sendingSpeedLimit: new SmsSendingSpeedLimit( - amount: givenSendingSpeedLimitAmount, - timeUnit: SmsSpeedLimitTimeUnit.Hour - ) - ); - - void SmsResponseAssertion(SmsResponse smsResponse) - { - Assert.IsNotNull(smsResponse); - Assert.AreEqual(givenBulkId, smsResponse.BulkId); - Assert.AreEqual(2, smsResponse.Messages.Count); - - Assert.AreEqual(givenMessageIdMessage1, smsResponse.Messages[0].MessageId); - Assert.AreEqual(givenToMessage1, smsResponse.Messages[0].To); + var givenMessageIdMessage2 = "2033247207850523792"; + + var expectedResponse = PreparePendingResponse(givenBulkId, givenToMessage1, givenMessageIdMessage1, + givenToMessage2, givenMessageIdMessage2); + SetUpPostRequest(SMS_SEND_TEXT_ADVANCED_ENDPOINT, expectedRequest, expectedResponse, 200); + + var smsApi = new SmsApi(configuration); + + var destination1 = new SmsDestination(givenMessageIdMessage1, givenToMessage1); + var anotherDestination1 = new SmsDestination(to: givenAnotherToMessage1); + + var destination2 = new SmsDestination(to: givenToMessage2); + + var smsMessage1 = new SmsTextualMessage( + from: givenFromMessage1, + destinations: new List { destination1, anotherDestination1 }, + text: givenTextMessage1, + flash: givenFlashMessage1, + language: new SmsLanguage(givenLanguageCodeMessage1), + transliteration: givenTransliterationMessage1, + intermediateReport: givenIntermediateReportMessage1, + notifyUrl: givenNotifyUrlMessage1, + notifyContentType: givenNotifyContentTypeMessage1, + callbackData: givenCallbackDataMessage1, + validityPeriod: givenValidityPeriodMessage1 + ); + + var smsMessage2 = new SmsTextualMessage( + from: givenFromMessage2, + destinations: new List { destination2 }, + text: givenTextMessage2, + sendAt: DateTimeOffset.Parse(givenSendAtMessage2), + deliveryTimeWindow: new SmsDeliveryTimeWindow( + new List { SmsDeliveryDay.Monday, SmsDeliveryDay.Tuesday, SmsDeliveryDay.Wednesday }, + new SmsDeliveryTimeFrom(givenDeliveryTimeFromHourMessage2, givenDeliveryTimeFromMinuteMessage2), + new SmsDeliveryTimeTo(givenDeliveryTimeToHourMessage2, givenDeliveryTimeToMinuteMessage2) + ), + regional: new SmsRegionalOptions( + new SmsIndiaDltOptions(givenContentTemplateIdMessage2, givenPrincipalEntityIdMessage2) + ) + ); + + var smsRequest = new SmsAdvancedTextualRequest( + messages: new List { smsMessage1, smsMessage2 }, + bulkId: givenBulkId, + tracking: new SmsTracking( + track: givenTracking, + type: givenTrackingType + ), + sendingSpeedLimit: new SmsSendingSpeedLimit( + givenSendingSpeedLimitAmount, + SmsSpeedLimitTimeUnit.Hour + ) + ); + + void SmsResponseAssertion(SmsResponse smsResponse) + { + Assert.IsNotNull(smsResponse); + Assert.AreEqual(givenBulkId, smsResponse.BulkId); + Assert.AreEqual(2, smsResponse.Messages.Count); - AssertPendingSmsResponse(smsResponse.Messages[0]); - } + Assert.AreEqual(givenMessageIdMessage1, smsResponse.Messages[0].MessageId); + Assert.AreEqual(givenToMessage1, smsResponse.Messages[0].To); - try - { - AssertResponse(smsApi.SendSmsMessage(smsRequest), SmsResponseAssertion); - AssertResponse(smsApi.SendSmsMessageAsync(smsRequest).Result, SmsResponseAssertion); + AssertPendingSmsResponse(smsResponse.Messages[0]); + } - AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfo(smsRequest), SmsResponseAssertion); - AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfoAsync(smsRequest).Result, SmsResponseAssertion); - } - catch (Exception) - { - throw; - } + AssertResponse(smsApi.SendSmsMessage(smsRequest), SmsResponseAssertion); + AssertResponse(smsApi.SendSmsMessageAsync(smsRequest).Result, SmsResponseAssertion); - } + AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfo(smsRequest), SmsResponseAssertion); + AssertResponseWithHttpInfo(smsApi.SendSmsMessageWithHttpInfoAsync(smsRequest).Result, SmsResponseAssertion); + } - [TestMethod] - public void ShouldSendFullyFeaturedBinaryMessage() - { - string givenFromMessage1 = "InfoSMS"; - string givenToMessage1 = "41793026727"; - string givenMessageIdMessage1 = "MESSAGE-ID-123-xyz"; - string givenAnotherToMessage1 = "41793026834"; - string givenHexMessage1 = "54 65 73 74 20 6d 65 73 73 61 67 65 2e"; - int givenDataCodingMessage1 = 0; - int givenEsmClassMessage1 = 0; - bool givenIntermediateReportMessage1 = true; - string givenNotifyUrlMessage1 = "https://www.example.com/sms/advanced"; - string givenNotifyContentTypeMessage1 = "application/json"; - string givenCallbackDataMessage1 = "DLR callback data"; - long givenValidityPeriodMessage1 = 720L; - - string expectedMessage1 = $@" + [TestMethod] + public void ShouldSendFullyFeaturedBinaryMessage() + { + var givenFromMessage1 = "InfoSMS"; + var givenToMessage1 = "41793026727"; + var givenMessageIdMessage1 = "MESSAGE-ID-123-xyz"; + var givenAnotherToMessage1 = "41793026834"; + var givenHexMessage1 = "54 65 73 74 20 6d 65 73 73 61 67 65 2e"; + var givenDataCodingMessage1 = 0; + var givenEsmClassMessage1 = 0; + var givenIntermediateReportMessage1 = true; + var givenNotifyUrlMessage1 = "https://www.example.com/sms/advanced"; + var givenNotifyContentTypeMessage1 = "application/json"; + var givenCallbackDataMessage1 = "DLR callback data"; + var givenValidityPeriodMessage1 = 720L; + + var expectedMessage1 = $@" {{ ""destinations"": [ {{ @@ -396,20 +389,20 @@ public void ShouldSendFullyFeaturedBinaryMessage() ""validityPeriod"": {givenValidityPeriodMessage1} }}"; - string givenFromMessage2 = "41793026700"; - string givenToMessage2 = "41793026700"; - string givenHexMessage2 = "54 65 73 74 20 6d 65 73 73 61 67 65 2e"; - int givenDataCodingMessage2 = 0; - int givenEsmClassMessage2 = 0; - string givenSendAtMessage2 = "2021-08-25T16:10:00.000+05:00"; - int givenDeliveryTimeFromHourMessage2 = 6; - int givenDeliveryTimeFromMinuteMessage2 = 0; - int givenDeliveryTimeToHourMessage2 = 15; - int givenDeliveryTimeToMinuteMessage2 = 30; - string givenContentTemplateIdMessage2 = "contentTemplateId"; - string givenPrincipalEntityIdMessage2 = "givenPrincipalEntityId"; - - string expectedMessage2 = $@" + var givenFromMessage2 = "41793026700"; + var givenToMessage2 = "41793026700"; + var givenHexMessage2 = "54 65 73 74 20 6d 65 73 73 61 67 65 2e"; + var givenDataCodingMessage2 = 0; + var givenEsmClassMessage2 = 0; + var givenSendAtMessage2 = "2021-08-25T16:10:00.000+05:00"; + var givenDeliveryTimeFromHourMessage2 = 6; + var givenDeliveryTimeFromMinuteMessage2 = 0; + var givenDeliveryTimeToHourMessage2 = 15; + var givenDeliveryTimeToMinuteMessage2 = 30; + var givenContentTemplateIdMessage2 = "contentTemplateId"; + var givenPrincipalEntityIdMessage2 = "givenPrincipalEntityId"; + + var expectedMessage2 = $@" {{ ""destinations"": [ {{ @@ -445,11 +438,11 @@ public void ShouldSendFullyFeaturedBinaryMessage() }} }}"; - string givenBulkId = "BULK-ID-123-xyz"; - int givenSendingSpeedLimitAmount = 10; - string givenSendingSpeedLimitTimeUnitString = "HOUR"; + var givenBulkId = "BULK-ID-123-xyz"; + var givenSendingSpeedLimitAmount = 10; + var givenSendingSpeedLimitTimeUnitString = "HOUR"; - string expectedRequest = $@" + var expectedRequest = $@" {{ ""messages"": [ {expectedMessage1}, @@ -462,103 +455,99 @@ public void ShouldSendFullyFeaturedBinaryMessage() }} }}"; - string givenMessageIdMessage2 = "2033247207850523792"; - - string expectedResponse = PreparePendingResponse(givenBulkId, givenToMessage1, givenMessageIdMessage1, givenToMessage2, givenMessageIdMessage2); - SetUpPostRequest(SMS_SEND_BINARY_ADVANCED_ENDPOINT, expectedRequest, expectedResponse, 200); - - var smsApi = new SmsApi(configuration); - - var destination1 = new SmsDestination(messageId: givenMessageIdMessage1, to: givenToMessage1); - var anotherDestination1 = new SmsDestination(to: givenAnotherToMessage1); - - var destination2 = new SmsDestination(to: givenToMessage2); - - var smsMessage1 = new SmsBinaryMessage( - from: givenFromMessage1, - destinations: new List { destination1, anotherDestination1 }, - binary: new SmsBinaryContent - ( - hex: givenHexMessage1, - dataCoding: givenDataCodingMessage1, - esmClass: givenEsmClassMessage1 - ), - intermediateReport: givenIntermediateReportMessage1, - notifyUrl: givenNotifyUrlMessage1, - notifyContentType: givenNotifyContentTypeMessage1, - callbackData: givenCallbackDataMessage1, - validityPeriod: givenValidityPeriodMessage1 - ); - - var smsMessage2 = new SmsBinaryMessage( - from: givenFromMessage2, - destinations: new List { destination2 }, - binary: new SmsBinaryContent - ( - hex: givenHexMessage2, - dataCoding: givenDataCodingMessage2, - esmClass: givenEsmClassMessage2 - ), - sendAt: DateTimeOffset.Parse(givenSendAtMessage2), - deliveryTimeWindow: new SmsDeliveryTimeWindow( - days: new List { SmsDeliveryDay.Monday, SmsDeliveryDay.Tuesday, SmsDeliveryDay.Wednesday }, - from: new SmsDeliveryTimeFrom(givenDeliveryTimeFromHourMessage2, givenDeliveryTimeFromMinuteMessage2), - to: new SmsDeliveryTimeTo(givenDeliveryTimeToHourMessage2, givenDeliveryTimeToMinuteMessage2) - ), - regional: new SmsRegionalOptions( - indiaDlt: new SmsIndiaDltOptions(givenContentTemplateIdMessage2, givenPrincipalEntityIdMessage2) - ) - ); - - var smsRequest = new SmsAdvancedBinaryRequest - ( - messages: new List { smsMessage1, smsMessage2 }, - bulkId: givenBulkId, - sendingSpeedLimit: new SmsSendingSpeedLimit - { - Amount = givenSendingSpeedLimitAmount, - TimeUnit = SmsSpeedLimitTimeUnit.Hour - } - ); - - void SmsResponseAssertion(SmsResponse smsResponse) - { - Assert.IsNotNull(smsResponse); - Assert.AreEqual(givenBulkId, smsResponse.BulkId); - Assert.AreEqual(2, smsResponse.Messages.Count); + var givenMessageIdMessage2 = "2033247207850523792"; - Assert.AreEqual(givenMessageIdMessage1, smsResponse.Messages[0].MessageId); - Assert.AreEqual(givenToMessage1, smsResponse.Messages[0].To); + var expectedResponse = PreparePendingResponse(givenBulkId, givenToMessage1, givenMessageIdMessage1, + givenToMessage2, givenMessageIdMessage2); + SetUpPostRequest(SMS_SEND_BINARY_ADVANCED_ENDPOINT, expectedRequest, expectedResponse, 200); - AssertPendingSmsResponse(smsResponse.Messages[0]); - } + var smsApi = new SmsApi(configuration); - try - { - AssertResponse(smsApi.SendBinarySmsMessage(smsRequest), SmsResponseAssertion); - AssertResponse(smsApi.SendBinarySmsMessageAsync(smsRequest).Result, SmsResponseAssertion); + var destination1 = new SmsDestination(givenMessageIdMessage1, givenToMessage1); + var anotherDestination1 = new SmsDestination(to: givenAnotherToMessage1); - AssertResponseWithHttpInfo(smsApi.SendBinarySmsMessageWithHttpInfo(smsRequest), SmsResponseAssertion); - AssertResponseWithHttpInfo(smsApi.SendBinarySmsMessageWithHttpInfoAsync(smsRequest).Result, SmsResponseAssertion); - } - catch (Exception) + var destination2 = new SmsDestination(to: givenToMessage2); + + var smsMessage1 = new SmsBinaryMessage( + from: givenFromMessage1, + destinations: new List { destination1, anotherDestination1 }, + binary: new SmsBinaryContent + ( + hex: givenHexMessage1, + dataCoding: givenDataCodingMessage1, + esmClass: givenEsmClassMessage1 + ), + intermediateReport: givenIntermediateReportMessage1, + notifyUrl: givenNotifyUrlMessage1, + notifyContentType: givenNotifyContentTypeMessage1, + callbackData: givenCallbackDataMessage1, + validityPeriod: givenValidityPeriodMessage1 + ); + + var smsMessage2 = new SmsBinaryMessage( + from: givenFromMessage2, + destinations: new List { destination2 }, + binary: new SmsBinaryContent + ( + hex: givenHexMessage2, + dataCoding: givenDataCodingMessage2, + esmClass: givenEsmClassMessage2 + ), + sendAt: DateTimeOffset.Parse(givenSendAtMessage2), + deliveryTimeWindow: new SmsDeliveryTimeWindow( + new List { SmsDeliveryDay.Monday, SmsDeliveryDay.Tuesday, SmsDeliveryDay.Wednesday }, + new SmsDeliveryTimeFrom(givenDeliveryTimeFromHourMessage2, givenDeliveryTimeFromMinuteMessage2), + new SmsDeliveryTimeTo(givenDeliveryTimeToHourMessage2, givenDeliveryTimeToMinuteMessage2) + ), + regional: new SmsRegionalOptions( + new SmsIndiaDltOptions(givenContentTemplateIdMessage2, givenPrincipalEntityIdMessage2) + ) + ); + + var smsRequest = new SmsAdvancedBinaryRequest + ( + messages: new List { smsMessage1, smsMessage2 }, + bulkId: givenBulkId, + sendingSpeedLimit: new SmsSendingSpeedLimit { - throw; + Amount = givenSendingSpeedLimitAmount, + TimeUnit = SmsSpeedLimitTimeUnit.Hour } - } + ); - [TestMethod] - public void ShouldSendFlashBinarySms() + void SmsResponseAssertion(SmsResponse smsResponse) { - string givenBulkId = "2034072219640523072"; - string givenTo = "41793026727"; - string givenMessageId = "2250be2d4219-3af1-78856-aabe-1362af1edfd2"; + Assert.IsNotNull(smsResponse); + Assert.AreEqual(givenBulkId, smsResponse.BulkId); + Assert.AreEqual(2, smsResponse.Messages.Count); + + Assert.AreEqual(givenMessageIdMessage1, smsResponse.Messages[0].MessageId); + Assert.AreEqual(givenToMessage1, smsResponse.Messages[0].To); + + AssertPendingSmsResponse(smsResponse.Messages[0]); + } + + AssertResponse(smsApi.SendBinarySmsMessage(smsRequest), SmsResponseAssertion); + AssertResponse(smsApi.SendBinarySmsMessageAsync(smsRequest).Result, SmsResponseAssertion); - string givenFrom = "InfoSMS"; - string givenHex = "0048 0065 006c 006c 006f 0020 0077 006f 0072 006c 0064 002c 0020 039a 03b1 03bb 03b7 03bc 03ad 03c1 03b1 0020 03ba 03cc 03c3 03bc 03b5 002c 0020 30b3 30f3 30cb 30c1 30cf"; - bool isFlash = true; + AssertResponseWithHttpInfo(smsApi.SendBinarySmsMessageWithHttpInfo(smsRequest), SmsResponseAssertion); + AssertResponseWithHttpInfo(smsApi.SendBinarySmsMessageWithHttpInfoAsync(smsRequest).Result, + SmsResponseAssertion); + } + + [TestMethod] + public void ShouldSendFlashBinarySms() + { + var givenBulkId = "2034072219640523072"; + var givenTo = "41793026727"; + var givenMessageId = "2250be2d4219-3af1-78856-aabe-1362af1edfd2"; - string expectedMessage = $@" + var givenFrom = "InfoSMS"; + var givenHex = + "0048 0065 006c 006c 006f 0020 0077 006f 0072 006c 0064 002c 0020 039a 03b1 03bb 03b7 03bc 03ad 03c1 03b1 0020 03ba 03cc 03c3 03bc 03b5 002c 0020 30b3 30f3 30cb 30c1 30cf"; + var isFlash = true; + + var expectedMessage = $@" {{ ""destinations"": [ {{ @@ -573,77 +562,71 @@ public void ShouldSendFlashBinarySms() }} }}"; - string expectedRequest = $@" + var expectedRequest = $@" {{ ""messages"": [ {expectedMessage} ] }}"; - string expectedResponse = PreparePendingResponse(givenBulkId, givenTo, givenMessageId); - SetUpPostRequest(SMS_SEND_BINARY_ADVANCED_ENDPOINT, expectedRequest, expectedResponse, 200); + var expectedResponse = PreparePendingResponse(givenBulkId, givenTo, givenMessageId); + SetUpPostRequest(SMS_SEND_BINARY_ADVANCED_ENDPOINT, expectedRequest, expectedResponse, 200); - var smsApi = new SmsApi(configuration); + var smsApi = new SmsApi(configuration); - var binaryMessage = new SmsBinaryMessage( - from: givenFrom, - destinations: new List { new SmsDestination(to: givenTo) }, - binary: new SmsBinaryContent(hex: givenHex), - flash: isFlash - ); + var binaryMessage = new SmsBinaryMessage( + from: givenFrom, + destinations: new List { new(to: givenTo) }, + binary: new SmsBinaryContent(hex: givenHex), + flash: isFlash + ); - var smsRequest = new SmsAdvancedBinaryRequest - ( - messages: new List { binaryMessage } - ); + var smsRequest = new SmsAdvancedBinaryRequest + ( + messages: new List { binaryMessage } + ); - void SmsResponseAssertion(SmsResponse smsResponse) - { - Assert.IsNotNull(smsResponse); - Assert.AreEqual(givenBulkId, smsResponse.BulkId); - Assert.AreEqual(1, smsResponse.Messages.Count); + void SmsResponseAssertion(SmsResponse smsResponse) + { + Assert.IsNotNull(smsResponse); + Assert.AreEqual(givenBulkId, smsResponse.BulkId); + Assert.AreEqual(1, smsResponse.Messages.Count); - Assert.AreEqual(givenMessageId, smsResponse.Messages[0].MessageId); - Assert.AreEqual(givenTo, smsResponse.Messages[0].To); + Assert.AreEqual(givenMessageId, smsResponse.Messages[0].MessageId); + Assert.AreEqual(givenTo, smsResponse.Messages[0].To); - AssertPendingSmsResponse(smsResponse.Messages[0]); - } + AssertPendingSmsResponse(smsResponse.Messages[0]); + } - try - { - AssertResponse(smsApi.SendBinarySmsMessage(smsRequest), SmsResponseAssertion); - AssertResponse(smsApi.SendBinarySmsMessageAsync(smsRequest).Result, SmsResponseAssertion); + AssertResponse(smsApi.SendBinarySmsMessage(smsRequest), SmsResponseAssertion); + AssertResponse(smsApi.SendBinarySmsMessageAsync(smsRequest).Result, SmsResponseAssertion); - AssertResponseWithHttpInfo(smsApi.SendBinarySmsMessageWithHttpInfo(smsRequest), SmsResponseAssertion); - AssertResponseWithHttpInfo(smsApi.SendBinarySmsMessageWithHttpInfoAsync(smsRequest).Result, SmsResponseAssertion); - } - catch (Exception) - { - throw; - } - } + AssertResponseWithHttpInfo(smsApi.SendBinarySmsMessageWithHttpInfo(smsRequest), SmsResponseAssertion); + AssertResponseWithHttpInfo(smsApi.SendBinarySmsMessageWithHttpInfoAsync(smsRequest).Result, + SmsResponseAssertion); + } - [TestMethod] - public void ShouldGetSmsLogs() - { - string givenBulkId = "BULK-ID-123-xyz"; - string givenMessageIdMessage1 = "MESSAGE-ID-123-xyz"; - string givenToMessage1 = "41793026727"; - string givenSendAtMessage1 = "2019-11-09T16:00:00.000+0530"; - string givenDoneAtMessage1 = "2019-11-09T16:00:00.000+0530"; - int givenSmsCountMessage1 = 1; - string givenPricePerMessageMessage1 = "0.01"; - string givenCurrencyMessage1 = "EUR"; - - string givenMessageIdMessage2 = "12db39c3-7822-4e72-a3ec-c87442c0ffc5"; - string givenToMessage2 = "41793026834"; - string givenSendAtMessage2 = "2019-11-09T17:00:00.000+0000"; - string givenDoneAtMessage2 = "2019-11-09T17:00:00.000+0000"; - int givenSmsCountMessage2 = 5; - string givenPricePerMessageMessage2 = "0.05"; - string givenCurrencyMessage2 = "HRK"; - - string givenResponse = $@" + [TestMethod] + public void ShouldGetSmsLogs() + { + var givenBulkId = "BULK-ID-123-xyz"; + var givenMessageIdMessage1 = "MESSAGE-ID-123-xyz"; + var givenToMessage1 = "41793026727"; + var givenSendAtMessage1 = "2019-11-09T16:00:00.000+0530"; + var givenDoneAtMessage1 = "2019-11-09T16:00:00.000+0530"; + var givenSmsCountMessage1 = 1; + var givenPricePerMessageMessage1 = "0.01"; + var givenCurrencyMessage1 = "EUR"; + + var givenMessageIdMessage2 = "12db39c3-7822-4e72-a3ec-c87442c0ffc5"; + var givenToMessage2 = "41793026834"; + var givenSendAtMessage2 = "2019-11-09T17:00:00.000+0000"; + var givenDoneAtMessage2 = "2019-11-09T17:00:00.000+0000"; + var givenSmsCountMessage2 = 5; + var givenPricePerMessageMessage2 = "0.05"; + var givenCurrencyMessage2 = "HRK"; + + var givenResponse = $@" {{ ""results"": [ {{ @@ -711,112 +694,114 @@ public void ShouldGetSmsLogs() ] }}"; - string givenSentSinceString = "2015-02-22T17:42:05.390+0100"; - var searchParams = new Dictionary - { - { "bulkId", givenBulkId }, - { "sentSince", givenSentSinceString } - }; + var givenSentSinceString = "2015-02-22T17:42:05.390+0100"; + var searchParams = new Dictionary + { + { "bulkId", givenBulkId }, + { "sentSince", givenSentSinceString } + }; - SetUpGetRequest(SMS_LOGS_ENDPOINT, searchParams, givenResponse, 200); + SetUpGetRequest(SMS_LOGS_ENDPOINT, searchParams, givenResponse, 200); - void LogsResponseAssertion(SmsLogsResponse logsResponse) - { - Assert.IsNotNull(logsResponse); - List results = logsResponse.Results; - Assert.IsNotNull(results); - Assert.AreEqual(2, results.Count); - - Assert.AreEqual(givenBulkId, results[0].BulkId); - Assert.AreEqual(givenMessageIdMessage1, results[0].MessageId); - Assert.AreEqual(givenToMessage1, results[0].To); - Assert.AreEqual(DateTimeOffset.Parse(givenSendAtMessage1), results[0].SentAt); - Assert.AreEqual(DateTimeOffset.Parse(givenDoneAtMessage1), results[0].DoneAt); - Assert.IsNull(results[0].From); - Assert.IsNull(results[0].Text); - Assert.IsNull(results[0].MccMnc); - Assert.AreEqual(decimal.Parse(givenPricePerMessageMessage1, System.Globalization.CultureInfo.InvariantCulture), results[0].Price.PricePerMessage); - Assert.AreEqual(givenCurrencyMessage1, results[0].Price.Currency); - AssertDeliveredSmsStatus(results[0].Status); - AssertNoError(results[0].Error); - - Assert.AreEqual(givenBulkId, results[1].BulkId); - Assert.AreEqual(givenMessageIdMessage2, results[1].MessageId); - Assert.AreEqual(givenToMessage2, results[1].To); - Assert.AreEqual(DateTimeOffset.Parse(givenSendAtMessage2), results[1].SentAt); - Assert.AreEqual(DateTimeOffset.Parse(givenDoneAtMessage2), results[1].DoneAt); - Assert.IsNull(results[1].From); - Assert.IsNull(results[1].Text); - Assert.IsNull(results[1].MccMnc); - Assert.AreEqual(decimal.Parse(givenPricePerMessageMessage2, System.Globalization.CultureInfo.InvariantCulture), results[1].Price.PricePerMessage); - Assert.AreEqual(givenCurrencyMessage2, results[1].Price.Currency); - AssertDeliveredSmsStatus(results[1].Status); - AssertNoError(results[1].Error); - } - SmsApi smsApi = new SmsApi(configuration); + void LogsResponseAssertion(SmsLogsResponse logsResponse) + { + Assert.IsNotNull(logsResponse); + List results = logsResponse.Results; + Assert.IsNotNull(results); + Assert.AreEqual(2, results.Count); + + Assert.AreEqual(givenBulkId, results[0].BulkId); + Assert.AreEqual(givenMessageIdMessage1, results[0].MessageId); + Assert.AreEqual(givenToMessage1, results[0].To); + Assert.AreEqual(DateTimeOffset.Parse(givenSendAtMessage1), results[0].SentAt); + Assert.AreEqual(DateTimeOffset.Parse(givenDoneAtMessage1), results[0].DoneAt); + Assert.IsNull(results[0].From); + Assert.IsNull(results[0].Text); + Assert.IsNull(results[0].MccMnc); + Assert.AreEqual(decimal.Parse(givenPricePerMessageMessage1, CultureInfo.InvariantCulture), + results[0].Price.PricePerMessage); + Assert.AreEqual(givenCurrencyMessage1, results[0].Price.Currency); + AssertDeliveredSmsStatus(results[0].Status); + AssertNoError(results[0].Error); + + Assert.AreEqual(givenBulkId, results[1].BulkId); + Assert.AreEqual(givenMessageIdMessage2, results[1].MessageId); + Assert.AreEqual(givenToMessage2, results[1].To); + Assert.AreEqual(DateTimeOffset.Parse(givenSendAtMessage2), results[1].SentAt); + Assert.AreEqual(DateTimeOffset.Parse(givenDoneAtMessage2), results[1].DoneAt); + Assert.IsNull(results[1].From); + Assert.IsNull(results[1].Text); + Assert.IsNull(results[1].MccMnc); + Assert.AreEqual(decimal.Parse(givenPricePerMessageMessage2, CultureInfo.InvariantCulture), + results[1].Price.PricePerMessage); + Assert.AreEqual(givenCurrencyMessage2, results[1].Price.Currency); + AssertDeliveredSmsStatus(results[1].Status); + AssertNoError(results[1].Error); + } - AssertResponse + var smsApi = new SmsApi(configuration); + + AssertResponse + ( + smsApi.GetOutboundSmsMessageLogs ( - smsApi.GetOutboundSmsMessageLogs - ( - sentSince: DateTimeOffset.Parse(givenSentSinceString), - bulkId: new List { givenBulkId } - ), - LogsResponseAssertion - ); - AssertResponse + sentSince: DateTimeOffset.Parse(givenSentSinceString), + bulkId: new List { givenBulkId } + ), + LogsResponseAssertion + ); + AssertResponse + ( + smsApi.GetOutboundSmsMessageLogsAsync ( - smsApi.GetOutboundSmsMessageLogsAsync - ( - sentSince: DateTimeOffset.Parse(givenSentSinceString), - bulkId: new List { givenBulkId } - ).Result, - LogsResponseAssertion - ); - AssertResponseWithHttpInfo + sentSince: DateTimeOffset.Parse(givenSentSinceString), + bulkId: new List { givenBulkId } + ).Result, + LogsResponseAssertion + ); + AssertResponseWithHttpInfo + ( + smsApi.GetOutboundSmsMessageLogsWithHttpInfo ( - smsApi.GetOutboundSmsMessageLogsWithHttpInfo - ( - sentSince: DateTimeOffset.Parse(givenSentSinceString), - bulkId: new List { givenBulkId } - ), - LogsResponseAssertion - ); - AssertResponseWithHttpInfo + sentSince: DateTimeOffset.Parse(givenSentSinceString), + bulkId: new List { givenBulkId } + ), + LogsResponseAssertion + ); + AssertResponseWithHttpInfo + ( + smsApi.GetOutboundSmsMessageLogsWithHttpInfoAsync ( - smsApi.GetOutboundSmsMessageLogsWithHttpInfoAsync - ( - sentSince: DateTimeOffset.Parse(givenSentSinceString), - bulkId: new List { givenBulkId } - ).Result, - LogsResponseAssertion - ); - - } + sentSince: DateTimeOffset.Parse(givenSentSinceString), + bulkId: new List { givenBulkId } + ).Result, + LogsResponseAssertion + ); + } - [TestMethod] - public void ShouldGetSmsReports() - { - string givenBulkId = "BULK-ID-123-xyz"; - string givenMessageId1 = "MESSAGE-ID-123-xyz"; - string givenTo1 = "41793026727"; - string givenSentAt1 = "2019-11-09T16:00:00.000+0000"; - string givenDoneAt1 = "2019-11-09T16:00:00.000+0000"; - int givenSmsCount = 1; - string givenPricePerMessage = "0.01"; - string givenCurrency = "EUR"; - string givenEntityId = "promotional-traffic-entity"; - string givenApplicationId1 = "marketing-automation-application"; - - string givenMessageId2 = "12db39c3-7822-4e72-a3ec-c87442c0ffc5"; - string givenTo2 = "41793026834"; - string givenSentAt2 = "2019-11-09T17:00:00.000+0000"; - string givenDoneAt2 = "2019-11-09T17:00:00.000+0000"; - string givenApplicationId2 = "default"; - - int givenLimit = 100; - - string givenResponse = $@" + [TestMethod] + public void ShouldGetSmsReports() + { + var givenBulkId = "BULK-ID-123-xyz"; + var givenMessageId1 = "MESSAGE-ID-123-xyz"; + var givenTo1 = "41793026727"; + var givenSentAt1 = "2019-11-09T16:00:00.000+0000"; + var givenDoneAt1 = "2019-11-09T16:00:00.000+0000"; + var givenSmsCount = 1; + var givenPricePerMessage = "0.01"; + var givenCurrency = "EUR"; + var givenEntityId = "promotional-traffic-entity"; + var givenApplicationId1 = "marketing-automation-application"; + + var givenMessageId2 = "12db39c3-7822-4e72-a3ec-c87442c0ffc5"; + var givenTo2 = "41793026834"; + var givenSentAt2 = "2019-11-09T17:00:00.000+0000"; + var givenDoneAt2 = "2019-11-09T17:00:00.000+0000"; + var givenApplicationId2 = "default"; + + var givenLimit = 100; + + var givenResponse = $@" {{ ""results"": [ {{ @@ -879,90 +864,99 @@ public void ShouldGetSmsReports() ] }}"; - var expectedQueryParameters = new Dictionary { - { "bulkId", givenBulkId}, - { "limit", givenLimit.ToString()} - }; - - SetUpGetRequest(SMS_REPORTS_ENDPOINT, expectedQueryParameters, givenResponse, 200); - - var smsApi = new SmsApi(configuration); + var expectedQueryParameters = new Dictionary + { + { "bulkId", givenBulkId }, + { "limit", givenLimit.ToString() } + }; - void AssertSmsDeliveryResult(SmsDeliveryResult smsDeliveryResult) - { - Assert.IsNotNull(smsDeliveryResult); - - Assert.IsNotNull(smsDeliveryResult.Results[0]); - Assert.AreEqual(smsDeliveryResult.Results[0].BulkId, givenBulkId); - Assert.AreEqual(smsDeliveryResult.Results[0].MessageId, givenMessageId1); - Assert.AreEqual(smsDeliveryResult.Results[0].To, givenTo1); - Assert.AreEqual(smsDeliveryResult.Results[0].SentAt, DateTimeOffset.Parse(givenSentAt1)); - Assert.AreEqual(smsDeliveryResult.Results[0].DoneAt, DateTimeOffset.Parse(givenDoneAt1)); - Assert.AreEqual(smsDeliveryResult.Results[0].SmsCount, givenSmsCount); - Assert.AreEqual(smsDeliveryResult.Results[0].Price.PricePerMessage, decimal.Parse(givenPricePerMessage, System.Globalization.CultureInfo.InvariantCulture)); - Assert.AreEqual(smsDeliveryResult.Results[0].Price.Currency, givenCurrency); - Assert.AreEqual(smsDeliveryResult.Results[0].Status.GroupId, DELIVERED_STATUS_GROUP_ID); - Assert.AreEqual(smsDeliveryResult.Results[0].Status.GroupName, DELIVERED_STATUS_GROUP_NAME); - Assert.AreEqual(smsDeliveryResult.Results[0].Status.Id, DELIVERED_STATUS_ID); - Assert.AreEqual(smsDeliveryResult.Results[0].Status.Name, DELIVERED_STATUS_NAME); - Assert.AreEqual(smsDeliveryResult.Results[0].Status.Description, DELIVERED_STATUS_DESCRIPTION); - Assert.AreEqual(smsDeliveryResult.Results[0].Error.GroupId, NO_ERROR_GROUP_ID); - Assert.AreEqual(smsDeliveryResult.Results[0].Error.GroupName, NO_ERROR_GROUP_NAME); - Assert.AreEqual(smsDeliveryResult.Results[0].Error.Id, NO_ERROR_ID); - Assert.AreEqual(smsDeliveryResult.Results[0].Error.Name, NO_ERROR_NAME); - Assert.AreEqual(smsDeliveryResult.Results[0].Error.Description, NO_ERROR_DESCRIPTION); - Assert.AreEqual(smsDeliveryResult.Results[0].Error.Permanent, NO_ERROR_IS_PERMANENT); - Assert.AreEqual(smsDeliveryResult.Results[0].EntityId, givenEntityId); - Assert.AreEqual(smsDeliveryResult.Results[0].ApplicationId, givenApplicationId1); - - Assert.IsNotNull(smsDeliveryResult.Results[1]); - Assert.AreEqual(smsDeliveryResult.Results[1].BulkId, givenBulkId); - Assert.AreEqual(smsDeliveryResult.Results[1].MessageId, givenMessageId2); - Assert.AreEqual(smsDeliveryResult.Results[1].To, givenTo2); - Assert.AreEqual(smsDeliveryResult.Results[1].SentAt, DateTimeOffset.Parse(givenSentAt2)); - Assert.AreEqual(smsDeliveryResult.Results[1].DoneAt, DateTimeOffset.Parse(givenDoneAt2)); - Assert.AreEqual(smsDeliveryResult.Results[1].SmsCount, givenSmsCount); - Assert.AreEqual(smsDeliveryResult.Results[1].Price.PricePerMessage, decimal.Parse(givenPricePerMessage, System.Globalization.CultureInfo.InvariantCulture)); - Assert.AreEqual(smsDeliveryResult.Results[1].Price.Currency, givenCurrency); - Assert.AreEqual(smsDeliveryResult.Results[1].Status.GroupId, DELIVERED_STATUS_GROUP_ID); - Assert.AreEqual(smsDeliveryResult.Results[1].Status.GroupName, DELIVERED_STATUS_GROUP_NAME); - Assert.AreEqual(smsDeliveryResult.Results[1].Status.Id, DELIVERED_STATUS_ID); - Assert.AreEqual(smsDeliveryResult.Results[1].Status.Name, DELIVERED_STATUS_NAME); - Assert.AreEqual(smsDeliveryResult.Results[1].Status.Description, DELIVERED_STATUS_DESCRIPTION); - Assert.AreEqual(smsDeliveryResult.Results[1].Error.GroupId, NO_ERROR_GROUP_ID); - Assert.AreEqual(smsDeliveryResult.Results[1].Error.GroupName, NO_ERROR_GROUP_NAME); - Assert.AreEqual(smsDeliveryResult.Results[1].Error.Id, NO_ERROR_ID); - Assert.AreEqual(smsDeliveryResult.Results[1].Error.Name, NO_ERROR_NAME); - Assert.AreEqual(smsDeliveryResult.Results[1].Error.Description, NO_ERROR_DESCRIPTION); - Assert.AreEqual(smsDeliveryResult.Results[1].Error.Permanent, NO_ERROR_IS_PERMANENT); - Assert.AreEqual(smsDeliveryResult.Results[1].ApplicationId, givenApplicationId2); - } + SetUpGetRequest(SMS_REPORTS_ENDPOINT, expectedQueryParameters, givenResponse, 200); - AssertResponse(smsApi.GetOutboundSmsMessageDeliveryReports(bulkId: givenBulkId, limit: givenLimit), AssertSmsDeliveryResult); - AssertResponse(smsApi.GetOutboundSmsMessageDeliveryReportsAsync(bulkId: givenBulkId, limit: givenLimit).Result, AssertSmsDeliveryResult); + var smsApi = new SmsApi(configuration); - AssertResponseWithHttpInfo(smsApi.GetOutboundSmsMessageDeliveryReportsWithHttpInfo(bulkId: givenBulkId, limit: givenLimit), AssertSmsDeliveryResult); - AssertResponseWithHttpInfo(smsApi.GetOutboundSmsMessageDeliveryReportsWithHttpInfoAsync(bulkId: givenBulkId, limit: givenLimit).Result, AssertSmsDeliveryResult); + void AssertSmsDeliveryResult(SmsDeliveryResult smsDeliveryResult) + { + Assert.IsNotNull(smsDeliveryResult); + + Assert.IsNotNull(smsDeliveryResult.Results[0]); + Assert.AreEqual(smsDeliveryResult.Results[0].BulkId, givenBulkId); + Assert.AreEqual(smsDeliveryResult.Results[0].MessageId, givenMessageId1); + Assert.AreEqual(smsDeliveryResult.Results[0].To, givenTo1); + Assert.AreEqual(smsDeliveryResult.Results[0].SentAt, DateTimeOffset.Parse(givenSentAt1)); + Assert.AreEqual(smsDeliveryResult.Results[0].DoneAt, DateTimeOffset.Parse(givenDoneAt1)); + Assert.AreEqual(smsDeliveryResult.Results[0].SmsCount, givenSmsCount); + Assert.AreEqual(smsDeliveryResult.Results[0].Price.PricePerMessage, + decimal.Parse(givenPricePerMessage, CultureInfo.InvariantCulture)); + Assert.AreEqual(smsDeliveryResult.Results[0].Price.Currency, givenCurrency); + Assert.AreEqual(smsDeliveryResult.Results[0].Status.GroupId, DELIVERED_STATUS_GROUP_ID); + Assert.AreEqual(smsDeliveryResult.Results[0].Status.GroupName, DELIVERED_STATUS_GROUP_NAME); + Assert.AreEqual(smsDeliveryResult.Results[0].Status.Id, DELIVERED_STATUS_ID); + Assert.AreEqual(smsDeliveryResult.Results[0].Status.Name, DELIVERED_STATUS_NAME); + Assert.AreEqual(smsDeliveryResult.Results[0].Status.Description, DELIVERED_STATUS_DESCRIPTION); + Assert.AreEqual(smsDeliveryResult.Results[0].Error.GroupId, NO_ERROR_GROUP_ID); + Assert.AreEqual(smsDeliveryResult.Results[0].Error.GroupName, NO_ERROR_GROUP_NAME); + Assert.AreEqual(smsDeliveryResult.Results[0].Error.Id, NO_ERROR_ID); + Assert.AreEqual(smsDeliveryResult.Results[0].Error.Name, NO_ERROR_NAME); + Assert.AreEqual(smsDeliveryResult.Results[0].Error.Description, NO_ERROR_DESCRIPTION); + Assert.AreEqual(smsDeliveryResult.Results[0].Error.Permanent, NO_ERROR_IS_PERMANENT); + Assert.AreEqual(smsDeliveryResult.Results[0].EntityId, givenEntityId); + Assert.AreEqual(smsDeliveryResult.Results[0].ApplicationId, givenApplicationId1); + + Assert.IsNotNull(smsDeliveryResult.Results[1]); + Assert.AreEqual(smsDeliveryResult.Results[1].BulkId, givenBulkId); + Assert.AreEqual(smsDeliveryResult.Results[1].MessageId, givenMessageId2); + Assert.AreEqual(smsDeliveryResult.Results[1].To, givenTo2); + Assert.AreEqual(smsDeliveryResult.Results[1].SentAt, DateTimeOffset.Parse(givenSentAt2)); + Assert.AreEqual(smsDeliveryResult.Results[1].DoneAt, DateTimeOffset.Parse(givenDoneAt2)); + Assert.AreEqual(smsDeliveryResult.Results[1].SmsCount, givenSmsCount); + Assert.AreEqual(smsDeliveryResult.Results[1].Price.PricePerMessage, + decimal.Parse(givenPricePerMessage, CultureInfo.InvariantCulture)); + Assert.AreEqual(smsDeliveryResult.Results[1].Price.Currency, givenCurrency); + Assert.AreEqual(smsDeliveryResult.Results[1].Status.GroupId, DELIVERED_STATUS_GROUP_ID); + Assert.AreEqual(smsDeliveryResult.Results[1].Status.GroupName, DELIVERED_STATUS_GROUP_NAME); + Assert.AreEqual(smsDeliveryResult.Results[1].Status.Id, DELIVERED_STATUS_ID); + Assert.AreEqual(smsDeliveryResult.Results[1].Status.Name, DELIVERED_STATUS_NAME); + Assert.AreEqual(smsDeliveryResult.Results[1].Status.Description, DELIVERED_STATUS_DESCRIPTION); + Assert.AreEqual(smsDeliveryResult.Results[1].Error.GroupId, NO_ERROR_GROUP_ID); + Assert.AreEqual(smsDeliveryResult.Results[1].Error.GroupName, NO_ERROR_GROUP_NAME); + Assert.AreEqual(smsDeliveryResult.Results[1].Error.Id, NO_ERROR_ID); + Assert.AreEqual(smsDeliveryResult.Results[1].Error.Name, NO_ERROR_NAME); + Assert.AreEqual(smsDeliveryResult.Results[1].Error.Description, NO_ERROR_DESCRIPTION); + Assert.AreEqual(smsDeliveryResult.Results[1].Error.Permanent, NO_ERROR_IS_PERMANENT); + Assert.AreEqual(smsDeliveryResult.Results[1].ApplicationId, givenApplicationId2); } - [TestMethod] - public void ShouldGetReceivedSmsMessages() - { - string givenMessageId = "817790313235066447"; - string givenFrom = "385916242493"; - string givenTo = "385921004026"; - string givenText = "QUIZ Correct answer is Paris"; - string givenCleanText = "Correct answer is Paris"; - string givenKeyword = "QUIZ"; - string givenReceivedAt = "2021-08-25T16:10:00.000+0500"; - int givenSmsCount = 1; - decimal givenPricePerMessage = 0; - string givenCurrency = "EUR"; - string givenCallbackData = "callbackData"; - int givenMessageCount = 1; - int givenPendingMessageCount = 0; - - string givenResponse = $@" + AssertResponse(smsApi.GetOutboundSmsMessageDeliveryReports(givenBulkId, limit: givenLimit), + AssertSmsDeliveryResult); + AssertResponse(smsApi.GetOutboundSmsMessageDeliveryReportsAsync(givenBulkId, limit: givenLimit).Result, + AssertSmsDeliveryResult); + + AssertResponseWithHttpInfo( + smsApi.GetOutboundSmsMessageDeliveryReportsWithHttpInfo(givenBulkId, limit: givenLimit), + AssertSmsDeliveryResult); + AssertResponseWithHttpInfo( + smsApi.GetOutboundSmsMessageDeliveryReportsWithHttpInfoAsync(givenBulkId, limit: givenLimit).Result, + AssertSmsDeliveryResult); + } + + [TestMethod] + public void ShouldGetReceivedSmsMessages() + { + var givenMessageId = "817790313235066447"; + var givenFrom = "385916242493"; + var givenTo = "385921004026"; + var givenText = "QUIZ Correct answer is Paris"; + var givenCleanText = "Correct answer is Paris"; + var givenKeyword = "QUIZ"; + var givenReceivedAt = "2021-08-25T16:10:00.000+0500"; + var givenSmsCount = 1; + decimal givenPricePerMessage = 0; + var givenCurrency = "EUR"; + var givenCallbackData = "callbackData"; + var givenMessageCount = 1; + var givenPendingMessageCount = 0; + + var givenResponse = $@" {{ ""results"": [ {{ @@ -985,56 +979,58 @@ public void ShouldGetReceivedSmsMessages() ""pendingMessageCount"": {givenPendingMessageCount} }}"; - int givenLimit = 2; - SetUpGetRequest(SMS_INBOX_REPORTS_ENDPOINT, new Dictionary { { "limit", givenLimit.ToString() } }, givenResponse, 200); + var givenLimit = 2; + SetUpGetRequest(SMS_INBOX_REPORTS_ENDPOINT, + new Dictionary { { "limit", givenLimit.ToString() } }, givenResponse, 200); - void ResultAssertions(SmsInboundMessageResult smsInboundResult) - { - Assert.IsNotNull(smsInboundResult); - Assert.AreEqual(givenMessageCount, smsInboundResult.MessageCount); - Assert.AreEqual(givenPendingMessageCount, smsInboundResult.PendingMessageCount); - - Assert.AreEqual(1, smsInboundResult.Results.Count); - SmsInboundMessage message = smsInboundResult.Results[0]; - Assert.AreEqual(givenMessageId, message.MessageId); - Assert.AreEqual(givenFrom, message.From); - Assert.AreEqual(givenTo, message.To); - Assert.AreEqual(givenText, message.Text); - Assert.AreEqual(givenCleanText, message.CleanText); - Assert.AreEqual(givenKeyword, message.Keyword); - Assert.AreEqual(DateTimeOffset.Parse(givenReceivedAt), message.ReceivedAt); - Assert.AreEqual(givenSmsCount, message.SmsCount); - Assert.AreEqual(givenPricePerMessage, message.Price.PricePerMessage); - Assert.AreEqual(givenCurrency, message.Price.Currency); - Assert.AreEqual(givenCallbackData, message.CallbackData); - } + void ResultAssertions(SmsInboundMessageResult smsInboundResult) + { + Assert.IsNotNull(smsInboundResult); + Assert.AreEqual(givenMessageCount, smsInboundResult.MessageCount); + Assert.AreEqual(givenPendingMessageCount, smsInboundResult.PendingMessageCount); + + Assert.AreEqual(1, smsInboundResult.Results.Count); + var message = smsInboundResult.Results[0]; + Assert.AreEqual(givenMessageId, message.MessageId); + Assert.AreEqual(givenFrom, message.From); + Assert.AreEqual(givenTo, message.To); + Assert.AreEqual(givenText, message.Text); + Assert.AreEqual(givenCleanText, message.CleanText); + Assert.AreEqual(givenKeyword, message.Keyword); + Assert.AreEqual(DateTimeOffset.Parse(givenReceivedAt), message.ReceivedAt); + Assert.AreEqual(givenSmsCount, message.SmsCount); + Assert.AreEqual(givenPricePerMessage, message.Price.PricePerMessage); + Assert.AreEqual(givenCurrency, message.Price.Currency); + Assert.AreEqual(givenCallbackData, message.CallbackData); + } - SmsApi receiveApi = new SmsApi(configuration); + var receiveApi = new SmsApi(configuration); - AssertResponse(receiveApi.GetInboundSmsMessages(givenLimit), ResultAssertions); - AssertResponse(receiveApi.GetInboundSmsMessagesAsync(givenLimit).Result, ResultAssertions); + AssertResponse(receiveApi.GetInboundSmsMessages(givenLimit), ResultAssertions); + AssertResponse(receiveApi.GetInboundSmsMessagesAsync(givenLimit).Result, ResultAssertions); - AssertResponseWithHttpInfo(receiveApi.GetInboundSmsMessagesWithHttpInfo(givenLimit), ResultAssertions); - AssertResponseWithHttpInfo(receiveApi.GetInboundSmsMessagesWithHttpInfoAsync(givenLimit).Result, ResultAssertions); - } + AssertResponseWithHttpInfo(receiveApi.GetInboundSmsMessagesWithHttpInfo(givenLimit), ResultAssertions); + AssertResponseWithHttpInfo(receiveApi.GetInboundSmsMessagesWithHttpInfoAsync(givenLimit).Result, + ResultAssertions); + } - [TestMethod] - public void ShouldSendSmsPreview() - { - string expectedPreviewText = "Let's see how many characters will remain unused in this message."; + [TestMethod] + public void ShouldSendSmsPreview() + { + var expectedPreviewText = "Let's see how many characters will remain unused in this message."; - string expectedRequest = $@" + var expectedRequest = $@" {{ ""text"": ""{expectedPreviewText}"" }}"; - string givenOriginalText = "Let's see how many characters will remain unused in this message."; - string givenTextPreview = "Let's see how many characters will remain unused in this message."; - int givenMessageCount = 1; - int givenCharactersRemaining = 95; + var givenOriginalText = "Let's see how many characters will remain unused in this message."; + var givenTextPreview = "Let's see how many characters will remain unused in this message."; + var givenMessageCount = 1; + var givenCharactersRemaining = 95; - string givenResponse = $@" + var givenResponse = $@" {{ ""originalText"": ""{givenOriginalText}"", ""previews"": [ @@ -1047,199 +1043,217 @@ public void ShouldSendSmsPreview() ] }}"; - SetUpPostRequest(SMS_SEND_PREVIEW_ENDPOINT, expectedRequest, givenResponse, 200); + SetUpPostRequest(SMS_SEND_PREVIEW_ENDPOINT, expectedRequest, givenResponse, 200); - void SmsPreviewAssertions(SmsPreviewResponse response) - { - Assert.IsNotNull(response); - Assert.AreEqual(givenOriginalText, response.OriginalText); - Assert.AreEqual(1, response.Previews.Count); - SmsPreview preview = response.Previews[0]; - Assert.AreEqual(givenTextPreview, preview.TextPreview); - Assert.AreEqual(givenMessageCount, preview.MessageCount); - Assert.AreEqual(givenCharactersRemaining, preview.CharactersRemaining); - Assert.AreEqual(givenOriginalText, response.OriginalText); - SmsLanguageConfiguration smsLanguage = preview.VarConfiguration; - Assert.IsNotNull(smsLanguage); - Assert.IsNull(smsLanguage.Language); - Assert.IsNull(smsLanguage.Transliteration); - } + void SmsPreviewAssertions(SmsPreviewResponse response) + { + Assert.IsNotNull(response); + Assert.AreEqual(givenOriginalText, response.OriginalText); + Assert.AreEqual(1, response.Previews.Count); + var preview = response.Previews[0]; + Assert.AreEqual(givenTextPreview, preview.TextPreview); + Assert.AreEqual(givenMessageCount, preview.MessageCount); + Assert.AreEqual(givenCharactersRemaining, preview.CharactersRemaining); + Assert.AreEqual(givenOriginalText, response.OriginalText); + var smsLanguage = preview.VarConfiguration; + Assert.IsNotNull(smsLanguage); + Assert.IsNull(smsLanguage.Language); + Assert.IsNull(smsLanguage.Transliteration); + } - SmsApi sendSmsApi = new SmsApi(configuration); - SmsPreviewRequest request = new SmsPreviewRequest(text: givenTextPreview); + var sendSmsApi = new SmsApi(configuration); + var request = new SmsPreviewRequest(givenTextPreview); - AssertResponse(sendSmsApi.PreviewSmsMessage(request), SmsPreviewAssertions); - AssertResponse(sendSmsApi.PreviewSmsMessageAsync(request).Result, SmsPreviewAssertions); - AssertResponseWithHttpInfo(sendSmsApi.PreviewSmsMessageWithHttpInfo(request), SmsPreviewAssertions); - AssertResponseWithHttpInfo(sendSmsApi.PreviewSmsMessageWithHttpInfoAsync(request).Result, SmsPreviewAssertions); - } + AssertResponse(sendSmsApi.PreviewSmsMessage(request), SmsPreviewAssertions); + AssertResponse(sendSmsApi.PreviewSmsMessageAsync(request).Result, SmsPreviewAssertions); + AssertResponseWithHttpInfo(sendSmsApi.PreviewSmsMessageWithHttpInfo(request), SmsPreviewAssertions); + AssertResponseWithHttpInfo(sendSmsApi.PreviewSmsMessageWithHttpInfoAsync(request).Result, SmsPreviewAssertions); + } - [TestMethod] - public void ShouldGetScheduledSmsMessages() - { - string givenResponse = $@" + [TestMethod] + public void ShouldGetScheduledSmsMessages() + { + var givenResponse = $@" {{ ""bulkId"": ""{GIVEN_BULK_ID}"", ""sendAt"": ""{GIVEN_SEND_AT}"" }}"; - SetUpGetRequest(SMS_BULKS_ENDPOINT, new Dictionary { { "bulkId", GIVEN_BULK_ID } }, givenResponse, 200); + SetUpGetRequest(SMS_BULKS_ENDPOINT, new Dictionary { { "bulkId", GIVEN_BULK_ID } }, + givenResponse, 200); - void BulkResponseAssertions(SmsBulkResponse response) - { - Assert.IsNotNull(response); - Assert.AreEqual(GIVEN_BULK_ID, response.BulkId); - Assert.AreEqual(DateTimeOffset.Parse(GIVEN_SEND_AT), response.SendAt); - } + void BulkResponseAssertions(SmsBulkResponse response) + { + Assert.IsNotNull(response); + Assert.AreEqual(GIVEN_BULK_ID, response.BulkId); + Assert.AreEqual(DateTimeOffset.Parse(GIVEN_SEND_AT), response.SendAt); + } - SmsApi scheduledSmsApi = new SmsApi(configuration); + var scheduledSmsApi = new SmsApi(configuration); - AssertResponse(scheduledSmsApi.GetScheduledSmsMessages(GIVEN_BULK_ID), BulkResponseAssertions); - AssertResponse(scheduledSmsApi.GetScheduledSmsMessagesAsync(GIVEN_BULK_ID).Result, BulkResponseAssertions); - AssertResponseWithHttpInfo(scheduledSmsApi.GetScheduledSmsMessagesWithHttpInfo(GIVEN_BULK_ID), BulkResponseAssertions); - AssertResponseWithHttpInfo(scheduledSmsApi.GetScheduledSmsMessagesWithHttpInfoAsync(GIVEN_BULK_ID).Result, BulkResponseAssertions); - } + AssertResponse(scheduledSmsApi.GetScheduledSmsMessages(GIVEN_BULK_ID), BulkResponseAssertions); + AssertResponse(scheduledSmsApi.GetScheduledSmsMessagesAsync(GIVEN_BULK_ID).Result, BulkResponseAssertions); + AssertResponseWithHttpInfo(scheduledSmsApi.GetScheduledSmsMessagesWithHttpInfo(GIVEN_BULK_ID), + BulkResponseAssertions); + AssertResponseWithHttpInfo(scheduledSmsApi.GetScheduledSmsMessagesWithHttpInfoAsync(GIVEN_BULK_ID).Result, + BulkResponseAssertions); + } - [TestMethod] - public void ShouldRescheduleSmsMessages() - { - string expectedRequest = $@" + [TestMethod] + public void ShouldRescheduleSmsMessages() + { + var expectedRequest = $@" {{ ""sendAt"": ""{GIVEN_SEND_AT_WITH_COLON}"" }}"; - string givenResponse = $@" + var givenResponse = $@" {{ ""bulkId"": ""{GIVEN_BULK_ID}"", ""sendAt"": ""{GIVEN_SEND_AT}"" }}"; - SetUpPutRequest(SMS_BULKS_ENDPOINT, new Dictionary { { "bulkId", GIVEN_BULK_ID } }, expectedRequest, givenResponse, 200); + SetUpPutRequest(SMS_BULKS_ENDPOINT, new Dictionary { { "bulkId", GIVEN_BULK_ID } }, + expectedRequest, givenResponse, 200); - void BulkResponseAssertions(SmsBulkResponse response) - { - Assert.IsNotNull(response); - Assert.AreEqual(GIVEN_BULK_ID, response.BulkId); - Assert.AreEqual(DateTimeOffset.Parse(GIVEN_SEND_AT), response.SendAt); - } - - SmsApi scheduledSmsApi = new SmsApi(configuration); - SmsBulkRequest bulkRequest = new SmsBulkRequest(sendAt: DateTimeOffset.Parse(GIVEN_SEND_AT_WITH_COLON)); - - AssertResponse(scheduledSmsApi.RescheduleSmsMessages(GIVEN_BULK_ID, bulkRequest), BulkResponseAssertions); - AssertResponse(scheduledSmsApi.RescheduleSmsMessagesAsync(GIVEN_BULK_ID, bulkRequest).Result, BulkResponseAssertions); - AssertResponseWithHttpInfo(scheduledSmsApi.RescheduleSmsMessagesWithHttpInfo(GIVEN_BULK_ID, bulkRequest), BulkResponseAssertions); - AssertResponseWithHttpInfo(scheduledSmsApi.RescheduleSmsMessagesWithHttpInfoAsync(GIVEN_BULK_ID, bulkRequest).Result, BulkResponseAssertions); + void BulkResponseAssertions(SmsBulkResponse response) + { + Assert.IsNotNull(response); + Assert.AreEqual(GIVEN_BULK_ID, response.BulkId); + Assert.AreEqual(DateTimeOffset.Parse(GIVEN_SEND_AT), response.SendAt); } - [TestMethod] - public void ShouldGetScheduledSmsMessagesStatus() - { - string givenResponse = $@" + var scheduledSmsApi = new SmsApi(configuration); + var bulkRequest = new SmsBulkRequest(DateTimeOffset.Parse(GIVEN_SEND_AT_WITH_COLON)); + + AssertResponse(scheduledSmsApi.RescheduleSmsMessages(GIVEN_BULK_ID, bulkRequest), BulkResponseAssertions); + AssertResponse(scheduledSmsApi.RescheduleSmsMessagesAsync(GIVEN_BULK_ID, bulkRequest).Result, + BulkResponseAssertions); + AssertResponseWithHttpInfo(scheduledSmsApi.RescheduleSmsMessagesWithHttpInfo(GIVEN_BULK_ID, bulkRequest), + BulkResponseAssertions); + AssertResponseWithHttpInfo( + scheduledSmsApi.RescheduleSmsMessagesWithHttpInfoAsync(GIVEN_BULK_ID, bulkRequest).Result, + BulkResponseAssertions); + } + + [TestMethod] + public void ShouldGetScheduledSmsMessagesStatus() + { + var givenResponse = $@" {{ ""bulkId"": ""{GIVEN_BULK_ID}"", ""status"": ""{GIVEN_BULK_STATUS_STRING}"" }}"; - SetUpGetRequest(SMS_BULKS_STATUS_ENDPOINT, new Dictionary { { "bulkId", GIVEN_BULK_ID } }, givenResponse, 200); - - void BulkResponseAssertions(SmsBulkStatusResponse response) - { - Assert.IsNotNull(response); - Assert.AreEqual(GIVEN_BULK_ID, response.BulkId); - Assert.AreEqual(GIVEN_BULK_STATUS, response.Status); - } + SetUpGetRequest(SMS_BULKS_STATUS_ENDPOINT, new Dictionary { { "bulkId", GIVEN_BULK_ID } }, + givenResponse, 200); - SmsApi scheduledSmsApi = new SmsApi(configuration); + void BulkResponseAssertions(SmsBulkStatusResponse response) + { + Assert.IsNotNull(response); + Assert.AreEqual(GIVEN_BULK_ID, response.BulkId); + Assert.AreEqual(GIVEN_BULK_STATUS, response.Status); + } - AssertResponse(scheduledSmsApi.GetScheduledSmsMessagesStatus(GIVEN_BULK_ID), BulkResponseAssertions); - AssertResponse(scheduledSmsApi.GetScheduledSmsMessagesStatusAsync(GIVEN_BULK_ID).Result, BulkResponseAssertions); - AssertResponseWithHttpInfo(scheduledSmsApi.GetScheduledSmsMessagesStatusWithHttpInfo(GIVEN_BULK_ID), BulkResponseAssertions); - AssertResponseWithHttpInfo(scheduledSmsApi.GetScheduledSmsMessagesStatusWithHttpInfoAsync(GIVEN_BULK_ID).Result, BulkResponseAssertions); + var scheduledSmsApi = new SmsApi(configuration); - } + AssertResponse(scheduledSmsApi.GetScheduledSmsMessagesStatus(GIVEN_BULK_ID), BulkResponseAssertions); + AssertResponse(scheduledSmsApi.GetScheduledSmsMessagesStatusAsync(GIVEN_BULK_ID).Result, + BulkResponseAssertions); + AssertResponseWithHttpInfo(scheduledSmsApi.GetScheduledSmsMessagesStatusWithHttpInfo(GIVEN_BULK_ID), + BulkResponseAssertions); + AssertResponseWithHttpInfo(scheduledSmsApi.GetScheduledSmsMessagesStatusWithHttpInfoAsync(GIVEN_BULK_ID).Result, + BulkResponseAssertions); + } - [TestMethod] - public void ShouldUpdateScheduledSmsMessagesStatus() - { - string expectedRequest = $@" + [TestMethod] + public void ShouldUpdateScheduledSmsMessagesStatus() + { + var expectedRequest = $@" {{ ""status"": ""{GIVEN_BULK_STATUS_STRING}"" }}"; - string givenResponse = $@" + var givenResponse = $@" {{ ""bulkId"": ""{GIVEN_BULK_ID}"", ""status"": ""{GIVEN_BULK_STATUS_STRING}"" }}"; - SetUpPutRequest(SMS_BULKS_STATUS_ENDPOINT, new Dictionary { { "bulkId", GIVEN_BULK_ID } }, expectedRequest, givenResponse, 200); - - void BulkResponseAssertions(SmsBulkStatusResponse response) - { - Assert.IsNotNull(response); - Assert.AreEqual(GIVEN_BULK_ID, response.BulkId); - Assert.AreEqual(GIVEN_BULK_STATUS, response.Status); - } - - SmsApi scheduledSmsApi = new SmsApi(configuration); - var updateStatusRequest = new SmsUpdateStatusRequest(SmsBulkStatus.Paused); - - AssertResponse(scheduledSmsApi.UpdateScheduledSmsMessagesStatus(GIVEN_BULK_ID, updateStatusRequest), BulkResponseAssertions); - AssertResponse(scheduledSmsApi.UpdateScheduledSmsMessagesStatusAsync(GIVEN_BULK_ID, updateStatusRequest).Result, BulkResponseAssertions); - AssertResponseWithHttpInfo(scheduledSmsApi.UpdateScheduledSmsMessagesStatusWithHttpInfo(GIVEN_BULK_ID, updateStatusRequest), BulkResponseAssertions); - AssertResponseWithHttpInfo(scheduledSmsApi.UpdateScheduledSmsMessagesStatusWithHttpInfoAsync(GIVEN_BULK_ID, updateStatusRequest).Result, BulkResponseAssertions); - - } + SetUpPutRequest(SMS_BULKS_STATUS_ENDPOINT, new Dictionary { { "bulkId", GIVEN_BULK_ID } }, + expectedRequest, givenResponse, 200); - private void AssertDeliveredSmsStatus(MessageStatus status) + void BulkResponseAssertions(SmsBulkStatusResponse response) { - Assert.AreEqual(DELIVERED_STATUS_GROUP_ID, status.GroupId); - Assert.AreEqual(DELIVERED_STATUS_GROUP_NAME, status.GroupName); - Assert.AreEqual(DELIVERED_STATUS_ID, status.Id); - Assert.AreEqual(DELIVERED_STATUS_NAME, status.Name); - Assert.AreEqual(DELIVERED_STATUS_DESCRIPTION, status.Description); - Assert.IsNull(status.Action); + Assert.IsNotNull(response); + Assert.AreEqual(GIVEN_BULK_ID, response.BulkId); + Assert.AreEqual(GIVEN_BULK_STATUS, response.Status); } - private void AssertNoError(MessageError error) - { - Assert.AreEqual(NO_ERROR_GROUP_ID, error.GroupId); - Assert.AreEqual(NO_ERROR_GROUP_NAME, error.GroupName); - Assert.AreEqual(NO_ERROR_ID, error.Id); - Assert.AreEqual(NO_ERROR_NAME, error.Name); - Assert.AreEqual(NO_ERROR_DESCRIPTION, error.Description); - Assert.AreEqual(NO_ERROR_IS_PERMANENT, error.Permanent); - } + var scheduledSmsApi = new SmsApi(configuration); + var updateStatusRequest = new SmsUpdateStatusRequest(SmsBulkStatus.Paused); + + AssertResponse(scheduledSmsApi.UpdateScheduledSmsMessagesStatus(GIVEN_BULK_ID, updateStatusRequest), + BulkResponseAssertions); + AssertResponse(scheduledSmsApi.UpdateScheduledSmsMessagesStatusAsync(GIVEN_BULK_ID, updateStatusRequest).Result, + BulkResponseAssertions); + AssertResponseWithHttpInfo( + scheduledSmsApi.UpdateScheduledSmsMessagesStatusWithHttpInfo(GIVEN_BULK_ID, updateStatusRequest), + BulkResponseAssertions); + AssertResponseWithHttpInfo( + scheduledSmsApi.UpdateScheduledSmsMessagesStatusWithHttpInfoAsync(GIVEN_BULK_ID, updateStatusRequest) + .Result, BulkResponseAssertions); + } - private void AssertPendingSmsResponse(SmsResponseDetails responseDetails) - { - Assert.AreEqual(PENDING_STATUS_GROUP_ID, responseDetails.Status.GroupId); - Assert.AreEqual(PENDING_STATUS_GROUP_NAME, responseDetails.Status.GroupName); - Assert.AreEqual(PENDING_STATUS_ID, responseDetails.Status.Id); - Assert.AreEqual(PENDING_STATUS_NAME, responseDetails.Status.Name); - Assert.AreEqual(PENDING_STATUS_DESCRIPTION, responseDetails.Status.Description); - Assert.IsNull(responseDetails.Status.Action); - } + private void AssertDeliveredSmsStatus(MessageStatus status) + { + Assert.AreEqual(DELIVERED_STATUS_GROUP_ID, status.GroupId); + Assert.AreEqual(DELIVERED_STATUS_GROUP_NAME, status.GroupName); + Assert.AreEqual(DELIVERED_STATUS_ID, status.Id); + Assert.AreEqual(DELIVERED_STATUS_NAME, status.Name); + Assert.AreEqual(DELIVERED_STATUS_DESCRIPTION, status.Description); + Assert.IsNull(status.Action); + } + private void AssertNoError(MessageError error) + { + Assert.AreEqual(NO_ERROR_GROUP_ID, error.GroupId); + Assert.AreEqual(NO_ERROR_GROUP_NAME, error.GroupName); + Assert.AreEqual(NO_ERROR_ID, error.Id); + Assert.AreEqual(NO_ERROR_NAME, error.Name); + Assert.AreEqual(NO_ERROR_DESCRIPTION, error.Description); + Assert.AreEqual(NO_ERROR_IS_PERMANENT, error.Permanent); + } - private string PreparePendingResponse(string givenBulkId, string givenDestination, string givenMessageId) - { - return $@" + private void AssertPendingSmsResponse(SmsResponseDetails responseDetails) + { + Assert.AreEqual(PENDING_STATUS_GROUP_ID, responseDetails.Status.GroupId); + Assert.AreEqual(PENDING_STATUS_GROUP_NAME, responseDetails.Status.GroupName); + Assert.AreEqual(PENDING_STATUS_ID, responseDetails.Status.Id); + Assert.AreEqual(PENDING_STATUS_NAME, responseDetails.Status.Name); + Assert.AreEqual(PENDING_STATUS_DESCRIPTION, responseDetails.Status.Description); + Assert.IsNull(responseDetails.Status.Action); + } + + + private string PreparePendingResponse(string givenBulkId, string givenDestination, string givenMessageId) + { + return $@" {{ ""bulkId"": ""{givenBulkId}"", ""messages"": [ {PreparePendingResponseDetails(givenDestination, givenMessageId)} ] }}"; - } + } - private string PreparePendingResponse(string givenBulkId, string givenDestination1, string givenMessageId1, string givenDestination2, string givenMessageId2) - { - return $@" + private string PreparePendingResponse(string givenBulkId, string givenDestination1, string givenMessageId1, + string givenDestination2, string givenMessageId2) + { + return $@" {{ ""bulkId"": ""{givenBulkId}"", ""messages"": [ @@ -1247,11 +1261,11 @@ private string PreparePendingResponse(string givenBulkId, string givenDestinatio {PreparePendingResponseDetails(givenDestination2, givenMessageId2)} ] }}"; - } + } - private string PreparePendingResponseDetails(string givenDestination, string givenMessageId) - { - return $@" + private string PreparePendingResponseDetails(string givenDestination, string givenMessageId) + { + return $@" {{ ""to"": ""{givenDestination}"", ""status"": {{ @@ -1263,6 +1277,5 @@ private string PreparePendingResponseDetails(string givenDestination, string giv }}, ""messageId"": ""{givenMessageId}"" }}"; - } } -} +} \ No newline at end of file diff --git a/ApiClient.Tests/Api/TfaApiTest.cs b/ApiClient.Tests/Api/TfaApiTest.cs index b9973c2..0c058f7 100644 --- a/ApiClient.Tests/Api/TfaApiTest.cs +++ b/ApiClient.Tests/Api/TfaApiTest.cs @@ -1,64 +1,63 @@ -using Infobip.Api.Client.Api; +using System.Globalization; +using Infobip.Api.Client.Api; using Infobip.Api.Client.Model; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -namespace ApiClient.Tests.Api +namespace ApiClient.Tests.Api; + +[TestClass] +public class TfaApiTest : ApiTest { - [TestClass] - public class TfaApiTest : ApiTest + protected const string TFA_APPLICATIONS = "/2fa/2/applications"; + protected const string TFA_APPLICATION = "/2fa/2/applications/{appId}"; + protected const string TFA_TEMPLATES = "/2fa/2/applications/{appId}/messages"; + protected const string TFA_TEMPLATE = "/2fa/2/applications/{appId}/messages/{msgId}"; + protected const string TFA_EMAIL_TEMPLATES = "/2fa/2/applications/{appId}/email/messages"; + protected const string TFA_EMAIL_TEMPLATE = "/2fa/2/applications/{appId}/email/messages/{msgId}"; + + protected const string TFA_SEND_PIN = "/2fa/2/pin"; + protected const string TFA_RESEND_PIN = "/2fa/2/pin/{pinId}/resend"; + protected const string TFA_SEND_PIN_VOICE = "/2fa/2/pin/voice"; + protected const string TFA_RESEND_PIN_VOICE = "/2fa/2/pin/{pinId}/resend/voice"; + protected const string TFA_SEND_PIN_EMAIL = "/2fa/2/pin/email"; + protected const string TFA_RESEND_PIN_EMAIL = "/2fa/2/pin/{pinId}/resend/email"; + protected const string TFA_VERIFY_PIN = "/2fa/2/pin/{pinId}/verify"; + protected const string TFA_VERIFICATION_STATUS = "/2fa/2/applications/{appId}/verifications"; + + [TestMethod] + public void ShouldGetTfaApplicationsTest() { - protected const string TFA_APPLICATIONS = "/2fa/2/applications"; - protected const string TFA_APPLICATION = "/2fa/2/applications/{appId}"; - protected const string TFA_TEMPLATES = "/2fa/2/applications/{appId}/messages"; - protected const string TFA_TEMPLATE = "/2fa/2/applications/{appId}/messages/{msgId}"; - protected const string TFA_EMAIL_TEMPLATES = "/2fa/2/applications/{appId}/email/messages"; - protected const string TFA_EMAIL_TEMPLATE = "/2fa/2/applications/{appId}/email/messages/{msgId}"; - - protected const string TFA_SEND_PIN = "/2fa/2/pin"; - protected const string TFA_RESEND_PIN = "/2fa/2/pin/{pinId}/resend"; - protected const string TFA_SEND_PIN_VOICE = "/2fa/2/pin/voice"; - protected const string TFA_RESEND_PIN_VOICE = "/2fa/2/pin/{pinId}/resend/voice"; - protected const string TFA_SEND_PIN_EMAIL = "/2fa/2/pin/email"; - protected const string TFA_RESEND_PIN_EMAIL = "/2fa/2/pin/{pinId}/resend/email"; - protected const string TFA_VERIFY_PIN = "/2fa/2/pin/{pinId}/verify"; - protected const string TFA_VERIFICATION_STATUS = "/2fa/2/applications/{appId}/verifications"; - - [TestMethod] - public void ShouldGetTfaApplicationsTest() - { - string expectedApplicationId1 = "0933F3BC087D2A617AC6DCB2EF5B8A61"; - string expectedGetApplicationName1 = "Test application BASIC 1"; - int expectedGetApplicationPinAttempts1 = 10; - string expectedAllowMultiplePinVerifications1 = "true"; - string expectedGetApplicationPinTimeToLive1 = "2h"; - string expectedGetApplicationVerifyPinLimit1 = "1/3s"; - string expectedGetApplicationSendPinPerApplicationLimit1 = "10000/1d"; - string expectedGetApplicationSendPinPerPhoneNumberLimit1 = "3/1d"; - string expectedEnabled1 = "true"; - - string expectedApplicationId2 = "5F04FACFAA4978F62FCAEBA97B37E90F"; - string expectedGetApplicationName2 = "Test application BASIC 2"; - int expectedGetApplicationPinAttempts2 = 12; - string expectedAllowMultiplePinVerifications2 = "true"; - string expectedGetApplicationPinTimeToLive2 = "10m"; - string expectedGetApplicationVerifyPinLimit2 = "2/1s"; - string expectedGetApplicationSendPinPerApplicationLimit2 = "10000/1d"; - string expectedGetApplicationSendPinPerPhoneNumberLimit2 = "5/1h"; - string expectedEnabled2 = "true"; - - string expectedApplicationId3 = "B450F966A8EF017180F148AF22C42642"; - string expectedGetApplicationName3 = "Test application BASIC 3"; - int expectedGetApplicationPinAttempts3 = 15; - string expectedAllowMultiplePinVerifications3 = "true"; - string expectedGetApplicationPinTimeToLive3 = "1h"; - string expectedGetApplicationVerifyPinLimit3 = "30/10s"; - string expectedGetApplicationSendPinPerApplicationLimit3 = "10000/3d"; - string expectedGetApplicationSendPinPerPhoneNumberLimit3 = "10/20m"; - string expectedEnabled3 = "true"; - - string expectedResponse = $@" + var expectedApplicationId1 = "0933F3BC087D2A617AC6DCB2EF5B8A61"; + var expectedGetApplicationName1 = "Test application BASIC 1"; + var expectedGetApplicationPinAttempts1 = 10; + var expectedAllowMultiplePinVerifications1 = "true"; + var expectedGetApplicationPinTimeToLive1 = "2h"; + var expectedGetApplicationVerifyPinLimit1 = "1/3s"; + var expectedGetApplicationSendPinPerApplicationLimit1 = "10000/1d"; + var expectedGetApplicationSendPinPerPhoneNumberLimit1 = "3/1d"; + var expectedEnabled1 = "true"; + + var expectedApplicationId2 = "5F04FACFAA4978F62FCAEBA97B37E90F"; + var expectedGetApplicationName2 = "Test application BASIC 2"; + var expectedGetApplicationPinAttempts2 = 12; + var expectedAllowMultiplePinVerifications2 = "true"; + var expectedGetApplicationPinTimeToLive2 = "10m"; + var expectedGetApplicationVerifyPinLimit2 = "2/1s"; + var expectedGetApplicationSendPinPerApplicationLimit2 = "10000/1d"; + var expectedGetApplicationSendPinPerPhoneNumberLimit2 = "5/1h"; + var expectedEnabled2 = "true"; + + var expectedApplicationId3 = "B450F966A8EF017180F148AF22C42642"; + var expectedGetApplicationName3 = "Test application BASIC 3"; + var expectedGetApplicationPinAttempts3 = 15; + var expectedAllowMultiplePinVerifications3 = "true"; + var expectedGetApplicationPinTimeToLive3 = "1h"; + var expectedGetApplicationVerifyPinLimit3 = "30/10s"; + var expectedGetApplicationSendPinPerApplicationLimit3 = "10000/3d"; + var expectedGetApplicationSendPinPerPhoneNumberLimit3 = "10/20m"; + var expectedEnabled3 = "true"; + + var expectedResponse = $@" [ {{ ""applicationId"": ""{expectedApplicationId1}"", @@ -101,70 +100,86 @@ public void ShouldGetTfaApplicationsTest() }} ]"; - SetUpGetRequest(TFA_APPLICATIONS, expectedResponse, 200); + SetUpGetRequest(TFA_APPLICATIONS, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - void AssertTfaGetApplicationsResponse(List tfaApplicationResponses) - { - Assert.IsNotNull(tfaApplicationResponses); - Assert.IsTrue(tfaApplicationResponses.Count.Equals(3)); - - var tfaApplicationResponse1 = tfaApplicationResponses[0]; - Assert.IsNotNull(tfaApplicationResponse1); - Assert.AreEqual(expectedApplicationId1, tfaApplicationResponse1.ApplicationId); - Assert.AreEqual(expectedGetApplicationName1, tfaApplicationResponse1.Name); - Assert.AreEqual(expectedGetApplicationPinAttempts1, tfaApplicationResponse1.VarConfiguration.PinAttempts); - Assert.AreEqual(bool.Parse(expectedAllowMultiplePinVerifications1), tfaApplicationResponse1.VarConfiguration.AllowMultiplePinVerifications); - Assert.AreEqual(expectedGetApplicationPinTimeToLive1, tfaApplicationResponse1.VarConfiguration.PinTimeToLive); - Assert.AreEqual(expectedGetApplicationVerifyPinLimit1, tfaApplicationResponse1.VarConfiguration.VerifyPinLimit); - Assert.AreEqual(expectedGetApplicationSendPinPerApplicationLimit1, tfaApplicationResponse1.VarConfiguration.SendPinPerApplicationLimit); - Assert.AreEqual(expectedGetApplicationSendPinPerPhoneNumberLimit1, tfaApplicationResponse1.VarConfiguration.SendPinPerPhoneNumberLimit); - - var tfaApplicationResponse2 = tfaApplicationResponses[1]; - Assert.IsNotNull(tfaApplicationResponse2); - Assert.AreEqual(expectedApplicationId2, tfaApplicationResponse2.ApplicationId); - Assert.AreEqual(expectedGetApplicationName2, tfaApplicationResponse2.Name); - Assert.AreEqual(expectedGetApplicationPinAttempts2, tfaApplicationResponse2.VarConfiguration.PinAttempts); - Assert.AreEqual(bool.Parse(expectedAllowMultiplePinVerifications2), tfaApplicationResponse2.VarConfiguration.AllowMultiplePinVerifications); - Assert.AreEqual(expectedGetApplicationPinTimeToLive2, tfaApplicationResponse2.VarConfiguration.PinTimeToLive); - Assert.AreEqual(expectedGetApplicationVerifyPinLimit2, tfaApplicationResponse2.VarConfiguration.VerifyPinLimit); - Assert.AreEqual(expectedGetApplicationSendPinPerApplicationLimit2, tfaApplicationResponse2.VarConfiguration.SendPinPerApplicationLimit); - Assert.AreEqual(expectedGetApplicationSendPinPerPhoneNumberLimit2, tfaApplicationResponse2.VarConfiguration.SendPinPerPhoneNumberLimit); - - var tfaApplicationResponse3 = tfaApplicationResponses[2]; - Assert.IsNotNull(tfaApplicationResponse3); - Assert.AreEqual(expectedApplicationId3, tfaApplicationResponse3.ApplicationId); - Assert.AreEqual(expectedGetApplicationName3, tfaApplicationResponse3.Name); - Assert.AreEqual(expectedGetApplicationPinAttempts3, tfaApplicationResponse3.VarConfiguration.PinAttempts); - Assert.AreEqual(bool.Parse(expectedAllowMultiplePinVerifications3), tfaApplicationResponse3.VarConfiguration.AllowMultiplePinVerifications); - Assert.AreEqual(expectedGetApplicationPinTimeToLive3, tfaApplicationResponse3.VarConfiguration.PinTimeToLive); - Assert.AreEqual(expectedGetApplicationVerifyPinLimit3, tfaApplicationResponse3.VarConfiguration.VerifyPinLimit); - Assert.AreEqual(expectedGetApplicationSendPinPerApplicationLimit3, tfaApplicationResponse3.VarConfiguration.SendPinPerApplicationLimit); - Assert.AreEqual(expectedGetApplicationSendPinPerPhoneNumberLimit3, tfaApplicationResponse3.VarConfiguration.SendPinPerPhoneNumberLimit); - } - - AssertResponse(tfaApi.GetTfaApplications(), AssertTfaGetApplicationsResponse); - AssertResponse(tfaApi.GetTfaApplicationsAsync().Result, AssertTfaGetApplicationsResponse); - - AssertResponseWithHttpInfo(tfaApi.GetTfaApplicationsWithHttpInfo(), AssertTfaGetApplicationsResponse); - AssertResponseWithHttpInfo(tfaApi.GetTfaApplicationsWithHttpInfoAsync().Result, AssertTfaGetApplicationsResponse); + void AssertTfaGetApplicationsResponse(List tfaApplicationResponses) + { + Assert.IsNotNull(tfaApplicationResponses); + Assert.IsTrue(tfaApplicationResponses.Count.Equals(3)); + + var tfaApplicationResponse1 = tfaApplicationResponses[0]; + Assert.IsNotNull(tfaApplicationResponse1); + Assert.AreEqual(expectedApplicationId1, tfaApplicationResponse1.ApplicationId); + Assert.AreEqual(expectedGetApplicationName1, tfaApplicationResponse1.Name); + Assert.AreEqual(expectedGetApplicationPinAttempts1, tfaApplicationResponse1.VarConfiguration.PinAttempts); + Assert.AreEqual(bool.Parse(expectedAllowMultiplePinVerifications1), + tfaApplicationResponse1.VarConfiguration.AllowMultiplePinVerifications); + Assert.AreEqual(expectedGetApplicationPinTimeToLive1, + tfaApplicationResponse1.VarConfiguration.PinTimeToLive); + Assert.AreEqual(expectedGetApplicationVerifyPinLimit1, + tfaApplicationResponse1.VarConfiguration.VerifyPinLimit); + Assert.AreEqual(expectedGetApplicationSendPinPerApplicationLimit1, + tfaApplicationResponse1.VarConfiguration.SendPinPerApplicationLimit); + Assert.AreEqual(expectedGetApplicationSendPinPerPhoneNumberLimit1, + tfaApplicationResponse1.VarConfiguration.SendPinPerPhoneNumberLimit); + + var tfaApplicationResponse2 = tfaApplicationResponses[1]; + Assert.IsNotNull(tfaApplicationResponse2); + Assert.AreEqual(expectedApplicationId2, tfaApplicationResponse2.ApplicationId); + Assert.AreEqual(expectedGetApplicationName2, tfaApplicationResponse2.Name); + Assert.AreEqual(expectedGetApplicationPinAttempts2, tfaApplicationResponse2.VarConfiguration.PinAttempts); + Assert.AreEqual(bool.Parse(expectedAllowMultiplePinVerifications2), + tfaApplicationResponse2.VarConfiguration.AllowMultiplePinVerifications); + Assert.AreEqual(expectedGetApplicationPinTimeToLive2, + tfaApplicationResponse2.VarConfiguration.PinTimeToLive); + Assert.AreEqual(expectedGetApplicationVerifyPinLimit2, + tfaApplicationResponse2.VarConfiguration.VerifyPinLimit); + Assert.AreEqual(expectedGetApplicationSendPinPerApplicationLimit2, + tfaApplicationResponse2.VarConfiguration.SendPinPerApplicationLimit); + Assert.AreEqual(expectedGetApplicationSendPinPerPhoneNumberLimit2, + tfaApplicationResponse2.VarConfiguration.SendPinPerPhoneNumberLimit); + + var tfaApplicationResponse3 = tfaApplicationResponses[2]; + Assert.IsNotNull(tfaApplicationResponse3); + Assert.AreEqual(expectedApplicationId3, tfaApplicationResponse3.ApplicationId); + Assert.AreEqual(expectedGetApplicationName3, tfaApplicationResponse3.Name); + Assert.AreEqual(expectedGetApplicationPinAttempts3, tfaApplicationResponse3.VarConfiguration.PinAttempts); + Assert.AreEqual(bool.Parse(expectedAllowMultiplePinVerifications3), + tfaApplicationResponse3.VarConfiguration.AllowMultiplePinVerifications); + Assert.AreEqual(expectedGetApplicationPinTimeToLive3, + tfaApplicationResponse3.VarConfiguration.PinTimeToLive); + Assert.AreEqual(expectedGetApplicationVerifyPinLimit3, + tfaApplicationResponse3.VarConfiguration.VerifyPinLimit); + Assert.AreEqual(expectedGetApplicationSendPinPerApplicationLimit3, + tfaApplicationResponse3.VarConfiguration.SendPinPerApplicationLimit); + Assert.AreEqual(expectedGetApplicationSendPinPerPhoneNumberLimit3, + tfaApplicationResponse3.VarConfiguration.SendPinPerPhoneNumberLimit); } - [TestMethod] - public void ShouldCreateTfaApplicationTest() - { - string expectedApplicationId = "1234567"; - string expectedCreateApplicationName = "2fa application name"; - int expectedCreateApplicationPinAttempts = 5; - string expectedAllowMultiplePinVerifications = "true"; - string expectedCreateApplicationPinTimeToLive = "10m"; - string expectedCreateApplicationVerifyPinLimit = "2/4s"; - string expectedCreateApplicationSendPinPerApplicationLimit = "5000/12h"; - string expectedCreateApplicationSendPinPerPhoneNumberLimit = "2/1d"; - string expectedEnabled = "true"; - - string givenRequest = $@" + AssertResponse(tfaApi.GetTfaApplications(), AssertTfaGetApplicationsResponse); + AssertResponse(tfaApi.GetTfaApplicationsAsync().Result, AssertTfaGetApplicationsResponse); + + AssertResponseWithHttpInfo(tfaApi.GetTfaApplicationsWithHttpInfo(), AssertTfaGetApplicationsResponse); + AssertResponseWithHttpInfo(tfaApi.GetTfaApplicationsWithHttpInfoAsync().Result, + AssertTfaGetApplicationsResponse); + } + + [TestMethod] + public void ShouldCreateTfaApplicationTest() + { + var expectedApplicationId = "1234567"; + var expectedCreateApplicationName = "2fa application name"; + var expectedCreateApplicationPinAttempts = 5; + var expectedAllowMultiplePinVerifications = "true"; + var expectedCreateApplicationPinTimeToLive = "10m"; + var expectedCreateApplicationVerifyPinLimit = "2/4s"; + var expectedCreateApplicationSendPinPerApplicationLimit = "5000/12h"; + var expectedCreateApplicationSendPinPerPhoneNumberLimit = "2/1d"; + var expectedEnabled = "true"; + + var givenRequest = $@" {{ ""name"": ""{expectedCreateApplicationName}"", ""enabled"": {expectedEnabled}, @@ -178,7 +193,7 @@ public void ShouldCreateTfaApplicationTest() }} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""applicationId"": ""{expectedApplicationId}"", ""name"": ""{expectedCreateApplicationName}"", @@ -193,56 +208,59 @@ public void ShouldCreateTfaApplicationTest() ""enabled"": {expectedEnabled} }}"; - SetUpPostRequest(TFA_APPLICATIONS, givenRequest, expectedResponse, 200); + SetUpPostRequest(TFA_APPLICATIONS, givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var tfaApplicationConfiguration = new TfaApplicationConfiguration() - { - PinAttempts = expectedCreateApplicationPinAttempts, - AllowMultiplePinVerifications = bool.Parse(expectedAllowMultiplePinVerifications), - PinTimeToLive = expectedCreateApplicationPinTimeToLive, - VerifyPinLimit = expectedCreateApplicationVerifyPinLimit, - SendPinPerApplicationLimit = expectedCreateApplicationSendPinPerApplicationLimit, - SendPinPerPhoneNumberLimit = expectedCreateApplicationSendPinPerPhoneNumberLimit - }; + var tfaApplicationConfiguration = new TfaApplicationConfiguration + { + PinAttempts = expectedCreateApplicationPinAttempts, + AllowMultiplePinVerifications = bool.Parse(expectedAllowMultiplePinVerifications), + PinTimeToLive = expectedCreateApplicationPinTimeToLive, + VerifyPinLimit = expectedCreateApplicationVerifyPinLimit, + SendPinPerApplicationLimit = expectedCreateApplicationSendPinPerApplicationLimit, + SendPinPerPhoneNumberLimit = expectedCreateApplicationSendPinPerPhoneNumberLimit + }; + + var tfaApplicationRequest = new TfaApplicationRequest( + tfaApplicationConfiguration, + bool.Parse(expectedEnabled), + expectedCreateApplicationName + ); + + void AssertTfaCreateApplicationResponse(TfaApplicationResponse tfaApplicationResponse) + { + Assert.IsNotNull(tfaApplicationResponse); + Assert.AreEqual(expectedApplicationId, tfaApplicationResponse.ApplicationId); + Assert.AreEqual(expectedCreateApplicationName, tfaApplicationResponse.Name); + Assert.AreEqual(tfaApplicationConfiguration, tfaApplicationResponse.VarConfiguration); + Assert.AreEqual(bool.Parse(expectedEnabled), tfaApplicationResponse.Enabled); + } - var tfaApplicationRequest = new TfaApplicationRequest( - varConfiguration: tfaApplicationConfiguration, - enabled: bool.Parse(expectedEnabled), - name: expectedCreateApplicationName - ); + AssertResponse(tfaApi.CreateTfaApplication(tfaApplicationRequest), AssertTfaCreateApplicationResponse); + AssertResponse(tfaApi.CreateTfaApplicationAsync(tfaApplicationRequest).Result, + AssertTfaCreateApplicationResponse); - void AssertTfaCreateApplicationResponse(TfaApplicationResponse tfaApplicationResponse) - { - Assert.IsNotNull(tfaApplicationResponse); - Assert.AreEqual(expectedApplicationId, tfaApplicationResponse.ApplicationId); - Assert.AreEqual(expectedCreateApplicationName, tfaApplicationResponse.Name); - Assert.AreEqual(tfaApplicationConfiguration, tfaApplicationResponse.VarConfiguration); - Assert.AreEqual(bool.Parse(expectedEnabled), tfaApplicationResponse.Enabled); - } - - AssertResponse(tfaApi.CreateTfaApplication(tfaApplicationRequest), AssertTfaCreateApplicationResponse); - AssertResponse(tfaApi.CreateTfaApplicationAsync(tfaApplicationRequest).Result, AssertTfaCreateApplicationResponse); - - AssertResponseWithHttpInfo(tfaApi.CreateTfaApplicationWithHttpInfo(tfaApplicationRequest), AssertTfaCreateApplicationResponse); - AssertResponseWithHttpInfo(tfaApi.CreateTfaApplicationWithHttpInfoAsync(tfaApplicationRequest).Result, AssertTfaCreateApplicationResponse); - } + AssertResponseWithHttpInfo(tfaApi.CreateTfaApplicationWithHttpInfo(tfaApplicationRequest), + AssertTfaCreateApplicationResponse); + AssertResponseWithHttpInfo(tfaApi.CreateTfaApplicationWithHttpInfoAsync(tfaApplicationRequest).Result, + AssertTfaCreateApplicationResponse); + } - [TestMethod] - public void ShouldGetTfaApplicationTest() - { - string expectedApplicationId = "1234567"; - string expectedGetApplicationName = "2fa application name"; - int expectedGetApplicationPinAttempts = 5; - string expectedAllowMultiplePinVerifications = "true"; - string expectedGetApplicationPinTimeToLive = "10m"; - string expectedGetApplicationVerifyPinLimit = "2/4s"; - string expectedGetApplicationSendPinPerApplicationLimit = "5000/12h"; - string expectedGetApplicationSendPinPerPhoneNumberLimit = "2/1d"; - string expectedEnabled = "true"; - - string expectedResponse = $@" + [TestMethod] + public void ShouldGetTfaApplicationTest() + { + var expectedApplicationId = "1234567"; + var expectedGetApplicationName = "2fa application name"; + var expectedGetApplicationPinAttempts = 5; + var expectedAllowMultiplePinVerifications = "true"; + var expectedGetApplicationPinTimeToLive = "10m"; + var expectedGetApplicationVerifyPinLimit = "2/4s"; + var expectedGetApplicationSendPinPerApplicationLimit = "5000/12h"; + var expectedGetApplicationSendPinPerPhoneNumberLimit = "2/1d"; + var expectedEnabled = "true"; + + var expectedResponse = $@" {{ ""applicationId"": ""{expectedApplicationId}"", ""name"": ""{expectedGetApplicationName}"", @@ -257,50 +275,52 @@ public void ShouldGetTfaApplicationTest() ""enabled"": {expectedEnabled} }}"; - SetUpGetRequest(TFA_APPLICATION.Replace("{appId}", expectedApplicationId), expectedResponse, 200); + SetUpGetRequest(TFA_APPLICATION.Replace("{appId}", expectedApplicationId), expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - void AssertTfaGetApplicationResponse(TfaApplicationResponse tfaApplicationResponse) + void AssertTfaGetApplicationResponse(TfaApplicationResponse tfaApplicationResponse) + { + var expectedApplicationConfiguration = new TfaApplicationConfiguration { - var expectedApplicationConfiguration = new TfaApplicationConfiguration() - { - PinAttempts = expectedGetApplicationPinAttempts, - AllowMultiplePinVerifications = bool.Parse(expectedAllowMultiplePinVerifications), - PinTimeToLive = expectedGetApplicationPinTimeToLive, - VerifyPinLimit = expectedGetApplicationVerifyPinLimit, - SendPinPerApplicationLimit = expectedGetApplicationSendPinPerApplicationLimit, - SendPinPerPhoneNumberLimit = expectedGetApplicationSendPinPerPhoneNumberLimit - }; - - Assert.IsNotNull(tfaApplicationResponse); - Assert.AreEqual(expectedApplicationId, tfaApplicationResponse.ApplicationId); - Assert.AreEqual(expectedGetApplicationName, tfaApplicationResponse.Name); - Assert.AreEqual(expectedApplicationConfiguration, tfaApplicationResponse.VarConfiguration); - Assert.AreEqual(bool.Parse(expectedEnabled), tfaApplicationResponse.Enabled); - } - - AssertResponse(tfaApi.GetTfaApplication(expectedApplicationId), AssertTfaGetApplicationResponse); - AssertResponse(tfaApi.GetTfaApplicationAsync(expectedApplicationId).Result, AssertTfaGetApplicationResponse); - - AssertResponseWithHttpInfo(tfaApi.GetTfaApplicationWithHttpInfo(expectedApplicationId), AssertTfaGetApplicationResponse); - AssertResponseWithHttpInfo(tfaApi.GetTfaApplicationWithHttpInfoAsync(expectedApplicationId).Result, AssertTfaGetApplicationResponse); + PinAttempts = expectedGetApplicationPinAttempts, + AllowMultiplePinVerifications = bool.Parse(expectedAllowMultiplePinVerifications), + PinTimeToLive = expectedGetApplicationPinTimeToLive, + VerifyPinLimit = expectedGetApplicationVerifyPinLimit, + SendPinPerApplicationLimit = expectedGetApplicationSendPinPerApplicationLimit, + SendPinPerPhoneNumberLimit = expectedGetApplicationSendPinPerPhoneNumberLimit + }; + + Assert.IsNotNull(tfaApplicationResponse); + Assert.AreEqual(expectedApplicationId, tfaApplicationResponse.ApplicationId); + Assert.AreEqual(expectedGetApplicationName, tfaApplicationResponse.Name); + Assert.AreEqual(expectedApplicationConfiguration, tfaApplicationResponse.VarConfiguration); + Assert.AreEqual(bool.Parse(expectedEnabled), tfaApplicationResponse.Enabled); } - [TestMethod] - public void ShouldUpdateTfaApplicationTest() - { - string expectedApplicationId = "1234567"; - string expectedCreateApplicationName = "2fa application name"; - int expectedCreateApplicationPinAttempts = 5; - string expectedAllowMultiplePinVerifications = "true"; - string expectedCreateApplicationPinTimeToLive = "10m"; - string expectedCreateApplicationVerifyPinLimit = "2/4s"; - string expectedCreateApplicationSendPinPerApplicationLimit = "5000/12h"; - string expectedCreateApplicationSendPinPerPhoneNumberLimit = "2/1d"; - string expectedEnabled = "true"; - - string givenRequest = $@" + AssertResponse(tfaApi.GetTfaApplication(expectedApplicationId), AssertTfaGetApplicationResponse); + AssertResponse(tfaApi.GetTfaApplicationAsync(expectedApplicationId).Result, AssertTfaGetApplicationResponse); + + AssertResponseWithHttpInfo(tfaApi.GetTfaApplicationWithHttpInfo(expectedApplicationId), + AssertTfaGetApplicationResponse); + AssertResponseWithHttpInfo(tfaApi.GetTfaApplicationWithHttpInfoAsync(expectedApplicationId).Result, + AssertTfaGetApplicationResponse); + } + + [TestMethod] + public void ShouldUpdateTfaApplicationTest() + { + var expectedApplicationId = "1234567"; + var expectedCreateApplicationName = "2fa application name"; + var expectedCreateApplicationPinAttempts = 5; + var expectedAllowMultiplePinVerifications = "true"; + var expectedCreateApplicationPinTimeToLive = "10m"; + var expectedCreateApplicationVerifyPinLimit = "2/4s"; + var expectedCreateApplicationSendPinPerApplicationLimit = "5000/12h"; + var expectedCreateApplicationSendPinPerPhoneNumberLimit = "2/1d"; + var expectedEnabled = "true"; + + var givenRequest = $@" {{ ""name"": ""{expectedCreateApplicationName}"", ""enabled"": {expectedEnabled}, @@ -314,7 +334,7 @@ public void ShouldUpdateTfaApplicationTest() }} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""applicationId"": ""{expectedApplicationId}"", ""name"": ""{expectedCreateApplicationName}"", @@ -329,57 +349,63 @@ public void ShouldUpdateTfaApplicationTest() ""enabled"": {expectedEnabled} }}"; - SetUpPutRequest(TFA_APPLICATION.Replace("{appId}", expectedApplicationId), givenRequest, expectedResponse, 200); + SetUpPutRequest(TFA_APPLICATION.Replace("{appId}", expectedApplicationId), givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var tfaApplicationConfiguration = new TfaApplicationConfiguration() - { - PinAttempts = expectedCreateApplicationPinAttempts, - AllowMultiplePinVerifications = bool.Parse(expectedAllowMultiplePinVerifications), - PinTimeToLive = expectedCreateApplicationPinTimeToLive, - VerifyPinLimit = expectedCreateApplicationVerifyPinLimit, - SendPinPerApplicationLimit = expectedCreateApplicationSendPinPerApplicationLimit, - SendPinPerPhoneNumberLimit = expectedCreateApplicationSendPinPerPhoneNumberLimit - }; - - var tfaApplicationRequest = new TfaApplicationRequest( - varConfiguration: tfaApplicationConfiguration, - enabled: bool.Parse(expectedEnabled), - name: expectedCreateApplicationName - ); - - void AssertTfaUpdateApplicationResponse(TfaApplicationResponse tfaApplicationResponse) - { - Assert.IsNotNull(tfaApplicationResponse); - Assert.AreEqual(expectedApplicationId, tfaApplicationResponse.ApplicationId); - Assert.AreEqual(expectedCreateApplicationName, tfaApplicationResponse.Name); - Assert.AreEqual(tfaApplicationConfiguration, tfaApplicationResponse.VarConfiguration); - Assert.AreEqual(bool.Parse(expectedEnabled), tfaApplicationResponse.Enabled); - } - - AssertResponse(tfaApi.UpdateTfaApplication(expectedApplicationId, tfaApplicationRequest), AssertTfaUpdateApplicationResponse); - AssertResponse(tfaApi.UpdateTfaApplicationAsync(expectedApplicationId, tfaApplicationRequest).Result, AssertTfaUpdateApplicationResponse); - - AssertResponseWithHttpInfo(tfaApi.UpdateTfaApplicationWithHttpInfo(expectedApplicationId, tfaApplicationRequest), AssertTfaUpdateApplicationResponse); - AssertResponseWithHttpInfo(tfaApi.UpdateTfaApplicationWithHttpInfoAsync(expectedApplicationId, tfaApplicationRequest).Result, AssertTfaUpdateApplicationResponse); + var tfaApplicationConfiguration = new TfaApplicationConfiguration + { + PinAttempts = expectedCreateApplicationPinAttempts, + AllowMultiplePinVerifications = bool.Parse(expectedAllowMultiplePinVerifications), + PinTimeToLive = expectedCreateApplicationPinTimeToLive, + VerifyPinLimit = expectedCreateApplicationVerifyPinLimit, + SendPinPerApplicationLimit = expectedCreateApplicationSendPinPerApplicationLimit, + SendPinPerPhoneNumberLimit = expectedCreateApplicationSendPinPerPhoneNumberLimit + }; + + var tfaApplicationRequest = new TfaApplicationRequest( + tfaApplicationConfiguration, + bool.Parse(expectedEnabled), + expectedCreateApplicationName + ); + + void AssertTfaUpdateApplicationResponse(TfaApplicationResponse tfaApplicationResponse) + { + Assert.IsNotNull(tfaApplicationResponse); + Assert.AreEqual(expectedApplicationId, tfaApplicationResponse.ApplicationId); + Assert.AreEqual(expectedCreateApplicationName, tfaApplicationResponse.Name); + Assert.AreEqual(tfaApplicationConfiguration, tfaApplicationResponse.VarConfiguration); + Assert.AreEqual(bool.Parse(expectedEnabled), tfaApplicationResponse.Enabled); } - [TestMethod] - public void ShouldGetTfaMessageTemplatesTest() - { - string givenApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; - - string expectedPinPlaceholder = "{{pin}}"; - string expectedMessageText = string.Format("Your PIN is {0}.", expectedPinPlaceholder); - int expectedPinLength = 4; - string expectedPinType = "Alphanumeric"; - string expectedLanguage = "En"; - string expectedSenderId = "Infobip 2FA"; - string expectedRepeatDtmf = "1#"; - double expectedSpeechRate = 1; - - string expectedResponse = $@" + AssertResponse(tfaApi.UpdateTfaApplication(expectedApplicationId, tfaApplicationRequest), + AssertTfaUpdateApplicationResponse); + AssertResponse(tfaApi.UpdateTfaApplicationAsync(expectedApplicationId, tfaApplicationRequest).Result, + AssertTfaUpdateApplicationResponse); + + AssertResponseWithHttpInfo( + tfaApi.UpdateTfaApplicationWithHttpInfo(expectedApplicationId, tfaApplicationRequest), + AssertTfaUpdateApplicationResponse); + AssertResponseWithHttpInfo( + tfaApi.UpdateTfaApplicationWithHttpInfoAsync(expectedApplicationId, tfaApplicationRequest).Result, + AssertTfaUpdateApplicationResponse); + } + + [TestMethod] + public void ShouldGetTfaMessageTemplatesTest() + { + var givenApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; + + var expectedPinPlaceholder = "{{pin}}"; + var expectedMessageText = string.Format("Your PIN is {0}.", expectedPinPlaceholder); + var expectedPinLength = 4; + var expectedPinType = "Alphanumeric"; + var expectedLanguage = "En"; + var expectedSenderId = "Infobip 2FA"; + var expectedRepeatDtmf = "1#"; + double expectedSpeechRate = 1; + + var expectedResponse = $@" [ {{ ""pinPlaceholder"": ""{expectedPinPlaceholder}"", @@ -393,48 +419,50 @@ public void ShouldGetTfaMessageTemplatesTest() }} ]"; - SetUpGetRequest(TFA_TEMPLATES.Replace("{appId}", givenApplicationId), expectedResponse, 200); + SetUpGetRequest(TFA_TEMPLATES.Replace("{appId}", givenApplicationId), expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - void AssertTfaGetTemplatesResponse(List tfaMessages) - { - Assert.IsNotNull(tfaMessages); - var tfaMessage = tfaMessages[0]; - - Assert.IsNotNull(tfaMessage); - Assert.AreEqual(expectedPinPlaceholder, tfaMessage.PinPlaceholder); - Assert.AreEqual(expectedMessageText, tfaMessage.MessageText); - Assert.AreEqual(expectedPinLength, tfaMessage.PinLength); - Assert.AreEqual(Enum.Parse(expectedPinType), tfaMessage.PinType); - Assert.AreEqual(Enum.Parse(expectedLanguage), tfaMessage.Language); - Assert.AreEqual(expectedSenderId, tfaMessage.SenderId); - Assert.AreEqual(expectedRepeatDtmf, tfaMessage.RepeatDTMF); - Assert.AreEqual(expectedSpeechRate, tfaMessage.SpeechRate); - } - - AssertResponse(tfaApi.GetTfaMessageTemplates(givenApplicationId), AssertTfaGetTemplatesResponse); - AssertResponse(tfaApi.GetTfaMessageTemplatesAsync(givenApplicationId).Result, AssertTfaGetTemplatesResponse); - - AssertResponseWithHttpInfo(tfaApi.GetTfaMessageTemplatesWithHttpInfo(givenApplicationId), AssertTfaGetTemplatesResponse); - AssertResponseWithHttpInfo(tfaApi.GetTfaMessageTemplatesWithHttpInfoAsync(givenApplicationId).Result, AssertTfaGetTemplatesResponse); + void AssertTfaGetTemplatesResponse(List tfaMessages) + { + Assert.IsNotNull(tfaMessages); + var tfaMessage = tfaMessages[0]; + + Assert.IsNotNull(tfaMessage); + Assert.AreEqual(expectedPinPlaceholder, tfaMessage.PinPlaceholder); + Assert.AreEqual(expectedMessageText, tfaMessage.MessageText); + Assert.AreEqual(expectedPinLength, tfaMessage.PinLength); + Assert.AreEqual(Enum.Parse(expectedPinType), tfaMessage.PinType); + Assert.AreEqual(Enum.Parse(expectedLanguage), tfaMessage.Language); + Assert.AreEqual(expectedSenderId, tfaMessage.SenderId); + Assert.AreEqual(expectedRepeatDtmf, tfaMessage.RepeatDTMF); + Assert.AreEqual(expectedSpeechRate, tfaMessage.SpeechRate); } - [TestMethod] - public void ShouldCreateTfaMessageTemplateTest() - { - string givenApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; - - string expectedPinPlaceholder = "{{pin}}"; - string expectedMessageText = string.Format("Your PIN is {0}.", expectedPinPlaceholder); - int expectedPinLength = 4; - string expectedPinType = "Alphanumeric"; - string expectedLanguage = "en"; - string expectedSenderId = "Infobip 2FA"; - string expectedRepeatDtmf = "1#"; - string expectedSpeechRate = "1.0"; - - string givenRequest = $@" + AssertResponse(tfaApi.GetTfaMessageTemplates(givenApplicationId), AssertTfaGetTemplatesResponse); + AssertResponse(tfaApi.GetTfaMessageTemplatesAsync(givenApplicationId).Result, AssertTfaGetTemplatesResponse); + + AssertResponseWithHttpInfo(tfaApi.GetTfaMessageTemplatesWithHttpInfo(givenApplicationId), + AssertTfaGetTemplatesResponse); + AssertResponseWithHttpInfo(tfaApi.GetTfaMessageTemplatesWithHttpInfoAsync(givenApplicationId).Result, + AssertTfaGetTemplatesResponse); + } + + [TestMethod] + public void ShouldCreateTfaMessageTemplateTest() + { + var givenApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; + + var expectedPinPlaceholder = "{{pin}}"; + var expectedMessageText = string.Format("Your PIN is {0}.", expectedPinPlaceholder); + var expectedPinLength = 4; + var expectedPinType = "Alphanumeric"; + var expectedLanguage = "en"; + var expectedSenderId = "Infobip 2FA"; + var expectedRepeatDtmf = "1#"; + var expectedSpeechRate = "1.0"; + + var givenRequest = $@" {{ ""language"": ""{expectedLanguage}"", ""pinType"": ""{expectedPinType}"", @@ -445,7 +473,7 @@ public void ShouldCreateTfaMessageTemplateTest() ""speechRate"": {expectedSpeechRate} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""pinPlaceholder"": ""{expectedPinPlaceholder}"", ""pinType"": ""{expectedPinType}"", @@ -457,56 +485,62 @@ public void ShouldCreateTfaMessageTemplateTest() ""speechRate"": {expectedSpeechRate} }}"; - SetUpPostRequest(TFA_TEMPLATES.Replace("{appId}", givenApplicationId), givenRequest, expectedResponse, 200); + SetUpPostRequest(TFA_TEMPLATES.Replace("{appId}", givenApplicationId), givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var tfaCreateMessageRequest = new TfaCreateMessageRequest( - language: Enum.Parse(expectedLanguage, true), - messageText: expectedMessageText, - pinLength: expectedPinLength, - pinType: Enum.Parse(expectedPinType, true), - repeatDTMF: expectedRepeatDtmf, - senderId: expectedSenderId, - speechRate: double.Parse(expectedSpeechRate, System.Globalization.CultureInfo.InvariantCulture) - ); + var tfaCreateMessageRequest = new TfaCreateMessageRequest( + Enum.Parse(expectedLanguage, true), + expectedMessageText, + expectedPinLength, + Enum.Parse(expectedPinType, true), + repeatDTMF: expectedRepeatDtmf, + senderId: expectedSenderId, + speechRate: double.Parse(expectedSpeechRate, CultureInfo.InvariantCulture) + ); - void AssertTfaCreateTemplateResponse(TfaMessage tfaMessage) - { - Assert.IsNotNull(tfaMessage); - Assert.AreEqual(expectedPinPlaceholder, tfaMessage.PinPlaceholder); - Assert.AreEqual(expectedMessageText, tfaMessage.MessageText); - Assert.AreEqual(expectedPinLength, tfaMessage.PinLength); - Assert.AreEqual(Enum.Parse(expectedPinType, true), tfaMessage.PinType); - Assert.AreEqual(Enum.Parse(expectedLanguage, true), tfaMessage.Language); - Assert.AreEqual(expectedSenderId, tfaMessage.SenderId); - Assert.AreEqual(expectedRepeatDtmf, tfaMessage.RepeatDTMF); - Assert.AreEqual(double.Parse(expectedSpeechRate, System.Globalization.CultureInfo.InvariantCulture), tfaMessage.SpeechRate); - } - - AssertResponse(tfaApi.CreateTfaMessageTemplate(givenApplicationId, tfaCreateMessageRequest), AssertTfaCreateTemplateResponse); - AssertResponse(tfaApi.CreateTfaMessageTemplateAsync(givenApplicationId, tfaCreateMessageRequest).Result, AssertTfaCreateTemplateResponse); - - AssertResponseWithHttpInfo(tfaApi.CreateTfaMessageTemplateWithHttpInfo(givenApplicationId, tfaCreateMessageRequest), AssertTfaCreateTemplateResponse); - AssertResponseWithHttpInfo(tfaApi.CreateTfaMessageTemplateWithHttpInfoAsync(givenApplicationId, tfaCreateMessageRequest).Result, AssertTfaCreateTemplateResponse); + void AssertTfaCreateTemplateResponse(TfaMessage tfaMessage) + { + Assert.IsNotNull(tfaMessage); + Assert.AreEqual(expectedPinPlaceholder, tfaMessage.PinPlaceholder); + Assert.AreEqual(expectedMessageText, tfaMessage.MessageText); + Assert.AreEqual(expectedPinLength, tfaMessage.PinLength); + Assert.AreEqual(Enum.Parse(expectedPinType, true), tfaMessage.PinType); + Assert.AreEqual(Enum.Parse(expectedLanguage, true), tfaMessage.Language); + Assert.AreEqual(expectedSenderId, tfaMessage.SenderId); + Assert.AreEqual(expectedRepeatDtmf, tfaMessage.RepeatDTMF); + Assert.AreEqual(double.Parse(expectedSpeechRate, CultureInfo.InvariantCulture), tfaMessage.SpeechRate); } - [TestMethod] - public void ShouldGetTfaMessageTemplateTest() - { - string givenApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; - string givenMessageId = "9C815F8AF3328"; - - string expectedPinPlaceholder = "{{pin}}"; - string expectedMessageText = string.Format("Your PIN is {0}.", expectedPinPlaceholder); - int expectedPinLength = 4; - string expectedPinType = "Alphanumeric"; - string expectedLanguage = "En"; - string expectedSenderId = "Infobip 2FA"; - string expectedRepeatDtmf = "1#"; - double expectedSpeechRate = 1.0; - - string expectedResponse = $@" + AssertResponse(tfaApi.CreateTfaMessageTemplate(givenApplicationId, tfaCreateMessageRequest), + AssertTfaCreateTemplateResponse); + AssertResponse(tfaApi.CreateTfaMessageTemplateAsync(givenApplicationId, tfaCreateMessageRequest).Result, + AssertTfaCreateTemplateResponse); + + AssertResponseWithHttpInfo( + tfaApi.CreateTfaMessageTemplateWithHttpInfo(givenApplicationId, tfaCreateMessageRequest), + AssertTfaCreateTemplateResponse); + AssertResponseWithHttpInfo( + tfaApi.CreateTfaMessageTemplateWithHttpInfoAsync(givenApplicationId, tfaCreateMessageRequest).Result, + AssertTfaCreateTemplateResponse); + } + + [TestMethod] + public void ShouldGetTfaMessageTemplateTest() + { + var givenApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; + var givenMessageId = "9C815F8AF3328"; + + var expectedPinPlaceholder = "{{pin}}"; + var expectedMessageText = string.Format("Your PIN is {0}.", expectedPinPlaceholder); + var expectedPinLength = 4; + var expectedPinType = "Alphanumeric"; + var expectedLanguage = "En"; + var expectedSenderId = "Infobip 2FA"; + var expectedRepeatDtmf = "1#"; + var expectedSpeechRate = 1.0; + + var expectedResponse = $@" {{ ""pinPlaceholder"": ""{expectedPinPlaceholder}"", ""pinType"": ""{expectedPinType}"", @@ -518,46 +552,51 @@ public void ShouldGetTfaMessageTemplateTest() ""speechRate"": {expectedSpeechRate} }}"; - SetUpGetRequest(TFA_TEMPLATE.Replace("{appId}", givenApplicationId).Replace("{msgId}", givenMessageId), expectedResponse, 200); + SetUpGetRequest(TFA_TEMPLATE.Replace("{appId}", givenApplicationId).Replace("{msgId}", givenMessageId), + expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - void AssertTfaGetTemplateResponse(TfaMessage tfaMessage) - { - Assert.IsNotNull(tfaMessage); - Assert.AreEqual(expectedPinPlaceholder, tfaMessage.PinPlaceholder); - Assert.AreEqual(expectedMessageText, tfaMessage.MessageText); - Assert.AreEqual(expectedPinLength, tfaMessage.PinLength); - Assert.AreEqual(Enum.Parse(expectedPinType), tfaMessage.PinType); - Assert.AreEqual(Enum.Parse(expectedLanguage), tfaMessage.Language); - Assert.AreEqual(expectedSenderId, tfaMessage.SenderId); - Assert.AreEqual(expectedRepeatDtmf, tfaMessage.RepeatDTMF); - Assert.AreEqual(expectedSpeechRate, tfaMessage.SpeechRate); - } - - AssertResponse(tfaApi.GetTfaMessageTemplate(givenApplicationId, givenMessageId), AssertTfaGetTemplateResponse); - AssertResponse(tfaApi.GetTfaMessageTemplateAsync(givenApplicationId, givenMessageId).Result, AssertTfaGetTemplateResponse); - - AssertResponseWithHttpInfo(tfaApi.GetTfaMessageTemplateWithHttpInfo(givenApplicationId, givenMessageId), AssertTfaGetTemplateResponse); - AssertResponseWithHttpInfo(tfaApi.GetTfaMessageTemplateWithHttpInfoAsync(givenApplicationId, givenMessageId).Result, AssertTfaGetTemplateResponse); + void AssertTfaGetTemplateResponse(TfaMessage tfaMessage) + { + Assert.IsNotNull(tfaMessage); + Assert.AreEqual(expectedPinPlaceholder, tfaMessage.PinPlaceholder); + Assert.AreEqual(expectedMessageText, tfaMessage.MessageText); + Assert.AreEqual(expectedPinLength, tfaMessage.PinLength); + Assert.AreEqual(Enum.Parse(expectedPinType), tfaMessage.PinType); + Assert.AreEqual(Enum.Parse(expectedLanguage), tfaMessage.Language); + Assert.AreEqual(expectedSenderId, tfaMessage.SenderId); + Assert.AreEqual(expectedRepeatDtmf, tfaMessage.RepeatDTMF); + Assert.AreEqual(expectedSpeechRate, tfaMessage.SpeechRate); } - [TestMethod] - public void ShouldUpdateTfaMessageTemplateTest() - { - string givenApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; - string givenMessageId = "5E3A6EA43432G5F3"; - - string expectedPinPlaceholder = "{{pin}}"; - string expectedMessageText = string.Format("Your PIN is {0}.", expectedPinPlaceholder); - int expectedPinLength = 4; - string expectedPinType = "Alphanumeric"; - string expectedLanguage = "en"; - string expectedSenderId = "Infobip 2FA"; - string expectedRepeatDtmf = "1#"; - string expectedSpeechRate = "1.0"; - - string givenRequest = $@" + AssertResponse(tfaApi.GetTfaMessageTemplate(givenApplicationId, givenMessageId), AssertTfaGetTemplateResponse); + AssertResponse(tfaApi.GetTfaMessageTemplateAsync(givenApplicationId, givenMessageId).Result, + AssertTfaGetTemplateResponse); + + AssertResponseWithHttpInfo(tfaApi.GetTfaMessageTemplateWithHttpInfo(givenApplicationId, givenMessageId), + AssertTfaGetTemplateResponse); + AssertResponseWithHttpInfo( + tfaApi.GetTfaMessageTemplateWithHttpInfoAsync(givenApplicationId, givenMessageId).Result, + AssertTfaGetTemplateResponse); + } + + [TestMethod] + public void ShouldUpdateTfaMessageTemplateTest() + { + var givenApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; + var givenMessageId = "5E3A6EA43432G5F3"; + + var expectedPinPlaceholder = "{{pin}}"; + var expectedMessageText = string.Format("Your PIN is {0}.", expectedPinPlaceholder); + var expectedPinLength = 4; + var expectedPinType = "Alphanumeric"; + var expectedLanguage = "en"; + var expectedSenderId = "Infobip 2FA"; + var expectedRepeatDtmf = "1#"; + var expectedSpeechRate = "1.0"; + + var givenRequest = $@" {{ ""language"": ""{expectedLanguage}"", ""pinType"": ""{expectedPinType}"", @@ -569,7 +608,7 @@ public void ShouldUpdateTfaMessageTemplateTest() }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""pinPlaceholder"": ""{expectedPinPlaceholder}"", ""pinType"": ""{expectedPinType}"", @@ -581,51 +620,59 @@ public void ShouldUpdateTfaMessageTemplateTest() ""speechRate"": {expectedSpeechRate} }}"; - SetUpPutRequest(TFA_TEMPLATE.Replace("{appId}", givenApplicationId).Replace("{msgId}", givenMessageId), givenRequest, expectedResponse, 200); + SetUpPutRequest(TFA_TEMPLATE.Replace("{appId}", givenApplicationId).Replace("{msgId}", givenMessageId), + givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var tfaUpdateMessageRequest = new TfaUpdateMessageRequest( - language: Enum.Parse(expectedLanguage, true), - messageText: expectedMessageText, - pinLength: expectedPinLength, - pinType: Enum.Parse(expectedPinType, true), - repeatDTMF: expectedRepeatDtmf, - senderId: expectedSenderId, - speechRate: double.Parse(expectedSpeechRate, System.Globalization.CultureInfo.InvariantCulture) - ); + var tfaUpdateMessageRequest = new TfaUpdateMessageRequest( + Enum.Parse(expectedLanguage, true), + expectedMessageText, + expectedPinLength, + Enum.Parse(expectedPinType, true), + repeatDTMF: expectedRepeatDtmf, + senderId: expectedSenderId, + speechRate: double.Parse(expectedSpeechRate, CultureInfo.InvariantCulture) + ); - void AssertTfaUpdateTemplateResponse(TfaMessage tfaMessage) - { - Assert.IsNotNull(tfaMessage); - Assert.AreEqual(expectedPinPlaceholder, tfaMessage.PinPlaceholder); - Assert.AreEqual(expectedMessageText, tfaMessage.MessageText); - Assert.AreEqual(expectedPinLength, tfaMessage.PinLength); - Assert.AreEqual(Enum.Parse(expectedPinType, true), tfaMessage.PinType); - Assert.AreEqual(Enum.Parse(expectedLanguage, true), tfaMessage.Language); - Assert.AreEqual(expectedSenderId, tfaMessage.SenderId); - Assert.AreEqual(expectedRepeatDtmf, tfaMessage.RepeatDTMF); - Assert.AreEqual(double.Parse(expectedSpeechRate, System.Globalization.CultureInfo.InvariantCulture), tfaMessage.SpeechRate); - } - - AssertResponse(tfaApi.UpdateTfaMessageTemplate(givenApplicationId, givenMessageId, tfaUpdateMessageRequest), AssertTfaUpdateTemplateResponse); - AssertResponse(tfaApi.UpdateTfaMessageTemplateAsync(givenApplicationId, givenMessageId, tfaUpdateMessageRequest).Result, AssertTfaUpdateTemplateResponse); - - AssertResponseWithHttpInfo(tfaApi.UpdateTfaMessageTemplateWithHttpInfo(givenApplicationId, givenMessageId, tfaUpdateMessageRequest), AssertTfaUpdateTemplateResponse); - AssertResponseWithHttpInfo(tfaApi.UpdateTfaMessageTemplateWithHttpInfoAsync(givenApplicationId, givenMessageId, tfaUpdateMessageRequest).Result, AssertTfaUpdateTemplateResponse); + void AssertTfaUpdateTemplateResponse(TfaMessage tfaMessage) + { + Assert.IsNotNull(tfaMessage); + Assert.AreEqual(expectedPinPlaceholder, tfaMessage.PinPlaceholder); + Assert.AreEqual(expectedMessageText, tfaMessage.MessageText); + Assert.AreEqual(expectedPinLength, tfaMessage.PinLength); + Assert.AreEqual(Enum.Parse(expectedPinType, true), tfaMessage.PinType); + Assert.AreEqual(Enum.Parse(expectedLanguage, true), tfaMessage.Language); + Assert.AreEqual(expectedSenderId, tfaMessage.SenderId); + Assert.AreEqual(expectedRepeatDtmf, tfaMessage.RepeatDTMF); + Assert.AreEqual(double.Parse(expectedSpeechRate, CultureInfo.InvariantCulture), tfaMessage.SpeechRate); } - [TestMethod] - public void ShouldCreateTfaEmailMessageTemplateTest() - { - TfaPinType expectedPinType = TfaPinType.Numeric; - int expectedPinLength = 4; - string expectedFrom = "company@example.com"; - int expectedEmailTemplateId = 1234; - string expectedMessageId = "9C815F8AF3328"; - string expectedApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; - - string givenRequest = $@" + AssertResponse(tfaApi.UpdateTfaMessageTemplate(givenApplicationId, givenMessageId, tfaUpdateMessageRequest), + AssertTfaUpdateTemplateResponse); + AssertResponse( + tfaApi.UpdateTfaMessageTemplateAsync(givenApplicationId, givenMessageId, tfaUpdateMessageRequest).Result, + AssertTfaUpdateTemplateResponse); + + AssertResponseWithHttpInfo( + tfaApi.UpdateTfaMessageTemplateWithHttpInfo(givenApplicationId, givenMessageId, tfaUpdateMessageRequest), + AssertTfaUpdateTemplateResponse); + AssertResponseWithHttpInfo( + tfaApi.UpdateTfaMessageTemplateWithHttpInfoAsync(givenApplicationId, givenMessageId, + tfaUpdateMessageRequest).Result, AssertTfaUpdateTemplateResponse); + } + + [TestMethod] + public void ShouldCreateTfaEmailMessageTemplateTest() + { + var expectedPinType = TfaPinType.Numeric; + var expectedPinLength = 4; + var expectedFrom = "company@example.com"; + var expectedEmailTemplateId = 1234; + var expectedMessageId = "9C815F8AF3328"; + var expectedApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; + + var givenRequest = $@" {{ ""pinType"": ""{expectedPinType}"", ""pinLength"": {expectedPinLength}, @@ -633,7 +680,7 @@ public void ShouldCreateTfaEmailMessageTemplateTest() ""emailTemplateId"": {expectedEmailTemplateId} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""messageId"": ""{expectedMessageId}"", ""applicationId"": ""{expectedApplicationId}"", @@ -643,47 +690,54 @@ public void ShouldCreateTfaEmailMessageTemplateTest() ""emailTemplateId"": {expectedEmailTemplateId} }}"; - SetUpPostRequest(TFA_EMAIL_TEMPLATES.Replace("{appId}", expectedApplicationId), givenRequest, expectedResponse, 200); + SetUpPostRequest(TFA_EMAIL_TEMPLATES.Replace("{appId}", expectedApplicationId), givenRequest, expectedResponse, + 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var tfaCreateEmailMessageRequest = new TfaCreateEmailMessageRequest( - pinType: expectedPinType, - pinLength: expectedPinLength, - from: expectedFrom, - emailTemplateId: expectedEmailTemplateId - ); - - void AssertTfaCreateEmailMessageResponse(TfaEmailMessage tfaEmailMessage) - { - Assert.IsNotNull(tfaEmailMessage); - Assert.AreEqual(expectedMessageId, tfaEmailMessage.MessageId); - Assert.AreEqual(expectedApplicationId, tfaEmailMessage.ApplicationId); - Assert.AreEqual(expectedPinLength, tfaEmailMessage.PinLength); - Assert.AreEqual(expectedPinType, tfaEmailMessage.PinType); - Assert.AreEqual(expectedFrom, tfaEmailMessage.From); - Assert.AreEqual(expectedEmailTemplateId, tfaEmailMessage.EmailTemplateId); - } - - AssertResponse(tfaApi.CreateTfaEmailMessageTemplate(expectedApplicationId, tfaCreateEmailMessageRequest), AssertTfaCreateEmailMessageResponse); - AssertResponse(tfaApi.CreateTfaEmailMessageTemplateAsync(expectedApplicationId, tfaCreateEmailMessageRequest).Result, AssertTfaCreateEmailMessageResponse); - - AssertResponseWithHttpInfo(tfaApi.CreateTfaEmailMessageTemplateWithHttpInfo(expectedApplicationId, tfaCreateEmailMessageRequest), AssertTfaCreateEmailMessageResponse); - AssertResponseWithHttpInfo(tfaApi.CreateTfaEmailMessageTemplateWithHttpInfoAsync(expectedApplicationId, tfaCreateEmailMessageRequest).Result, AssertTfaCreateEmailMessageResponse); + var tfaCreateEmailMessageRequest = new TfaCreateEmailMessageRequest( + pinType: expectedPinType, + pinLength: expectedPinLength, + from: expectedFrom, + emailTemplateId: expectedEmailTemplateId + ); + void AssertTfaCreateEmailMessageResponse(TfaEmailMessage tfaEmailMessage) + { + Assert.IsNotNull(tfaEmailMessage); + Assert.AreEqual(expectedMessageId, tfaEmailMessage.MessageId); + Assert.AreEqual(expectedApplicationId, tfaEmailMessage.ApplicationId); + Assert.AreEqual(expectedPinLength, tfaEmailMessage.PinLength); + Assert.AreEqual(expectedPinType, tfaEmailMessage.PinType); + Assert.AreEqual(expectedFrom, tfaEmailMessage.From); + Assert.AreEqual(expectedEmailTemplateId, tfaEmailMessage.EmailTemplateId); } - [TestMethod] - public void ShouldUpdateTfaEmailMessageTemplateTest() - { - TfaPinType expectedPinType = TfaPinType.Numeric; - int expectedPinLength = 4; - string expectedFrom = "company@example.com"; - int expectedEmailTemplateId = 1234; - string expectedMessageId = "9C815F8AF3328"; - string expectedApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; - - string givenRequest = $@" + AssertResponse(tfaApi.CreateTfaEmailMessageTemplate(expectedApplicationId, tfaCreateEmailMessageRequest), + AssertTfaCreateEmailMessageResponse); + AssertResponse( + tfaApi.CreateTfaEmailMessageTemplateAsync(expectedApplicationId, tfaCreateEmailMessageRequest).Result, + AssertTfaCreateEmailMessageResponse); + + AssertResponseWithHttpInfo( + tfaApi.CreateTfaEmailMessageTemplateWithHttpInfo(expectedApplicationId, tfaCreateEmailMessageRequest), + AssertTfaCreateEmailMessageResponse); + AssertResponseWithHttpInfo( + tfaApi.CreateTfaEmailMessageTemplateWithHttpInfoAsync(expectedApplicationId, tfaCreateEmailMessageRequest) + .Result, AssertTfaCreateEmailMessageResponse); + } + + [TestMethod] + public void ShouldUpdateTfaEmailMessageTemplateTest() + { + var expectedPinType = TfaPinType.Numeric; + var expectedPinLength = 4; + var expectedFrom = "company@example.com"; + var expectedEmailTemplateId = 1234; + var expectedMessageId = "9C815F8AF3328"; + var expectedApplicationId = "HJ675435E3A6EA43432G5F37A635KJ8B"; + + var givenRequest = $@" {{ ""pinType"": ""{expectedPinType}"", ""pinLength"": {expectedPinLength}, @@ -691,7 +745,7 @@ public void ShouldUpdateTfaEmailMessageTemplateTest() ""emailTemplateId"": {expectedEmailTemplateId} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""messageId"": ""{expectedMessageId}"", ""applicationId"": ""{expectedApplicationId}"", @@ -701,49 +755,59 @@ public void ShouldUpdateTfaEmailMessageTemplateTest() ""emailTemplateId"": {expectedEmailTemplateId} }}"; - SetUpPutRequest(TFA_EMAIL_TEMPLATE.Replace("{appId}", expectedApplicationId).Replace("{msgId}", expectedMessageId), givenRequest, expectedResponse, 200); + SetUpPutRequest( + TFA_EMAIL_TEMPLATE.Replace("{appId}", expectedApplicationId).Replace("{msgId}", expectedMessageId), + givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var tfaUpdateEmailMessageRequest = new TfaUpdateEmailMessageRequest( - pinType: expectedPinType, - pinLength: expectedPinLength, - from: expectedFrom, - emailTemplateId: expectedEmailTemplateId - ); + var tfaUpdateEmailMessageRequest = new TfaUpdateEmailMessageRequest( + pinType: expectedPinType, + pinLength: expectedPinLength, + from: expectedFrom, + emailTemplateId: expectedEmailTemplateId + ); - void AssertTfaUpdateEmailMessageResponse(TfaEmailMessage tfaEmailMessage) - { - Assert.IsNotNull(tfaEmailMessage); - Assert.AreEqual(expectedMessageId, tfaEmailMessage.MessageId); - Assert.AreEqual(expectedApplicationId, tfaEmailMessage.ApplicationId); - Assert.AreEqual(expectedPinLength, tfaEmailMessage.PinLength); - Assert.AreEqual(expectedPinType, tfaEmailMessage.PinType); - Assert.AreEqual(expectedFrom, tfaEmailMessage.From); - Assert.AreEqual(expectedEmailTemplateId, tfaEmailMessage.EmailTemplateId); - } - - AssertResponse(tfaApi.UpdateTfaEmailMessageTemplate(expectedApplicationId, expectedMessageId, tfaUpdateEmailMessageRequest), AssertTfaUpdateEmailMessageResponse); - AssertResponse(tfaApi.UpdateTfaEmailMessageTemplateAsync(expectedApplicationId, expectedMessageId, tfaUpdateEmailMessageRequest).Result, AssertTfaUpdateEmailMessageResponse); - - AssertResponseWithHttpInfo(tfaApi.UpdateTfaEmailMessageTemplateWithHttpInfo(expectedApplicationId, expectedMessageId, tfaUpdateEmailMessageRequest), AssertTfaUpdateEmailMessageResponse); - AssertResponseWithHttpInfo(tfaApi.UpdateTfaEmailMessageTemplateWithHttpInfoAsync(expectedApplicationId, expectedMessageId, tfaUpdateEmailMessageRequest).Result, AssertTfaUpdateEmailMessageResponse); + void AssertTfaUpdateEmailMessageResponse(TfaEmailMessage tfaEmailMessage) + { + Assert.IsNotNull(tfaEmailMessage); + Assert.AreEqual(expectedMessageId, tfaEmailMessage.MessageId); + Assert.AreEqual(expectedApplicationId, tfaEmailMessage.ApplicationId); + Assert.AreEqual(expectedPinLength, tfaEmailMessage.PinLength); + Assert.AreEqual(expectedPinType, tfaEmailMessage.PinType); + Assert.AreEqual(expectedFrom, tfaEmailMessage.From); + Assert.AreEqual(expectedEmailTemplateId, tfaEmailMessage.EmailTemplateId); } - [TestMethod] - public void ShouldSendTfaPinCodeViaSmsTest() - { - string givenApplicationId = "1234567"; - string givenMessageId = "7654321"; - string givenFrom = "Sender 1"; - string givenFirstName = "John"; + AssertResponse( + tfaApi.UpdateTfaEmailMessageTemplate(expectedApplicationId, expectedMessageId, + tfaUpdateEmailMessageRequest), AssertTfaUpdateEmailMessageResponse); + AssertResponse( + tfaApi.UpdateTfaEmailMessageTemplateAsync(expectedApplicationId, expectedMessageId, + tfaUpdateEmailMessageRequest).Result, AssertTfaUpdateEmailMessageResponse); + + AssertResponseWithHttpInfo( + tfaApi.UpdateTfaEmailMessageTemplateWithHttpInfo(expectedApplicationId, expectedMessageId, + tfaUpdateEmailMessageRequest), AssertTfaUpdateEmailMessageResponse); + AssertResponseWithHttpInfo( + tfaApi.UpdateTfaEmailMessageTemplateWithHttpInfoAsync(expectedApplicationId, expectedMessageId, + tfaUpdateEmailMessageRequest).Result, AssertTfaUpdateEmailMessageResponse); + } + + [TestMethod] + public void ShouldSendTfaPinCodeViaSmsTest() + { + var givenApplicationId = "1234567"; + var givenMessageId = "7654321"; + var givenFrom = "Sender 1"; + var givenFirstName = "John"; - string expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; - string expectedTo = "41793026727"; - string expectedNcStatus = "NC_DESTINATION_REACHABLE"; - string expectedSmsStatus = "MESSAGE_SENT"; + var expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; + var expectedTo = "41793026727"; + var expectedNcStatus = "NC_DESTINATION_REACHABLE"; + var expectedSmsStatus = "MESSAGE_SENT"; - string givenRequest = $@" + var givenRequest = $@" {{ ""applicationId"": ""{givenApplicationId}"", ""messageId"": ""{givenMessageId}"", @@ -754,7 +818,7 @@ public void ShouldSendTfaPinCodeViaSmsTest() }} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""pinId"": ""{expectedPinId}"", ""to"": ""{expectedTo}"", @@ -762,53 +826,57 @@ public void ShouldSendTfaPinCodeViaSmsTest() ""smsStatus"": ""{expectedSmsStatus}"" }}"; - SetUpPostRequest(TFA_SEND_PIN, givenRequest, expectedResponse, 200); + SetUpPostRequest(TFA_SEND_PIN, givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var givenPlaceholders = new Dictionary { { "firstName", givenFirstName } }; - var tfaStartAuthenticationRequest = new TfaStartAuthenticationRequest( - applicationId: givenApplicationId, - from: givenFrom, - messageId: givenMessageId, - placeholders: givenPlaceholders, - to: expectedTo - ); + var givenPlaceholders = new Dictionary { { "firstName", givenFirstName } }; + var tfaStartAuthenticationRequest = new TfaStartAuthenticationRequest( + givenApplicationId, + givenFrom, + givenMessageId, + givenPlaceholders, + expectedTo + ); - void AssertTfaStartAuthenticationResponse(TfaStartAuthenticationResponse tfaStartAuthenticationResponse) - { - Assert.IsNotNull(tfaStartAuthenticationResponse); - Assert.AreEqual(expectedPinId, tfaStartAuthenticationResponse.PinId); - Assert.AreEqual(expectedTo, tfaStartAuthenticationResponse.To); - Assert.AreEqual(expectedNcStatus, tfaStartAuthenticationResponse.NcStatus); - Assert.AreEqual(expectedSmsStatus, tfaStartAuthenticationResponse.SmsStatus); - } - - AssertResponse(tfaApi.SendTfaPinCodeOverSms(tfaStartAuthenticationRequest: tfaStartAuthenticationRequest), AssertTfaStartAuthenticationResponse); - AssertResponse(tfaApi.SendTfaPinCodeOverSmsAsync(tfaStartAuthenticationRequest: tfaStartAuthenticationRequest).Result, AssertTfaStartAuthenticationResponse); - - AssertResponseWithHttpInfo(tfaApi.SendTfaPinCodeOverSmsWithHttpInfo(tfaStartAuthenticationRequest: tfaStartAuthenticationRequest), AssertTfaStartAuthenticationResponse); - AssertResponseWithHttpInfo(tfaApi.SendTfaPinCodeOverSmsWithHttpInfoAsync(tfaStartAuthenticationRequest: tfaStartAuthenticationRequest).Result, AssertTfaStartAuthenticationResponse); + void AssertTfaStartAuthenticationResponse(TfaStartAuthenticationResponse tfaStartAuthenticationResponse) + { + Assert.IsNotNull(tfaStartAuthenticationResponse); + Assert.AreEqual(expectedPinId, tfaStartAuthenticationResponse.PinId); + Assert.AreEqual(expectedTo, tfaStartAuthenticationResponse.To); + Assert.AreEqual(expectedNcStatus, tfaStartAuthenticationResponse.NcStatus); + Assert.AreEqual(expectedSmsStatus, tfaStartAuthenticationResponse.SmsStatus); } - [TestMethod] - public void ShouldResendTfaPinCodeViaSmsTest() - { - string givenFirstName = "John"; + AssertResponse(tfaApi.SendTfaPinCodeOverSms(tfaStartAuthenticationRequest), + AssertTfaStartAuthenticationResponse); + AssertResponse(tfaApi.SendTfaPinCodeOverSmsAsync(tfaStartAuthenticationRequest).Result, + AssertTfaStartAuthenticationResponse); - string expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; - string expectedTo = "41793026727"; - string expectedNcStatus = "NC_DESTINATION_REACHABLE"; - string expectedSmsStatus = "MESSAGE_SENT"; + AssertResponseWithHttpInfo(tfaApi.SendTfaPinCodeOverSmsWithHttpInfo(tfaStartAuthenticationRequest), + AssertTfaStartAuthenticationResponse); + AssertResponseWithHttpInfo(tfaApi.SendTfaPinCodeOverSmsWithHttpInfoAsync(tfaStartAuthenticationRequest).Result, + AssertTfaStartAuthenticationResponse); + } - string givenRequest = $@" + [TestMethod] + public void ShouldResendTfaPinCodeViaSmsTest() + { + var givenFirstName = "John"; + + var expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; + var expectedTo = "41793026727"; + var expectedNcStatus = "NC_DESTINATION_REACHABLE"; + var expectedSmsStatus = "MESSAGE_SENT"; + + var givenRequest = $@" {{ ""placeholders"": {{ ""firstName"": ""{givenFirstName}"" }} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""pinId"": ""{expectedPinId}"", ""to"": ""{expectedTo}"", @@ -816,44 +884,49 @@ public void ShouldResendTfaPinCodeViaSmsTest() ""smsStatus"": ""{expectedSmsStatus}"" }}"; - SetUpPostRequest(TFA_RESEND_PIN.Replace("{pinId}", expectedPinId), givenRequest, expectedResponse, 200); + SetUpPostRequest(TFA_RESEND_PIN.Replace("{pinId}", expectedPinId), givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var tfaResendPinRequest = new TfaResendPinRequest() - { - Placeholders = new Dictionary { { "firstName", givenFirstName } } - }; + var tfaResendPinRequest = new TfaResendPinRequest + { + Placeholders = new Dictionary { { "firstName", givenFirstName } } + }; - void AssertTfaStartAuthenticationResponse(TfaStartAuthenticationResponse tfaStartAuthenticationResponse) - { - Assert.IsNotNull(tfaStartAuthenticationResponse); - Assert.AreEqual(expectedPinId, tfaStartAuthenticationResponse.PinId); - Assert.AreEqual(expectedTo, tfaStartAuthenticationResponse.To); - Assert.AreEqual(expectedNcStatus, tfaStartAuthenticationResponse.NcStatus); - Assert.AreEqual(expectedSmsStatus, tfaStartAuthenticationResponse.SmsStatus); - } - - AssertResponse(tfaApi.ResendTfaPinCodeOverSms(expectedPinId, tfaResendPinRequest), AssertTfaStartAuthenticationResponse); - AssertResponse(tfaApi.ResendTfaPinCodeOverSmsAsync(expectedPinId, tfaResendPinRequest).Result, AssertTfaStartAuthenticationResponse); - - AssertResponseWithHttpInfo(tfaApi.ResendTfaPinCodeOverSmsWithHttpInfo(expectedPinId, tfaResendPinRequest), AssertTfaStartAuthenticationResponse); - AssertResponseWithHttpInfo(tfaApi.ResendTfaPinCodeOverSmsWithHttpInfoAsync(expectedPinId, tfaResendPinRequest).Result, AssertTfaStartAuthenticationResponse); + void AssertTfaStartAuthenticationResponse(TfaStartAuthenticationResponse tfaStartAuthenticationResponse) + { + Assert.IsNotNull(tfaStartAuthenticationResponse); + Assert.AreEqual(expectedPinId, tfaStartAuthenticationResponse.PinId); + Assert.AreEqual(expectedTo, tfaStartAuthenticationResponse.To); + Assert.AreEqual(expectedNcStatus, tfaStartAuthenticationResponse.NcStatus); + Assert.AreEqual(expectedSmsStatus, tfaStartAuthenticationResponse.SmsStatus); } - [TestMethod] - public void ShouldSendTfaPinCodeViaVoiceTest() - { - string givenApplicationId = "1234567"; - string givenMessageId = "7654321"; - string givenFrom = "Sender 1"; - string givenFirstName = "John"; + AssertResponse(tfaApi.ResendTfaPinCodeOverSms(expectedPinId, tfaResendPinRequest), + AssertTfaStartAuthenticationResponse); + AssertResponse(tfaApi.ResendTfaPinCodeOverSmsAsync(expectedPinId, tfaResendPinRequest).Result, + AssertTfaStartAuthenticationResponse); + + AssertResponseWithHttpInfo(tfaApi.ResendTfaPinCodeOverSmsWithHttpInfo(expectedPinId, tfaResendPinRequest), + AssertTfaStartAuthenticationResponse); + AssertResponseWithHttpInfo( + tfaApi.ResendTfaPinCodeOverSmsWithHttpInfoAsync(expectedPinId, tfaResendPinRequest).Result, + AssertTfaStartAuthenticationResponse); + } + + [TestMethod] + public void ShouldSendTfaPinCodeViaVoiceTest() + { + var givenApplicationId = "1234567"; + var givenMessageId = "7654321"; + var givenFrom = "Sender 1"; + var givenFirstName = "John"; - string expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; - string expectedTo = "41793026727"; - string expectedCallStatus = "PENDING_ACCEPTED"; + var expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; + var expectedTo = "41793026727"; + var expectedCallStatus = "PENDING_ACCEPTED"; - string givenRequest = $@" + var givenRequest = $@" {{ ""applicationId"": ""{givenApplicationId}"", ""messageId"": ""{givenMessageId}"", @@ -864,102 +937,113 @@ public void ShouldSendTfaPinCodeViaVoiceTest() }} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""pinId"": ""{expectedPinId}"", ""to"": ""{expectedTo}"", ""callStatus"": ""{expectedCallStatus}"" }}"; - SetUpPostRequest(TFA_SEND_PIN_VOICE, givenRequest, expectedResponse, 200); + SetUpPostRequest(TFA_SEND_PIN_VOICE, givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var givenPlaceholders = new Dictionary { { "firstName", givenFirstName } }; - var tfaStartAuthenticationRequest = new TfaStartAuthenticationRequest( - applicationId: givenApplicationId, - from: givenFrom, - messageId: givenMessageId, - placeholders: givenPlaceholders, - to: expectedTo - ); + var givenPlaceholders = new Dictionary { { "firstName", givenFirstName } }; + var tfaStartAuthenticationRequest = new TfaStartAuthenticationRequest( + givenApplicationId, + givenFrom, + givenMessageId, + givenPlaceholders, + expectedTo + ); - void AssertTfaStartAuthenticationResponse(TfaStartAuthenticationResponse tfaStartAuthenticationResponse) - { - Assert.IsNotNull(tfaStartAuthenticationResponse); - Assert.AreEqual(expectedPinId, tfaStartAuthenticationResponse.PinId); - Assert.AreEqual(expectedTo, tfaStartAuthenticationResponse.To); - Assert.AreEqual(expectedCallStatus, tfaStartAuthenticationResponse.CallStatus); - } + void AssertTfaStartAuthenticationResponse(TfaStartAuthenticationResponse tfaStartAuthenticationResponse) + { + Assert.IsNotNull(tfaStartAuthenticationResponse); + Assert.AreEqual(expectedPinId, tfaStartAuthenticationResponse.PinId); + Assert.AreEqual(expectedTo, tfaStartAuthenticationResponse.To); + Assert.AreEqual(expectedCallStatus, tfaStartAuthenticationResponse.CallStatus); + } - AssertResponse(tfaApi.SendTfaPinCodeOverVoice(tfaStartAuthenticationRequest), AssertTfaStartAuthenticationResponse); - AssertResponse(tfaApi.SendTfaPinCodeOverVoiceAsync(tfaStartAuthenticationRequest).Result, AssertTfaStartAuthenticationResponse); + AssertResponse(tfaApi.SendTfaPinCodeOverVoice(tfaStartAuthenticationRequest), + AssertTfaStartAuthenticationResponse); + AssertResponse(tfaApi.SendTfaPinCodeOverVoiceAsync(tfaStartAuthenticationRequest).Result, + AssertTfaStartAuthenticationResponse); - AssertResponseWithHttpInfo(tfaApi.SendTfaPinCodeOverVoiceWithHttpInfo(tfaStartAuthenticationRequest), AssertTfaStartAuthenticationResponse); - AssertResponseWithHttpInfo(tfaApi.SendTfaPinCodeOverVoiceWithHttpInfoAsync(tfaStartAuthenticationRequest).Result, AssertTfaStartAuthenticationResponse); - } + AssertResponseWithHttpInfo(tfaApi.SendTfaPinCodeOverVoiceWithHttpInfo(tfaStartAuthenticationRequest), + AssertTfaStartAuthenticationResponse); + AssertResponseWithHttpInfo( + tfaApi.SendTfaPinCodeOverVoiceWithHttpInfoAsync(tfaStartAuthenticationRequest).Result, + AssertTfaStartAuthenticationResponse); + } - [TestMethod] - public void ShouldResendTfaPinCodeViaVoiceTest() - { - string givenFirstName = "John"; + [TestMethod] + public void ShouldResendTfaPinCodeViaVoiceTest() + { + var givenFirstName = "John"; - string expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; - string expectedTo = "41793026727"; - string expectedCallStatus = "MESSAGE_SENT"; + var expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; + var expectedTo = "41793026727"; + var expectedCallStatus = "MESSAGE_SENT"; - string givenRequest = $@" + var givenRequest = $@" {{ ""placeholders"": {{ ""firstName"": ""{givenFirstName}"" }} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""pinId"": ""{expectedPinId}"", ""to"": {expectedTo}, ""callStatus"": ""{expectedCallStatus}"" }}"; - SetUpPostRequest(TFA_RESEND_PIN_VOICE.Replace("{pinId}", expectedPinId), givenRequest, expectedResponse, 200); + SetUpPostRequest(TFA_RESEND_PIN_VOICE.Replace("{pinId}", expectedPinId), givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var tfaResendPinRequest = new TfaResendPinRequest() - { - Placeholders = new Dictionary { { "firstName", givenFirstName } } - }; - - void AssertTfaStartAuthenticationResponse(TfaStartAuthenticationResponse tfaStartAuthenticationResponse) - { - Assert.IsNotNull(tfaStartAuthenticationResponse); - Assert.AreEqual(expectedPinId, tfaStartAuthenticationResponse.PinId); - Assert.AreEqual(expectedTo, tfaStartAuthenticationResponse.To); - Assert.AreEqual(expectedCallStatus, tfaStartAuthenticationResponse.CallStatus); - } - - AssertResponse(tfaApi.ResendTfaPinCodeOverVoice(expectedPinId, tfaResendPinRequest), AssertTfaStartAuthenticationResponse); ; - AssertResponse(tfaApi.ResendTfaPinCodeOverVoiceAsync(expectedPinId, tfaResendPinRequest).Result, AssertTfaStartAuthenticationResponse); + var tfaResendPinRequest = new TfaResendPinRequest + { + Placeholders = new Dictionary { { "firstName", givenFirstName } } + }; - AssertResponseWithHttpInfo(tfaApi.ResendTfaPinCodeOverVoiceWithHttpInfo(expectedPinId, tfaResendPinRequest), AssertTfaStartAuthenticationResponse); - AssertResponseWithHttpInfo(tfaApi.ResendTfaPinCodeOverVoiceWithHttpInfoAsync(expectedPinId, tfaResendPinRequest).Result, AssertTfaStartAuthenticationResponse); + void AssertTfaStartAuthenticationResponse(TfaStartAuthenticationResponse tfaStartAuthenticationResponse) + { + Assert.IsNotNull(tfaStartAuthenticationResponse); + Assert.AreEqual(expectedPinId, tfaStartAuthenticationResponse.PinId); + Assert.AreEqual(expectedTo, tfaStartAuthenticationResponse.To); + Assert.AreEqual(expectedCallStatus, tfaStartAuthenticationResponse.CallStatus); } - [TestMethod] - public void ShouldSendTfaPinCodeViaEmailTest() - { - string givenApplicationId = "1234567"; - string givenMessageId = "7654321"; - string givenFirstName = "John"; + AssertResponse(tfaApi.ResendTfaPinCodeOverVoice(expectedPinId, tfaResendPinRequest), + AssertTfaStartAuthenticationResponse); + ; + AssertResponse(tfaApi.ResendTfaPinCodeOverVoiceAsync(expectedPinId, tfaResendPinRequest).Result, + AssertTfaStartAuthenticationResponse); + + AssertResponseWithHttpInfo(tfaApi.ResendTfaPinCodeOverVoiceWithHttpInfo(expectedPinId, tfaResendPinRequest), + AssertTfaStartAuthenticationResponse); + AssertResponseWithHttpInfo( + tfaApi.ResendTfaPinCodeOverVoiceWithHttpInfoAsync(expectedPinId, tfaResendPinRequest).Result, + AssertTfaStartAuthenticationResponse); + } + + [TestMethod] + public void ShouldSendTfaPinCodeViaEmailTest() + { + var givenApplicationId = "1234567"; + var givenMessageId = "7654321"; + var givenFirstName = "John"; - string expectedTo = "john.smith@example.com"; - string expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; - string expectedEmailStatusName = "PENDING_ACCEPTED"; - string expectedEmailStatusDescription = "Message accepted, pending for delivery."; + var expectedTo = "john.smith@example.com"; + var expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; + var expectedEmailStatusName = "PENDING_ACCEPTED"; + var expectedEmailStatusDescription = "Message accepted, pending for delivery."; - string givenRequest = $@" + var givenRequest = $@" {{ ""applicationId"": ""{givenApplicationId}"", ""messageId"": ""{givenMessageId}"", @@ -969,7 +1053,7 @@ public void ShouldSendTfaPinCodeViaEmailTest() }} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""pinId"": ""{expectedPinId}"", ""to"": ""{expectedTo}"", @@ -979,53 +1063,60 @@ public void ShouldSendTfaPinCodeViaEmailTest() }} }}"; - SetUpPostRequest(TFA_SEND_PIN_EMAIL, givenRequest, expectedResponse, 200); + SetUpPostRequest(TFA_SEND_PIN_EMAIL, givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var givenPlaceholders = new Dictionary { { "firstName", givenFirstName } }; + var givenPlaceholders = new Dictionary { { "firstName", givenFirstName } }; - var tfaStartEmailAuthenticationRequest = new TfaStartEmailAuthenticationRequest( - applicationId: givenApplicationId, - messageId: givenMessageId, - to: expectedTo, - placeholders: givenPlaceholders - ); + var tfaStartEmailAuthenticationRequest = new TfaStartEmailAuthenticationRequest( + givenApplicationId, + messageId: givenMessageId, + to: expectedTo, + placeholders: givenPlaceholders + ); - void AssertTfaStartEmailAuthenticationResponse(TfaStartEmailAuthenticationResponse tfaStartEmailAuthenticationResponse) - { - Assert.IsNotNull(tfaStartEmailAuthenticationRequest); - Assert.AreEqual(expectedPinId, tfaStartEmailAuthenticationResponse.PinId); - Assert.AreEqual(expectedTo, tfaStartEmailAuthenticationResponse.To); - Assert.AreEqual(expectedEmailStatusName, tfaStartEmailAuthenticationResponse.EmailStatus.Name); - Assert.AreEqual(expectedEmailStatusDescription, tfaStartEmailAuthenticationResponse.EmailStatus.Description); - } - - AssertResponse(tfaApi.Send2faPinCodeOverEmail(tfaStartEmailAuthenticationRequest), AssertTfaStartEmailAuthenticationResponse); - AssertResponse(tfaApi.Send2faPinCodeOverEmailAsync(tfaStartEmailAuthenticationRequest).Result, AssertTfaStartEmailAuthenticationResponse); - - AssertResponseWithHttpInfo(tfaApi.Send2faPinCodeOverEmailWithHttpInfo(tfaStartEmailAuthenticationRequest), AssertTfaStartEmailAuthenticationResponse); - AssertResponseWithHttpInfo(tfaApi.Send2faPinCodeOverEmailWithHttpInfoAsync(tfaStartEmailAuthenticationRequest).Result, AssertTfaStartEmailAuthenticationResponse); + void AssertTfaStartEmailAuthenticationResponse( + TfaStartEmailAuthenticationResponse tfaStartEmailAuthenticationResponse) + { + Assert.IsNotNull(tfaStartEmailAuthenticationRequest); + Assert.AreEqual(expectedPinId, tfaStartEmailAuthenticationResponse.PinId); + Assert.AreEqual(expectedTo, tfaStartEmailAuthenticationResponse.To); + Assert.AreEqual(expectedEmailStatusName, tfaStartEmailAuthenticationResponse.EmailStatus.Name); + Assert.AreEqual(expectedEmailStatusDescription, + tfaStartEmailAuthenticationResponse.EmailStatus.Description); } - [TestMethod] - public void ShouldResendTfaPinCodeViaEmailTest() - { - string givenFirstName = "John"; + AssertResponse(tfaApi.Send2faPinCodeOverEmail(tfaStartEmailAuthenticationRequest), + AssertTfaStartEmailAuthenticationResponse); + AssertResponse(tfaApi.Send2faPinCodeOverEmailAsync(tfaStartEmailAuthenticationRequest).Result, + AssertTfaStartEmailAuthenticationResponse); - string expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; - string expectedTo = "john.smith@example.com"; - string expectedEmailStatusName = "PENDING_ACCEPTED"; - string expectedEmailStatusDescription = "Message accepted, pending for delivery."; + AssertResponseWithHttpInfo(tfaApi.Send2faPinCodeOverEmailWithHttpInfo(tfaStartEmailAuthenticationRequest), + AssertTfaStartEmailAuthenticationResponse); + AssertResponseWithHttpInfo( + tfaApi.Send2faPinCodeOverEmailWithHttpInfoAsync(tfaStartEmailAuthenticationRequest).Result, + AssertTfaStartEmailAuthenticationResponse); + } - string givenRequest = $@" + [TestMethod] + public void ShouldResendTfaPinCodeViaEmailTest() + { + var givenFirstName = "John"; + + var expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B67"; + var expectedTo = "john.smith@example.com"; + var expectedEmailStatusName = "PENDING_ACCEPTED"; + var expectedEmailStatusDescription = "Message accepted, pending for delivery."; + + var givenRequest = $@" {{ ""placeholders"": {{ ""firstName"": ""{givenFirstName}"" }} }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""pinId"": ""{expectedPinId}"", ""to"": ""{expectedTo}"", @@ -1035,47 +1126,55 @@ public void ShouldResendTfaPinCodeViaEmailTest() }} }}"; - SetUpPostRequest(TFA_RESEND_PIN_EMAIL.Replace("{pinId}", expectedPinId), givenRequest, expectedResponse, 200); + SetUpPostRequest(TFA_RESEND_PIN_EMAIL.Replace("{pinId}", expectedPinId), givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var tfaResendPinRequest = new TfaResendPinRequest() - { - Placeholders = new Dictionary { { "firstName", givenFirstName } } - }; + var tfaResendPinRequest = new TfaResendPinRequest + { + Placeholders = new Dictionary { { "firstName", givenFirstName } } + }; - void AssertTfaStartAuthenticationResponse(TfaStartEmailAuthenticationResponse tfaStartEmailAuthenticationResponse) - { - Assert.IsNotNull(tfaStartEmailAuthenticationResponse); - Assert.AreEqual(expectedPinId, tfaStartEmailAuthenticationResponse.PinId); - Assert.AreEqual(expectedTo, tfaStartEmailAuthenticationResponse.To); - Assert.AreEqual(expectedEmailStatusName, tfaStartEmailAuthenticationResponse.EmailStatus.Name); - Assert.AreEqual(expectedEmailStatusDescription, tfaStartEmailAuthenticationResponse.EmailStatus.Description); - } - - AssertResponse(tfaApi.Resend2faPinCodeOverEmail(expectedPinId, tfaResendPinRequest), AssertTfaStartAuthenticationResponse); ; - AssertResponse(tfaApi.Resend2faPinCodeOverEmailAsync(expectedPinId, tfaResendPinRequest).Result, AssertTfaStartAuthenticationResponse); - - AssertResponseWithHttpInfo(tfaApi.Resend2faPinCodeOverEmailWithHttpInfo(expectedPinId, tfaResendPinRequest), AssertTfaStartAuthenticationResponse); - AssertResponseWithHttpInfo(tfaApi.Resend2faPinCodeOverEmailWithHttpInfoAsync(expectedPinId, tfaResendPinRequest).Result, AssertTfaStartAuthenticationResponse); + void AssertTfaStartAuthenticationResponse( + TfaStartEmailAuthenticationResponse tfaStartEmailAuthenticationResponse) + { + Assert.IsNotNull(tfaStartEmailAuthenticationResponse); + Assert.AreEqual(expectedPinId, tfaStartEmailAuthenticationResponse.PinId); + Assert.AreEqual(expectedTo, tfaStartEmailAuthenticationResponse.To); + Assert.AreEqual(expectedEmailStatusName, tfaStartEmailAuthenticationResponse.EmailStatus.Name); + Assert.AreEqual(expectedEmailStatusDescription, + tfaStartEmailAuthenticationResponse.EmailStatus.Description); } - [TestMethod] - public void ShouldVerifyTfaCallTest() - { - string givenPin = "1598"; + AssertResponse(tfaApi.Resend2faPinCodeOverEmail(expectedPinId, tfaResendPinRequest), + AssertTfaStartAuthenticationResponse); + ; + AssertResponse(tfaApi.Resend2faPinCodeOverEmailAsync(expectedPinId, tfaResendPinRequest).Result, + AssertTfaStartAuthenticationResponse); + + AssertResponseWithHttpInfo(tfaApi.Resend2faPinCodeOverEmailWithHttpInfo(expectedPinId, tfaResendPinRequest), + AssertTfaStartAuthenticationResponse); + AssertResponseWithHttpInfo( + tfaApi.Resend2faPinCodeOverEmailWithHttpInfoAsync(expectedPinId, tfaResendPinRequest).Result, + AssertTfaStartAuthenticationResponse); + } - string expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B68"; - string expectedMsisdn = "41793026726"; - string expectedVerified = "true"; - int expectedAttemptsRemaining = 0; + [TestMethod] + public void ShouldVerifyTfaCallTest() + { + var givenPin = "1598"; + + var expectedPinId = "9C817C6F8AF3D48F9FE553282AFA2B68"; + var expectedMsisdn = "41793026726"; + var expectedVerified = "true"; + var expectedAttemptsRemaining = 0; - string givenRequest = $@" + var givenRequest = $@" {{ ""pin"": ""{givenPin}"" }}"; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""pinId"": ""{expectedPinId}"", ""msisdn"": ""{expectedMsisdn}"", @@ -1083,42 +1182,47 @@ public void ShouldVerifyTfaCallTest() ""attemptsRemaining"": {expectedAttemptsRemaining} }}"; - SetUpPostRequest(TFA_VERIFY_PIN.Replace("{pinId}", expectedPinId), givenRequest, expectedResponse, 200); + SetUpPostRequest(TFA_VERIFY_PIN.Replace("{pinId}", expectedPinId), givenRequest, expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - var tfaVerifyPinRequest = new TfaVerifyPinRequest(givenPin); + var tfaVerifyPinRequest = new TfaVerifyPinRequest(givenPin); - void AssertTfaVerifyPinResponse(TfaVerifyPinResponse tfaVerifyPinResponse) - { - Assert.IsNotNull(tfaVerifyPinResponse); - Assert.AreEqual(expectedPinId, tfaVerifyPinResponse.PinId); - Assert.AreEqual(expectedMsisdn, tfaVerifyPinResponse.Msisdn); - Assert.AreEqual(bool.Parse(expectedVerified), tfaVerifyPinResponse.Verified); - Assert.AreEqual(expectedAttemptsRemaining, tfaVerifyPinResponse.AttemptsRemaining); - } - - AssertResponse(tfaApi.VerifyTfaPhoneNumber(expectedPinId, tfaVerifyPinRequest), AssertTfaVerifyPinResponse); ; - AssertResponse(tfaApi.VerifyTfaPhoneNumberAsync(expectedPinId, tfaVerifyPinRequest).Result, AssertTfaVerifyPinResponse); - - AssertResponseWithHttpInfo(tfaApi.VerifyTfaPhoneNumberWithHttpInfo(expectedPinId, tfaVerifyPinRequest), AssertTfaVerifyPinResponse); - AssertResponseWithHttpInfo(tfaApi.VerifyTfaPhoneNumberWithHttpInfoAsync(expectedPinId, tfaVerifyPinRequest).Result, AssertTfaVerifyPinResponse); + void AssertTfaVerifyPinResponse(TfaVerifyPinResponse tfaVerifyPinResponse) + { + Assert.IsNotNull(tfaVerifyPinResponse); + Assert.AreEqual(expectedPinId, tfaVerifyPinResponse.PinId); + Assert.AreEqual(expectedMsisdn, tfaVerifyPinResponse.Msisdn); + Assert.AreEqual(bool.Parse(expectedVerified), tfaVerifyPinResponse.Verified); + Assert.AreEqual(expectedAttemptsRemaining, tfaVerifyPinResponse.AttemptsRemaining); } - [TestMethod] - public void ShouldGetTfaVerificationStatusTest() - { - string givenApplicationId = "16A8B5FE2BCD6CA716A2D780CB3F3390"; + AssertResponse(tfaApi.VerifyTfaPhoneNumber(expectedPinId, tfaVerifyPinRequest), AssertTfaVerifyPinResponse); + ; + AssertResponse(tfaApi.VerifyTfaPhoneNumberAsync(expectedPinId, tfaVerifyPinRequest).Result, + AssertTfaVerifyPinResponse); + + AssertResponseWithHttpInfo(tfaApi.VerifyTfaPhoneNumberWithHttpInfo(expectedPinId, tfaVerifyPinRequest), + AssertTfaVerifyPinResponse); + AssertResponseWithHttpInfo( + tfaApi.VerifyTfaPhoneNumberWithHttpInfoAsync(expectedPinId, tfaVerifyPinRequest).Result, + AssertTfaVerifyPinResponse); + } + + [TestMethod] + public void ShouldGetTfaVerificationStatusTest() + { + var givenApplicationId = "16A8B5FE2BCD6CA716A2D780CB3F3390"; - string expectedMsisdn = "41793026726"; - string expectedVerified1 = "true"; - long expectedVerifiedAt1 = 1418364366L; - long expectedSentAt1 = 1418364246L; - string expectedVerified2 = "false"; - long expectedVerifiedAt2 = 1418364226L; - long expectedSentAt2 = 1418333246L; + var expectedMsisdn = "41793026726"; + var expectedVerified1 = "true"; + var expectedVerifiedAt1 = 1418364366L; + var expectedSentAt1 = 1418364246L; + var expectedVerified2 = "false"; + var expectedVerifiedAt2 = 1418364226L; + var expectedSentAt2 = 1418333246L; - string expectedResponse = $@" + var expectedResponse = $@" {{ ""verifications"": [ {{ @@ -1136,34 +1240,39 @@ public void ShouldGetTfaVerificationStatusTest() ] }}"; - SetUpGetRequest(TFA_VERIFICATION_STATUS.Replace("{appId}", givenApplicationId), expectedResponse, 200); + SetUpGetRequest(TFA_VERIFICATION_STATUS.Replace("{appId}", givenApplicationId), expectedResponse, 200); - var tfaApi = new TfaApi(configuration); + var tfaApi = new TfaApi(configuration); - void AssertTfaVerificationResponse(TfaVerificationResponse tfaVerificationResponse) - { - Assert.IsNotNull(tfaVerificationResponse); - Assert.IsNotNull(tfaVerificationResponse.Verifications); - Assert.IsTrue(tfaVerificationResponse.Verifications.Count.Equals(2)); - - var tfaVerification1 = tfaVerificationResponse.Verifications[0]; - Assert.AreEqual(expectedMsisdn, tfaVerification1.Msisdn); - Assert.AreEqual(bool.Parse(expectedVerified1), tfaVerification1.Verified); - Assert.AreEqual(expectedVerifiedAt1, tfaVerification1.VerifiedAt); - Assert.AreEqual(expectedSentAt1, tfaVerification1.SentAt); - - var tfaVerification2 = tfaVerificationResponse.Verifications[1]; - Assert.AreEqual(expectedMsisdn, tfaVerification2.Msisdn); - Assert.AreEqual(bool.Parse(expectedVerified2), tfaVerification2.Verified); - Assert.AreEqual(expectedVerifiedAt2, tfaVerification2.VerifiedAt); - Assert.AreEqual(expectedSentAt2, tfaVerification2.SentAt); - } - - AssertResponse(tfaApi.GetTfaVerificationStatus(expectedMsisdn, givenApplicationId), AssertTfaVerificationResponse); ; - AssertResponse(tfaApi.GetTfaVerificationStatusAsync(expectedMsisdn, givenApplicationId).Result, AssertTfaVerificationResponse); - - AssertResponseWithHttpInfo(tfaApi.GetTfaVerificationStatusWithHttpInfo(expectedMsisdn, givenApplicationId), AssertTfaVerificationResponse); - AssertResponseWithHttpInfo(tfaApi.GetTfaVerificationStatusWithHttpInfoAsync(expectedMsisdn, givenApplicationId).Result, AssertTfaVerificationResponse); + void AssertTfaVerificationResponse(TfaVerificationResponse tfaVerificationResponse) + { + Assert.IsNotNull(tfaVerificationResponse); + Assert.IsNotNull(tfaVerificationResponse.Verifications); + Assert.IsTrue(tfaVerificationResponse.Verifications.Count.Equals(2)); + + var tfaVerification1 = tfaVerificationResponse.Verifications[0]; + Assert.AreEqual(expectedMsisdn, tfaVerification1.Msisdn); + Assert.AreEqual(bool.Parse(expectedVerified1), tfaVerification1.Verified); + Assert.AreEqual(expectedVerifiedAt1, tfaVerification1.VerifiedAt); + Assert.AreEqual(expectedSentAt1, tfaVerification1.SentAt); + + var tfaVerification2 = tfaVerificationResponse.Verifications[1]; + Assert.AreEqual(expectedMsisdn, tfaVerification2.Msisdn); + Assert.AreEqual(bool.Parse(expectedVerified2), tfaVerification2.Verified); + Assert.AreEqual(expectedVerifiedAt2, tfaVerification2.VerifiedAt); + Assert.AreEqual(expectedSentAt2, tfaVerification2.SentAt); } + + AssertResponse(tfaApi.GetTfaVerificationStatus(expectedMsisdn, givenApplicationId), + AssertTfaVerificationResponse); + ; + AssertResponse(tfaApi.GetTfaVerificationStatusAsync(expectedMsisdn, givenApplicationId).Result, + AssertTfaVerificationResponse); + + AssertResponseWithHttpInfo(tfaApi.GetTfaVerificationStatusWithHttpInfo(expectedMsisdn, givenApplicationId), + AssertTfaVerificationResponse); + AssertResponseWithHttpInfo( + tfaApi.GetTfaVerificationStatusWithHttpInfoAsync(expectedMsisdn, givenApplicationId).Result, + AssertTfaVerificationResponse); } } \ No newline at end of file diff --git a/ApiClient.Tests/ApiExceptionTest.cs b/ApiClient.Tests/ApiExceptionTest.cs index adaf4a1..9af435c 100644 --- a/ApiClient.Tests/ApiExceptionTest.cs +++ b/ApiClient.Tests/ApiExceptionTest.cs @@ -2,49 +2,47 @@ using Infobip.Api.Client.Api; using Infobip.Api.Client.Model; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Linq; using ApiException = Infobip.Api.Client.ApiException; -namespace ApiClient.Tests +namespace ApiClient.Tests; + +[TestClass] +public class ApiExceptionTest : ApiTest { - [TestClass] - public class ApiExceptionTest : ApiTest - { - protected const string SMS_SEND_TEXT_ADVANCED_ENDPOINT = "/sms/2/text/advanced"; + protected const string SMS_SEND_TEXT_ADVANCED_ENDPOINT = "/sms/2/text/advanced"; - internal static readonly Tuple[] ErrorResponses = - { - Tuple.Create(400, "BAD_REQUEST", "Bad Request", "[messages[0].destinations : size must be between 1 and 2147483647]"), - Tuple.Create(401, "UNAUTHORIZED", "Unauthorized", "Invalid login details"), - Tuple.Create(403, "UNAUTHORIZED", "Forbidden", "Unauthorized access"), - Tuple.Create(404, "NOT_FOUND", "Not Found", "Requested URL not found: /sms/2/text/advanced"), - Tuple.Create(429, "TOO_MANY_REQUESTS", "Too Many Requests", "Too many requests"), - Tuple.Create(500, "GENERAL_ERROR", "Internal Server Error", "Something went wrong. Please contact support."), - Tuple.Create(503, "0", "Service Unavailable", "Error processing email validation request! Please try again"), - }; + internal static readonly Tuple[] ErrorResponses = + { + Tuple.Create(400, "BAD_REQUEST", "Bad Request", + "[messages[0].destinations : size must be between 1 and 2147483647]"), + Tuple.Create(401, "UNAUTHORIZED", "Unauthorized", "Invalid login details"), + Tuple.Create(403, "UNAUTHORIZED", "Forbidden", "Unauthorized access"), + Tuple.Create(404, "NOT_FOUND", "Not Found", "Requested URL not found: /sms/2/text/advanced"), + Tuple.Create(429, "TOO_MANY_REQUESTS", "Too Many Requests", "Too many requests"), + Tuple.Create(500, "GENERAL_ERROR", "Internal Server Error", "Something went wrong. Please contact support."), + Tuple.Create(503, "0", "Service Unavailable", "Error processing email validation request! Please try again") + }; - [DataTestMethod] - [DataRow(0)] - [DataRow(1)] - [DataRow(2)] - [DataRow(3)] - [DataRow(4)] - [DataRow(5)] - [DataRow(6)] - public void ErrorResponseTest(int errorResponseIndex) - { - int httpCode = ErrorResponses[errorResponseIndex].Item1; - string messageId = ErrorResponses[errorResponseIndex].Item2; - string errorPhrase = ErrorResponses[errorResponseIndex].Item3; - string errorText = ErrorResponses[errorResponseIndex].Item4; + [DataTestMethod] + [DataRow(0)] + [DataRow(1)] + [DataRow(2)] + [DataRow(3)] + [DataRow(4)] + [DataRow(5)] + [DataRow(6)] + public void ErrorResponseTest(int errorResponseIndex) + { + var httpCode = ErrorResponses[errorResponseIndex].Item1; + var messageId = ErrorResponses[errorResponseIndex].Item2; + var errorPhrase = ErrorResponses[errorResponseIndex].Item3; + var errorText = ErrorResponses[errorResponseIndex].Item4; - string to = "41793026727"; - string from = "InfoSMS"; - string message = "This is a sample message"; + var to = "41793026727"; + var from = "InfoSMS"; + var message = "This is a sample message"; - string responseJson = $@" + var responseJson = $@" {{ ""requestError"": {{ ""serviceException"": {{ @@ -54,7 +52,7 @@ public void ErrorResponseTest(int errorResponseIndex) }} }}"; - string expectedRequest = $@" + var expectedRequest = $@" {{ ""messages"": [ {{ @@ -72,40 +70,41 @@ public void ErrorResponseTest(int errorResponseIndex) ""includeSmsCountInResponse"":false }}"; - Dictionary responseHeaders = new Dictionary() - { - { "Server", "SMS,API" }, - { "X-Request-ID", "1608758729810312842" }, - { "Content-Type", "application/json; charset=utf-8" } - }; - - SetUpPostRequest(SMS_SEND_TEXT_ADVANCED_ENDPOINT, expectedRequest, responseJson, httpCode); + var responseHeaders = new Dictionary + { + { "Server", "SMS,API" }, + { "X-Request-ID", "1608758729810312842" }, + { "Content-Type", "application/json; charset=utf-8" } + }; - var smsApi = new SmsApi(this.configuration); + SetUpPostRequest(SMS_SEND_TEXT_ADVANCED_ENDPOINT, expectedRequest, responseJson, httpCode); - var request = new SmsAdvancedTextualRequest( - messages: new List { - new SmsTextualMessage( - from: from, text: message, destinations: new List{ new SmsDestination(to: to) } - ) - } - ); + var smsApi = new SmsApi(configuration); - try - { - var result = smsApi.SendSmsMessage(request); - } - catch (ApiException ex) + var request = new SmsAdvancedTextualRequest( + messages: new List { - Assert.AreEqual(httpCode, ex.ErrorCode); - Assert.IsNotNull(ex.ErrorContent); - Assert.AreEqual(responseJson, ex.ErrorContent); - Assert.IsInstanceOfType(ex, typeof(ApiException)); - Assert.IsTrue(ex.Message.Contains(errorPhrase)); - Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(messageId) == true); - Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(errorText) == true); - Assert.IsTrue(responseHeaders.All(h => ex.Headers.ContainsKey(h.Key) && ex.Headers[h.Key].First().Equals(h.Value))); + new( + from: from, text: message, destinations: new List { new(to: to) } + ) } + ); + + try + { + var result = smsApi.SendSmsMessage(request); + } + catch (ApiException ex) + { + Assert.AreEqual(httpCode, ex.ErrorCode); + Assert.IsNotNull(ex.ErrorContent); + Assert.AreEqual(responseJson, ex.ErrorContent); + Assert.IsInstanceOfType(ex, typeof(ApiException)); + Assert.IsTrue(ex.Message.Contains(errorPhrase)); + Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(messageId) == true); + Assert.IsTrue(ex.ErrorContent.ToString()?.Contains(errorText) == true); + Assert.IsTrue(responseHeaders.All(h => + ex.Headers.ContainsKey(h.Key) && ex.Headers[h.Key].First().Equals(h.Value))); } } -} +} \ No newline at end of file diff --git a/ApiClient.Tests/DateTimeSerializationTest.cs b/ApiClient.Tests/DateTimeSerializationTest.cs index df405f2..e509d56 100644 --- a/ApiClient.Tests/DateTimeSerializationTest.cs +++ b/ApiClient.Tests/DateTimeSerializationTest.cs @@ -1,78 +1,77 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; -namespace ApiClient.Tests +namespace ApiClient.Tests; + +[TestClass] +public class DateTimeSerializationTest { - [TestClass] - public class DateTimeSerializationTest - { - internal static readonly DateTimeOffset[] DateTimeValues = new[] { - new DateTimeOffset(2035, 8, 18, 12, 8, 42, 777, new TimeSpan(0, 0, 0)), - new DateTimeOffset(2035, 8, 18, 13, 8, 42, 777, new TimeSpan(1, 0, 0)), - new DateTimeOffset(2035, 8, 18, 11, 8, 42, 777, new TimeSpan(-1, 0, 0)), - new DateTimeOffset(2035, 8, 18, 17, 8, 42, 777, new TimeSpan(5, 0, 0)), - new DateTimeOffset(2035, 8, 18, 7, 8, 42, 777, new TimeSpan(-5, 0, 0)), - new DateTimeOffset(2035, 8, 18, 13, 38, 42, 777, new TimeSpan(1, 30, 0)), - new DateTimeOffset(2035, 8, 18, 10, 38, 42, 777, new TimeSpan(-1, -30, 0)), - new DateTimeOffset(2035, 8, 18, 17, 38, 42, 777, new TimeSpan(5, 30, 0)), - new DateTimeOffset(2035, 8, 18, 6, 38, 42, 777, new TimeSpan(-5, -30, 0)) - }; + private const string EXPECTED_DATETIME_FORMAT = "yyyy-MM-ddTHH:mm:ss.fffzzzz"; + private const string EXPECTED_DATE_FORMAT = "yyyy-MM-dd"; + private const string EXPECTED_DATE = "2035-08-18"; + private const long EXPECTED_TICKS = 642066048000000000; - const string EXPECTED_DATETIME_FORMAT = "yyyy-MM-ddTHH:mm:ss.fffzzzz"; - const string EXPECTED_DATE_FORMAT = "yyyy-MM-dd"; - const string EXPECTED_DATE = "2035-08-18"; - const long EXPECTED_TICKS = 642066048000000000; + internal static readonly DateTimeOffset[] DateTimeValues = + { + new DateTimeOffset(2035, 8, 18, 12, 8, 42, 777, new TimeSpan(0, 0, 0)), + new DateTimeOffset(2035, 8, 18, 13, 8, 42, 777, new TimeSpan(1, 0, 0)), + new DateTimeOffset(2035, 8, 18, 11, 8, 42, 777, new TimeSpan(-1, 0, 0)), + new DateTimeOffset(2035, 8, 18, 17, 8, 42, 777, new TimeSpan(5, 0, 0)), + new DateTimeOffset(2035, 8, 18, 7, 8, 42, 777, new TimeSpan(-5, 0, 0)), + new DateTimeOffset(2035, 8, 18, 13, 38, 42, 777, new TimeSpan(1, 30, 0)), + new DateTimeOffset(2035, 8, 18, 10, 38, 42, 777, new TimeSpan(-1, -30, 0)), + new DateTimeOffset(2035, 8, 18, 17, 38, 42, 777, new TimeSpan(5, 30, 0)), + new DateTimeOffset(2035, 8, 18, 6, 38, 42, 777, new TimeSpan(-5, -30, 0)) + }; - [DataRow("2035-08-18T12:08:42.777+0000", 0)] - [DataRow("2035-08-18T13:08:42.777+0100", 1)] - [DataRow("2035-08-18T11:08:42.777-0100", 2)] - [DataRow("2035-08-18T17:08:42.777+0500", 3)] - [DataRow("2035-08-18T07:08:42.777-0500", 4)] - [DataRow("2035-08-18T13:38:42.777+0130", 5)] - [DataRow("2035-08-18T10:38:42.777-0130", 6)] - [DataRow("2035-08-18T17:38:42.777+0530", 7)] - [DataRow("2035-08-18T06:38:42.777-0530", 8)] - [DataTestMethod] - public void DateTimeFormatDeserializationTest(string dateString, int dateValueIndex) - { - DateTimeOffset expected = DateTimeValues[dateValueIndex]; + [DataRow("2035-08-18T12:08:42.777+0000", 0)] + [DataRow("2035-08-18T13:08:42.777+0100", 1)] + [DataRow("2035-08-18T11:08:42.777-0100", 2)] + [DataRow("2035-08-18T17:08:42.777+0500", 3)] + [DataRow("2035-08-18T07:08:42.777-0500", 4)] + [DataRow("2035-08-18T13:38:42.777+0130", 5)] + [DataRow("2035-08-18T10:38:42.777-0130", 6)] + [DataRow("2035-08-18T17:38:42.777+0530", 7)] + [DataRow("2035-08-18T06:38:42.777-0530", 8)] + [DataTestMethod] + public void DateTimeFormatDeserializationTest(string dateString, int dateValueIndex) + { + var expected = DateTimeValues[dateValueIndex]; - string jsonDate = $"{{\"date\":\"{dateString}\"}}"; + var jsonDate = $"{{\"date\":\"{dateString}\"}}"; - TestObject actual = JsonConvert.DeserializeObject(jsonDate)!; + var actual = JsonConvert.DeserializeObject(jsonDate)!; - Assert.AreEqual(expected, actual.Date); - Assert.AreEqual(expected.Ticks, actual.Date.Ticks); - Assert.AreEqual(expected.Offset, actual.Date.Offset); - Assert.AreEqual(EXPECTED_DATE, actual.Date.ToString(EXPECTED_DATE_FORMAT)); - Assert.AreEqual(EXPECTED_TICKS, actual.Date.Date.Ticks); - Assert.AreEqual(expected.ToString(), actual.Date.ToString()); - Assert.AreEqual(expected.ToString(EXPECTED_DATETIME_FORMAT), actual.Date.ToString(EXPECTED_DATETIME_FORMAT)); - } + Assert.AreEqual(expected, actual.Date); + Assert.AreEqual(expected.Ticks, actual.Date.Ticks); + Assert.AreEqual(expected.Offset, actual.Date.Offset); + Assert.AreEqual(EXPECTED_DATE, actual.Date.ToString(EXPECTED_DATE_FORMAT)); + Assert.AreEqual(EXPECTED_TICKS, actual.Date.Date.Ticks); + Assert.AreEqual(expected.ToString(), actual.Date.ToString()); + Assert.AreEqual(expected.ToString(EXPECTED_DATETIME_FORMAT), actual.Date.ToString(EXPECTED_DATETIME_FORMAT)); + } - [DataRow(0, "2035-08-18T12:08:42.777+00:00")] - [DataRow(1, "2035-08-18T13:08:42.777+01:00")] - [DataRow(2, "2035-08-18T11:08:42.777-01:00")] - [DataRow(3, "2035-08-18T17:08:42.777+05:00")] - [DataRow(4, "2035-08-18T07:08:42.777-05:00")] - [DataRow(5, "2035-08-18T13:38:42.777+01:30")] - [DataRow(6, "2035-08-18T10:38:42.777-01:30")] - [DataRow(7, "2035-08-18T17:38:42.777+05:30")] - [DataRow(8, "2035-08-18T06:38:42.777-05:30")] - [DataTestMethod] - public void DateTimeFormatSerializationTest(int dateValueIndex, string expected) - { - DateTimeOffset initialDate = DateTimeValues[dateValueIndex]; + [DataRow(0, "2035-08-18T12:08:42.777+00:00")] + [DataRow(1, "2035-08-18T13:08:42.777+01:00")] + [DataRow(2, "2035-08-18T11:08:42.777-01:00")] + [DataRow(3, "2035-08-18T17:08:42.777+05:00")] + [DataRow(4, "2035-08-18T07:08:42.777-05:00")] + [DataRow(5, "2035-08-18T13:38:42.777+01:30")] + [DataRow(6, "2035-08-18T10:38:42.777-01:30")] + [DataRow(7, "2035-08-18T17:38:42.777+05:30")] + [DataRow(8, "2035-08-18T06:38:42.777-05:30")] + [DataTestMethod] + public void DateTimeFormatSerializationTest(int dateValueIndex, string expected) + { + var initialDate = DateTimeValues[dateValueIndex]; - string actual = JsonConvert.SerializeObject(initialDate); + var actual = JsonConvert.SerializeObject(initialDate); - Assert.AreEqual($"\"{expected}\"", actual); - } + Assert.AreEqual($"\"{expected}\"", actual); + } - public class TestObject - { - public DateTimeOffset Date { get; set; } - } + public class TestObject + { + public DateTimeOffset Date { get; set; } } -} +} \ No newline at end of file diff --git a/ApiClient.Tests/GeneralSetupTest.cs b/ApiClient.Tests/GeneralSetupTest.cs index be0220a..f0aee8e 100644 --- a/ApiClient.Tests/GeneralSetupTest.cs +++ b/ApiClient.Tests/GeneralSetupTest.cs @@ -1,22 +1,20 @@ -using System; -using System.Collections.Generic; -using System.Net; +using System.Net; using ApiClient.Tests.Api; using Infobip.Api.Client; using Microsoft.VisualStudio.TestTools.UnitTesting; using RestSharp; -namespace ApiClient.Tests +namespace ApiClient.Tests; + +[TestClass] +public class GeneralSetupTest : ApiTest { - [TestClass] - public class GeneralSetupTest : ApiTest - { - protected const string SMS_SEND_TEXT_ADVANCED_ENDPOINT = "/sms/2/text/advanced"; + protected const string SMS_SEND_TEXT_ADVANCED_ENDPOINT = "/sms/2/text/advanced"; - [TestMethod] - public void UsingExampleFromDocs() - { - string givenRequest = @" + [TestMethod] + public void UsingExampleFromDocs() + { + var givenRequest = @" { ""messages"": [ { @@ -31,7 +29,7 @@ public void UsingExampleFromDocs() ] }"; - string expectedResponse = @" + var expectedResponse = @" { ""bulkId"": ""2034072219640523072"", ""messages"": [ @@ -49,25 +47,24 @@ public void UsingExampleFromDocs() ] }"; - SetUpPostRequest(SMS_SEND_TEXT_ADVANCED_ENDPOINT, new Dictionary { { "param1", "val1" } }, givenRequest, expectedResponse, 200); + SetUpPostRequest(SMS_SEND_TEXT_ADVANCED_ENDPOINT, new Dictionary { { "param1", "val1" } }, + givenRequest, expectedResponse, 200); - var client = new RestClient(configuration!.BasePath + SMS_SEND_TEXT_ADVANCED_ENDPOINT) - { - UserAgent = "infobip-api-client-csharp/" + Configuration.Version, - Timeout = -1 - }; - var request = new RestRequest(Method.POST); - request.AddHeader("Authorization", configuration.ApiKeyWithPrefix); - request.AddHeader("Content-Type", "application/json; charset=utf-8"); - request.AddHeader("Accept", "application/json"); - request.AddQueryParameter("param1", "val1"); - request.AddParameter("application/json", givenRequest, ParameterType.RequestBody); - IRestResponse response = client.Execute(request); - - Assert.IsNotNull(response); - Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); - Assert.AreEqual(expectedResponse, response.Content); + var client = new RestClient(configuration!.BasePath + SMS_SEND_TEXT_ADVANCED_ENDPOINT) + { + UserAgent = "infobip-api-client-csharp/" + Configuration.Version, + Timeout = -1 + }; + var request = new RestRequest(Method.POST); + request.AddHeader("Authorization", configuration.ApiKeyWithPrefix); + request.AddHeader("Content-Type", "application/json; charset=utf-8"); + request.AddHeader("Accept", "application/json"); + request.AddQueryParameter("param1", "val1"); + request.AddParameter("application/json", givenRequest, ParameterType.RequestBody); + var response = client.Execute(request); - } + Assert.IsNotNull(response); + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + Assert.AreEqual(expectedResponse, response.Content); } -} +} \ No newline at end of file