From 9b5db342c16b85f767fc343fd6d3ca37396f7118 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 30 Oct 2017 13:26:07 +0300 Subject: [PATCH] Update telephony methods; More test coverage; Minor fixes in api methods; --- Retailcrm/Retailcrm.csproj | 3 + Retailcrm/Versions/V3/Customers.cs | 2 +- Retailcrm/Versions/V3/Packs.cs | 2 +- Retailcrm/Versions/V3/Telephony.cs | 150 +++++++++ Retailcrm/Versions/V4/Customers.cs | 2 +- Retailcrm/Versions/V4/Orders.cs | 2 +- Retailcrm/Versions/V4/Stores.cs | 2 +- Retailcrm/Versions/V4/Telephony.cs | 116 +++++++ Retailcrm/Versions/V4/Users.cs | 2 +- Retailcrm/Versions/V5/Costs.cs | 27 +- Retailcrm/Versions/V5/CustomFields.cs | 19 +- Retailcrm/Versions/V5/Notes.cs | 2 +- Retailcrm/Versions/V5/Payments.cs | 10 + Retailcrm/Versions/V5/References.cs | 15 + Retailcrm/Versions/V5/Segments.cs | 2 +- Retailcrm/Versions/V5/Stores.cs | 4 +- Retailcrm/Versions/V5/Tasks.cs | 2 +- Retailcrm/Versions/V5/Telephony.cs | 28 ++ RetailcrmUnitTest/ApiTest.cs | 12 +- RetailcrmUnitTest/App.config.dist | 4 + RetailcrmUnitTest/RetailcrmUnitTest.csproj | 16 + RetailcrmUnitTest/V3/ClientTest.cs | 14 +- RetailcrmUnitTest/V3/CustomersTest.cs | 18 +- RetailcrmUnitTest/V3/OrdersTest.cs | 18 +- RetailcrmUnitTest/V3/PacksTest.cs | 41 +-- RetailcrmUnitTest/V3/ReferencesTest.cs | 349 +++++++++++++++++++++ RetailcrmUnitTest/V3/StoresTest.cs | 20 +- RetailcrmUnitTest/V3/TelephonyTest.cs | 33 ++ RetailcrmUnitTest/V4/CustomersTest.cs | 48 +++ RetailcrmUnitTest/V4/MarketplaceTest.cs | 43 +++ RetailcrmUnitTest/V4/OrdersTest.cs | 18 +- RetailcrmUnitTest/V4/ReferencesTest.cs | 35 ++- RetailcrmUnitTest/V4/StoresTest.cs | 37 +++ RetailcrmUnitTest/V4/TelephonyTest.cs | 84 +++++ RetailcrmUnitTest/V4/UsersTest.cs | 41 +++ RetailcrmUnitTest/V5/CostsTest.cs | 226 +++++++++++++ RetailcrmUnitTest/V5/CustomFieldsTest.cs | 163 ++++++++++ RetailcrmUnitTest/V5/IntegrationTest.cs | 51 +++ RetailcrmUnitTest/V5/NotesTest.cs | 72 +++++ RetailcrmUnitTest/V5/OrdersTest.cs | 17 +- RetailcrmUnitTest/V5/PaymentsTest.cs | 83 +++++ RetailcrmUnitTest/V5/ReferencesTest.cs | 117 ++++++- RetailcrmUnitTest/V5/SegmentsTest.cs | 39 +++ RetailcrmUnitTest/V5/TasksTest.cs | 91 ++++++ RetailcrmUnitTest/V5/TelephonyTest.cs | 36 +++ RetailcrmUnitTest/V5/UsersTest.cs | 43 +++ 46 files changed, 2034 insertions(+), 125 deletions(-) create mode 100644 Retailcrm/Versions/V3/Telephony.cs create mode 100644 Retailcrm/Versions/V4/Telephony.cs create mode 100644 Retailcrm/Versions/V5/Telephony.cs create mode 100644 RetailcrmUnitTest/V3/ReferencesTest.cs create mode 100644 RetailcrmUnitTest/V3/TelephonyTest.cs create mode 100644 RetailcrmUnitTest/V4/CustomersTest.cs create mode 100644 RetailcrmUnitTest/V4/MarketplaceTest.cs create mode 100644 RetailcrmUnitTest/V4/StoresTest.cs create mode 100644 RetailcrmUnitTest/V4/TelephonyTest.cs create mode 100644 RetailcrmUnitTest/V4/UsersTest.cs create mode 100644 RetailcrmUnitTest/V5/CostsTest.cs create mode 100644 RetailcrmUnitTest/V5/CustomFieldsTest.cs create mode 100644 RetailcrmUnitTest/V5/IntegrationTest.cs create mode 100644 RetailcrmUnitTest/V5/NotesTest.cs create mode 100644 RetailcrmUnitTest/V5/PaymentsTest.cs create mode 100644 RetailcrmUnitTest/V5/SegmentsTest.cs create mode 100644 RetailcrmUnitTest/V5/TasksTest.cs create mode 100644 RetailcrmUnitTest/V5/TelephonyTest.cs create mode 100644 RetailcrmUnitTest/V5/UsersTest.cs diff --git a/Retailcrm/Retailcrm.csproj b/Retailcrm/Retailcrm.csproj index 9322c2c..418a598 100644 --- a/Retailcrm/Retailcrm.csproj +++ b/Retailcrm/Retailcrm.csproj @@ -58,6 +58,7 @@ + @@ -65,6 +66,7 @@ + @@ -78,6 +80,7 @@ + diff --git a/Retailcrm/Versions/V3/Customers.cs b/Retailcrm/Versions/V3/Customers.cs index 408be6b..3204bf8 100644 --- a/Retailcrm/Versions/V3/Customers.cs +++ b/Retailcrm/Versions/V3/Customers.cs @@ -102,7 +102,7 @@ namespace Retailcrm.Versions.V3 /// /// /// - public Response CustomersList(Dictionary filter = null, int page = 0, int limit = 0) + public Response CustomersList(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V3/Packs.cs b/Retailcrm/Versions/V3/Packs.cs index 4feabdc..44ecb80 100644 --- a/Retailcrm/Versions/V3/Packs.cs +++ b/Retailcrm/Versions/V3/Packs.cs @@ -13,7 +13,7 @@ namespace Retailcrm.Versions.V3 /// /// /// - public Response PacksList(Dictionary filter = null, int page = 0, int limit = 0) + public Response PacksList(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V3/Telephony.cs b/Retailcrm/Versions/V3/Telephony.cs new file mode 100644 index 0000000..330ad95 --- /dev/null +++ b/Retailcrm/Versions/V3/Telephony.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.Web.Script.Serialization; + +namespace Retailcrm.Versions.V3 +{ + public partial class Client + { + /// + /// Get manager + /// + /// + /// + /// + public Response TelephonyManagerGet(string phone, string details = "1") + { + Dictionary parameters = new Dictionary(); + + if (string.IsNullOrEmpty(phone)) + { + throw new ArgumentException("Parameter `phone` must contains a data"); + } + + parameters.Add("details", details); + parameters.Add("phone", phone); + + return Request.MakeRequest("/telephony/manager", Request.MethodGet, parameters); + } + + /// + /// Send call event + /// + /// + /// + /// + /// + /// + public Response TelephonyCallEvent(string phone, string type, string status, string code) + { + if (string.IsNullOrEmpty(phone)) + { + throw new ArgumentException("Parameter `phone` must contains a data"); + } + + if (string.IsNullOrEmpty(code)) + { + throw new ArgumentException("Parameter `phone` must contains a data"); + } + + List statuses = new List { "answered", "busy", "cancel", "failed", "no answered" }; + List types = new List { "hangup", "in", "out" }; + + if (!statuses.Contains(status)) + { + throw new ArgumentException("Parameter `status` must be equal one of `answered|busy|cancel|failed|no answered`"); + } + + if (!types.Contains(type)) + { + throw new ArgumentException("Parameter `type` must be equal one of `hangup|in|out`"); + } + + return Request.MakeRequest( + "/telephony/call/event", + Request.MethodPost, + new Dictionary + { + { "phone", phone }, + { "type", type }, + { "hangupStatus", status}, + { "code", code } + } + ); + } + + /// + /// Upload calls + /// + /// + /// + public Response TelephonyCallsUpload(List calls) + { + if (calls.Count < 1) + { + throw new ArgumentException("Parameter `calls` must contains a data"); + } + + if (calls.Count > 50) + { + throw new ArgumentException("Parameter `calls` must contain 50 or less records"); + } + + return Request.MakeRequest( + "/telephony/calls/upload", + Request.MethodPost, + new Dictionary + { + { "calls", new JavaScriptSerializer().Serialize(calls) } + } + ); + } + + /// + /// Edit telephony settings + /// + /// + /// + /// + /// + /// + /// + /// + public Response TelephonySettingsEdit(string code, string clientId, string url, string name, string logo, string active = "true") + { + if (string.IsNullOrEmpty(name)) + { + throw new ArgumentException("Parameter `name` must contains a data"); + } + + if (string.IsNullOrEmpty(code)) + { + throw new ArgumentException("Parameter `phone` must contains a data"); + } + + if (string.IsNullOrEmpty(url)) + { + throw new ArgumentException("Parameter `url` must contains a data"); + } + + if (string.IsNullOrEmpty(clientId)) + { + throw new ArgumentException("Parameter `clientId` must contains a data"); + } + + return Request.MakeRequest( + $"/telephony/setting/{code}", + Request.MethodPost, + new Dictionary + { + { "code", code }, + { "name", name }, + { "clientId", clientId}, + { "makeCallUrl", url }, + { "image", logo }, + { "active", active } + } + ); + } + } +} diff --git a/Retailcrm/Versions/V4/Customers.cs b/Retailcrm/Versions/V4/Customers.cs index e1bb53c..ce63f78 100644 --- a/Retailcrm/Versions/V4/Customers.cs +++ b/Retailcrm/Versions/V4/Customers.cs @@ -11,7 +11,7 @@ namespace Retailcrm.Versions.V4 /// /// /// - public Response CustomersHistory(Dictionary filter = null, int page = 0, int limit = 0) + public Response CustomersHistory(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V4/Orders.cs b/Retailcrm/Versions/V4/Orders.cs index 7679e1f..36008fd 100644 --- a/Retailcrm/Versions/V4/Orders.cs +++ b/Retailcrm/Versions/V4/Orders.cs @@ -11,7 +11,7 @@ namespace Retailcrm.Versions.V4 /// /// /// - public Response OrdersHistory(Dictionary filter = null, int page = 0, int limit = 0) + public Response OrdersHistory(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V4/Stores.cs b/Retailcrm/Versions/V4/Stores.cs index 3802514..80069f6 100644 --- a/Retailcrm/Versions/V4/Stores.cs +++ b/Retailcrm/Versions/V4/Stores.cs @@ -13,7 +13,7 @@ namespace Retailcrm.Versions.V4 /// /// /// - public Response StoreProducts(Dictionary filter = null, int page = 0, int limit = 0) + public Response StoreProducts(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V4/Telephony.cs b/Retailcrm/Versions/V4/Telephony.cs new file mode 100644 index 0000000..25f176f --- /dev/null +++ b/Retailcrm/Versions/V4/Telephony.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Web.Script.Serialization; + +namespace Retailcrm.Versions.V4 +{ + public partial class Client + { + /// + /// Send call event + /// + /// + /// + public Response TelephonyCallEvent(Dictionary ievent) + { + if (ievent.Count < 1) + { + throw new ArgumentException("Parameter `event` must contain data"); + } + + if (!ievent.ContainsKey("phone")) + { + throw new ArgumentException("Parameter `phone` must contains a data"); + } + + if (!ievent.ContainsKey("type")) + { + throw new ArgumentException("Parameter `type` must contains a data"); + } + + if (!ievent.ContainsKey("hangupStatus")) + { + throw new ArgumentException("Parameter `hangupStatus` must contains a data"); + } + + List statuses = new List { "answered", "busy", "cancel", "failed", "no answered" }; + List types = new List { "hangup", "in", "out" }; + + if (!statuses.Contains(ievent["hangupStatus"].ToString())) + { + throw new ArgumentException("Parameter `status` must be equal one of `answered|busy|cancel|failed|no answered`"); + } + + if (!types.Contains(ievent["type"].ToString())) + { + throw new ArgumentException("Parameter `type` must be equal one of `hangup|in|out`"); + } + + return Request.MakeRequest( + "/telephony/call/event", + Request.MethodPost, + new Dictionary + { + { "event", new JavaScriptSerializer().Serialize(ievent) } + } + ); + } + + /// + /// Get telephony settings + /// + /// + /// + public Response TelephonySettingsGet(string code) + { + if (string.IsNullOrEmpty(code)) + { + throw new ArgumentException("Parameter `code` should contain data"); + } + + return Request.MakeRequest($"/telephony/setting/{code}", Request.MethodGet); + } + + /// + /// Edit telephony settings + /// + /// + /// + public Response TelephonySettingsEdit(Dictionary configuration) + { + if (configuration.Count < 1) + { + throw new ArgumentException("Parameter `configuration` must contain data"); + } + + if (!configuration.ContainsKey("code")) + { + throw new ArgumentException("Parameter `configuration` should contain `code`"); + } + + if (!configuration.ContainsKey("name")) + { + throw new ArgumentException("Parameter `configuration` should contain `name`"); + } + + if (!configuration.ContainsKey("makeCallUrl")) + { + throw new ArgumentException("Parameter `configuration` should contain `makeCallUrl`"); + } + + if (!configuration.ContainsKey("clientId")) + { + throw new ArgumentException("Parameter `configuration` should contain `clientId`"); + } + + return Request.MakeRequest( + $"/telephony/setting/{configuration["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "configuration", new JavaScriptSerializer().Serialize(configuration) } + } + ); + } + } +} diff --git a/Retailcrm/Versions/V4/Users.cs b/Retailcrm/Versions/V4/Users.cs index a8aed51..82b778e 100644 --- a/Retailcrm/Versions/V4/Users.cs +++ b/Retailcrm/Versions/V4/Users.cs @@ -39,7 +39,7 @@ namespace Retailcrm.Versions.V4 /// /// /// - public Response UsersGroups(int page = 0, int limit = 0) + public Response UsersGroups(int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V5/Costs.cs b/Retailcrm/Versions/V5/Costs.cs index 3dea7ab..55109d4 100644 --- a/Retailcrm/Versions/V5/Costs.cs +++ b/Retailcrm/Versions/V5/Costs.cs @@ -13,7 +13,7 @@ namespace Retailcrm.Versions.V5 /// /// /// - public Response CostsList(Dictionary filter = null, int page = 0, int limit = 0) + public Response CostsList(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); @@ -48,6 +48,26 @@ namespace Retailcrm.Versions.V5 throw new ArgumentException("Parameter `cost` must contains a data"); } + if (!cost.ContainsKey("costItem")) + { + throw new ArgumentException("Parameter `costItem` must be set"); + } + + if (!cost.ContainsKey("summ")) + { + throw new ArgumentException("Parameter `summ` must be set"); + } + + if (!cost.ContainsKey("dateFrom")) + { + throw new ArgumentException("`dateFrom`: Time interval lower bound must not be blank"); + } + + if (!cost.ContainsKey("dateTo")) + { + throw new ArgumentException("`dateTo`: Time interval upper bound must not be blank"); + } + return Request.MakeRequest( "/costs/create", Request.MethodPost, @@ -95,6 +115,11 @@ namespace Retailcrm.Versions.V5 throw new ArgumentException("Parameter `costs` must contains a data"); } + if (costs.Count > 50) + { + throw new ArgumentException("Parameter `costs` must contain 50 or less records"); + } + return Request.MakeRequest( "/costs/upload", Request.MethodPost, diff --git a/Retailcrm/Versions/V5/CustomFields.cs b/Retailcrm/Versions/V5/CustomFields.cs index f2bb57c..f6733a5 100644 --- a/Retailcrm/Versions/V5/CustomFields.cs +++ b/Retailcrm/Versions/V5/CustomFields.cs @@ -13,7 +13,7 @@ namespace Retailcrm.Versions.V5 /// /// /// - public Response CustomFieldsList(Dictionary filter = null, int page = 0, int limit = 0) + public Response CustomFieldsList(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); @@ -39,9 +39,8 @@ namespace Retailcrm.Versions.V5 /// Create custom field /// /// - /// /// - public Response CustomFieldsCreate(Dictionary customField, string entity = "") + public Response CustomFieldsCreate(Dictionary customField) { List types = new List { @@ -68,6 +67,11 @@ namespace Retailcrm.Versions.V5 throw new ArgumentException("Parameter `customField` should contain `type`"); } + if (!customField.ContainsKey("entity")) + { + throw new ArgumentException("Parameter `customField` should contain `entity`"); + } + if (!types.Contains(customField["type"].ToString())) { throw new ArgumentException( @@ -76,7 +80,7 @@ namespace Retailcrm.Versions.V5 } return Request.MakeRequest( - $"/custom-fields/{entity}/create", + $"/custom-fields/{customField["entity"].ToString()}/create", Request.MethodPost, new Dictionary { @@ -103,9 +107,8 @@ namespace Retailcrm.Versions.V5 /// Update custom field /// /// - /// /// - public Response CustomFieldsUpdate(Dictionary customField, string entity = "") + public Response CustomFieldsUpdate(Dictionary customField) { if (customField.Count < 1) { @@ -123,7 +126,7 @@ namespace Retailcrm.Versions.V5 } return Request.MakeRequest( - $"/custom-fields/{entity}/{customField["code"].ToString()}/edit", + $"/custom-fields/{customField["entity"].ToString()}/{customField["code"].ToString()}/edit", Request.MethodPost, new Dictionary { @@ -139,7 +142,7 @@ namespace Retailcrm.Versions.V5 /// /// /// - public Response CustomDictionaryList(Dictionary filter = null, int page = 0, int limit = 0) + public Response CustomDictionaryList(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V5/Notes.cs b/Retailcrm/Versions/V5/Notes.cs index 06e7e23..d9e8ed1 100644 --- a/Retailcrm/Versions/V5/Notes.cs +++ b/Retailcrm/Versions/V5/Notes.cs @@ -52,7 +52,7 @@ namespace Retailcrm.Versions.V5 /// /// /// - public Response NotesList(Dictionary filter = null, int page = 0, int limit = 0) + public Response NotesList(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V5/Payments.cs b/Retailcrm/Versions/V5/Payments.cs index df340f2..39e920b 100644 --- a/Retailcrm/Versions/V5/Payments.cs +++ b/Retailcrm/Versions/V5/Payments.cs @@ -19,6 +19,16 @@ namespace Retailcrm.Versions.V5 throw new ArgumentException("Parameter `payment` must contains a data"); } + if (!payment.ContainsKey("type")) + { + throw new ArgumentException("Parameter `type` must be set"); + } + + if (!payment.ContainsKey("order")) + { + throw new ArgumentException("Parameter `order` must be set"); + } + return Request.MakeRequest( "/orders/payments/create", Request.MethodPost, diff --git a/Retailcrm/Versions/V5/References.cs b/Retailcrm/Versions/V5/References.cs index b66a406..2a724cf 100644 --- a/Retailcrm/Versions/V5/References.cs +++ b/Retailcrm/Versions/V5/References.cs @@ -91,6 +91,11 @@ namespace Retailcrm.Versions.V5 throw new ArgumentException("Parameter `name` is missing"); } + if (!item.ContainsKey("group")) + { + throw new ArgumentException("Parameter `group` is missing"); + } + List types = new List { "const", @@ -129,6 +134,16 @@ namespace Retailcrm.Versions.V5 throw new ArgumentException("Parameter `legalName` is missing"); } + if (!entity.ContainsKey("countryIso")) + { + throw new ArgumentException("Parameter `countryIso` is missing"); + } + + if (!entity.ContainsKey("contragentType")) + { + throw new ArgumentException("Parameter `contragentType` is missing"); + } + return Request.MakeRequest( $"/reference/legal-entities/{entity["code"].ToString()}/edit", Request.MethodPost, diff --git a/Retailcrm/Versions/V5/Segments.cs b/Retailcrm/Versions/V5/Segments.cs index 00c556d..89a5b05 100644 --- a/Retailcrm/Versions/V5/Segments.cs +++ b/Retailcrm/Versions/V5/Segments.cs @@ -11,7 +11,7 @@ namespace Retailcrm.Versions.V5 /// /// /// - public Response Segments(Dictionary filter = null, int page = 0, int limit = 0) + public Response Segments(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V5/Stores.cs b/Retailcrm/Versions/V5/Stores.cs index 3199779..cebc55d 100644 --- a/Retailcrm/Versions/V5/Stores.cs +++ b/Retailcrm/Versions/V5/Stores.cs @@ -32,7 +32,7 @@ namespace Retailcrm.Versions.V5 /// /// /// - public Response StoreProductsGroups(Dictionary filter = null, int page = 0, int limit = 0) + public Response StoreProductsGroups(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); @@ -61,7 +61,7 @@ namespace Retailcrm.Versions.V5 /// /// /// - public Response StoreProductsProperties(Dictionary filter = null, int page = 0, int limit = 0) + public Response StoreProductsProperties(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V5/Tasks.cs b/Retailcrm/Versions/V5/Tasks.cs index 8f01663..44466a5 100644 --- a/Retailcrm/Versions/V5/Tasks.cs +++ b/Retailcrm/Versions/V5/Tasks.cs @@ -83,7 +83,7 @@ namespace Retailcrm.Versions.V5 /// /// /// - public Response TasksList(Dictionary filter = null, int page = 0, int limit = 0) + public Response TasksList(Dictionary filter = null, int page = 1, int limit = 20) { Dictionary parameters = new Dictionary(); diff --git a/Retailcrm/Versions/V5/Telephony.cs b/Retailcrm/Versions/V5/Telephony.cs new file mode 100644 index 0000000..90923bb --- /dev/null +++ b/Retailcrm/Versions/V5/Telephony.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; + +namespace Retailcrm.Versions.V5 +{ + public partial class Client + { + /// + /// Get telephony settings + /// + /// + /// + public new Response TelephonySettingsGet(string code) + { + throw new ArgumentException("This method is unavailable in API V5", code); + } + + /// + /// Edit telephony settings + /// + /// + /// + public new Response TelephonySettingsEdit(Dictionary configuration) + { + throw new ArgumentException("This method is unavailable in API V5", configuration.ToString()); + } + } +} diff --git a/RetailcrmUnitTest/ApiTest.cs b/RetailcrmUnitTest/ApiTest.cs index 42226fc..00dc6ef 100644 --- a/RetailcrmUnitTest/ApiTest.cs +++ b/RetailcrmUnitTest/ApiTest.cs @@ -1,10 +1,10 @@ -namespace RetailcrmUnitTest -{ - using System.Collections.Specialized; - using System.Configuration; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Retailcrm; +using System.Collections.Specialized; +using System.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +namespace RetailcrmUnitTest +{ [TestClass] public class ApiTest { diff --git a/RetailcrmUnitTest/App.config.dist b/RetailcrmUnitTest/App.config.dist index 1a5450d..1e318f9 100644 --- a/RetailcrmUnitTest/App.config.dist +++ b/RetailcrmUnitTest/App.config.dist @@ -4,5 +4,9 @@ + + + + \ No newline at end of file diff --git a/RetailcrmUnitTest/RetailcrmUnitTest.csproj b/RetailcrmUnitTest/RetailcrmUnitTest.csproj index 8e023d2..4e311fc 100644 --- a/RetailcrmUnitTest/RetailcrmUnitTest.csproj +++ b/RetailcrmUnitTest/RetailcrmUnitTest.csproj @@ -58,11 +58,27 @@ + + + + + + + + + + + + + + + + diff --git a/RetailcrmUnitTest/V3/ClientTest.cs b/RetailcrmUnitTest/V3/ClientTest.cs index 9814be0..acbb2b1 100644 --- a/RetailcrmUnitTest/V3/ClientTest.cs +++ b/RetailcrmUnitTest/V3/ClientTest.cs @@ -1,11 +1,11 @@ -namespace RetailcrmUnitTest.V3 -{ - using System.Collections.Specialized; - using System.Configuration; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Retailcrm; - using Retailcrm.Versions.V3; +using System.Collections.Specialized; +using System.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V3; +namespace RetailcrmUnitTest.V3 +{ [TestClass] public class ClientTest { diff --git a/RetailcrmUnitTest/V3/CustomersTest.cs b/RetailcrmUnitTest/V3/CustomersTest.cs index 3d13e9b..f2487c1 100644 --- a/RetailcrmUnitTest/V3/CustomersTest.cs +++ b/RetailcrmUnitTest/V3/CustomersTest.cs @@ -1,13 +1,13 @@ -namespace RetailcrmUnitTest.V3 -{ - using System; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.Configuration; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Retailcrm; - using Retailcrm.Versions.V3; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V3; +namespace RetailcrmUnitTest.V3 +{ [TestClass] public class CustomersTest { diff --git a/RetailcrmUnitTest/V3/OrdersTest.cs b/RetailcrmUnitTest/V3/OrdersTest.cs index 54d8787..0da1443 100644 --- a/RetailcrmUnitTest/V3/OrdersTest.cs +++ b/RetailcrmUnitTest/V3/OrdersTest.cs @@ -1,13 +1,13 @@ -namespace RetailcrmUnitTest.V3 -{ - using System; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.Configuration; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Retailcrm; - using Retailcrm.Versions.V3; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V3; +namespace RetailcrmUnitTest.V3 +{ [TestClass] public class OrdersTest { diff --git a/RetailcrmUnitTest/V3/PacksTest.cs b/RetailcrmUnitTest/V3/PacksTest.cs index 1dacf8f..454c7ee 100644 --- a/RetailcrmUnitTest/V3/PacksTest.cs +++ b/RetailcrmUnitTest/V3/PacksTest.cs @@ -1,16 +1,15 @@ -using System.Globalization; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using System.Globalization; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V3; namespace RetailcrmUnitTest.V3 { - using System; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.Configuration; - using System.Linq; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Retailcrm; - using Retailcrm.Versions.V3; - [TestClass] public class PacksTest { @@ -23,28 +22,6 @@ namespace RetailcrmUnitTest.V3 _client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"], _appSettings["site"]); } - #region Дополнительные атрибуты тестирования - // - // При написании тестов можно использовать следующие дополнительные атрибуты: - // - // ClassInitialize используется для выполнения кода до запуска первого теста в классе - // [ClassInitialize()] - // public static void MyClassInitialize(TestContext testContext) { } - // - // ClassCleanup используется для выполнения кода после завершения работы всех тестов в классе - // [ClassCleanup()] - // public static void MyClassCleanup() { } - // - // TestInitialize используется для выполнения кода перед запуском каждого теста - // [TestInitialize()] - // public void MyTestInitialize() { } - // - // TestCleanup используется для выполнения кода после завершения каждого теста - // [TestCleanup()] - // public void MyTestCleanup() { } - // - #endregion - [TestMethod] public void PacksCreateUpdateReadDelete() { diff --git a/RetailcrmUnitTest/V3/ReferencesTest.cs b/RetailcrmUnitTest/V3/ReferencesTest.cs new file mode 100644 index 0000000..667d310 --- /dev/null +++ b/RetailcrmUnitTest/V3/ReferencesTest.cs @@ -0,0 +1,349 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V3; + +namespace RetailcrmUnitTest.V3 +{ + [TestClass] + public class ReferencesTest + { + private readonly Client _client; + + public ReferencesTest() + { + NameValueCollection appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void Countries() + { + Response response = _client.Countries(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void DeliveryServices() + { + Response response = _client.DeliveryServices(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void DeliveryTypes() + { + Response response = _client.DeliveryTypes(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void OrderMethods() + { + Response response = _client.OrderMethods(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void OrderTypes() + { + Response response = _client.OrderTypes(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void PaymentStatuses() + { + Response response = _client.PaymentStatuses(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void PaymentTypes() + { + Response response = _client.PaymentTypes(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void ProductStatuses() + { + Response response = _client.ProductStatuses(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void Sites() + { + Response response = _client.Sites(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void StatusGroups() + { + Response response = _client.StatusGroups(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void Statuses() + { + Response response = _client.Statuses(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void Stores() + { + Response response = _client.Stores(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void DeliveryServicesEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.DeliveryServicesEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestDeliveryService-{guid}" } + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void DeliveryTypesEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.DeliveryTypesEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestDeliveryType-{guid}" }, + { "defaultCost", 300 }, + { "defaultNetCost", 250} + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void OrderMethodsEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.OrderMethodsEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestOrderMethod-{guid}" } + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void OrderTypesEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.OrderTypesEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestOrderType-{guid}" } + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void PaymentStatusesEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.PaymentStatusesEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestPaymentStatus-{guid}" } + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void PaymentTypesEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.PaymentTypesEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestPaymentType-{guid}" } + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void ProductStatusesEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.ProductStatusesEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestProductStatus-{guid}" } + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void SitesEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.SitesEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestProductStatus-{guid}" }, + { "url", $"http://{guid}.example.org" } + } + ); + + Assert.IsFalse(response.IsSuccessfull()); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void StatusesEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.StatusesEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestProductStatus-{guid}" }, + { "ordering", 40}, + { "group", "cancel"} + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void StoresEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.StoresEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestProductStatus-{guid}" }, + { "type", "store-type-warehouse"} + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + } +} \ No newline at end of file diff --git a/RetailcrmUnitTest/V3/StoresTest.cs b/RetailcrmUnitTest/V3/StoresTest.cs index 5df8f2e..f1ae7c3 100644 --- a/RetailcrmUnitTest/V3/StoresTest.cs +++ b/RetailcrmUnitTest/V3/StoresTest.cs @@ -1,14 +1,14 @@ -namespace RetailcrmUnitTest.V3 -{ - using System; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.Configuration; - using System.Diagnostics; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Retailcrm; - using Retailcrm.Versions.V3; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V3; +namespace RetailcrmUnitTest.V3 +{ [TestClass] public class StoresTest { diff --git a/RetailcrmUnitTest/V3/TelephonyTest.cs b/RetailcrmUnitTest/V3/TelephonyTest.cs new file mode 100644 index 0000000..22ab2e9 --- /dev/null +++ b/RetailcrmUnitTest/V3/TelephonyTest.cs @@ -0,0 +1,33 @@ +using System.Collections.Specialized; +using System.Configuration; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V3; + +namespace RetailcrmUnitTest.V3 +{ + [TestClass] + public class TelephonyTest + { + private readonly Client _client; + private readonly NameValueCollection _appSettings; + + public TelephonyTest() + { + _appSettings = ConfigurationManager.AppSettings; + _client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]); + } + + [TestMethod] + public void TelephonyManagerGet() + { + Response response = _client.TelephonyManagerGet(_appSettings["phone"]); + Debug.WriteLine(response.GetRawResponse()); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + } +} diff --git a/RetailcrmUnitTest/V4/CustomersTest.cs b/RetailcrmUnitTest/V4/CustomersTest.cs new file mode 100644 index 0000000..38f6b3c --- /dev/null +++ b/RetailcrmUnitTest/V4/CustomersTest.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V4; + +namespace RetailcrmUnitTest.V4 +{ + [TestClass] + public class CustomersTest + { + private readonly Client _client; + + public CustomersTest() + { + NameValueCollection appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void CustomersHistory() + { + Response response = _client.CustomersHistory(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("history")); + + DateTime datetime = DateTime.Now; + + Response responseFiltered = _client.CustomersHistory( + new Dictionary + { + { "startDate", datetime.AddMonths(-2).ToString("yyyy-MM-dd HH:mm:ss") }, + { "endDate", datetime.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss")} + } + ); + + Assert.IsTrue(responseFiltered.IsSuccessfull()); + Assert.IsTrue(responseFiltered.GetStatusCode() == 200); + Assert.IsInstanceOfType(responseFiltered, typeof(Response)); + Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("history")); + } + } +} diff --git a/RetailcrmUnitTest/V4/MarketplaceTest.cs b/RetailcrmUnitTest/V4/MarketplaceTest.cs new file mode 100644 index 0000000..c18875f --- /dev/null +++ b/RetailcrmUnitTest/V4/MarketplaceTest.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V4; + +namespace RetailcrmUnitTest.V4 +{ + [TestClass] + public class MarketplaceTest + { + private readonly Client _client; + + public MarketplaceTest() + { + var appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void MarketplaceSettingsEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.MarketplaceSettingsEdit( + new Dictionary() + { + { "name", $"MarketplaceApp-{guid}" }, + { "code", guid}, + { "configurationUrl", $"http://{guid}.example.com"}, + { "active", false} + } + ); + + Debug.WriteLine(response.GetRawResponse()); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + } +} diff --git a/RetailcrmUnitTest/V4/OrdersTest.cs b/RetailcrmUnitTest/V4/OrdersTest.cs index f33668f..91e4989 100644 --- a/RetailcrmUnitTest/V4/OrdersTest.cs +++ b/RetailcrmUnitTest/V4/OrdersTest.cs @@ -1,13 +1,13 @@ -namespace RetailcrmUnitTest.V4 -{ - using System; - using System.Collections.Specialized; - using System.Configuration; - using System.Collections.Generic; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Retailcrm; - using Retailcrm.Versions.V4; +using System; +using System.Collections.Specialized; +using System.Configuration; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V4; +namespace RetailcrmUnitTest.V4 +{ [TestClass] public class OrdersTest { diff --git a/RetailcrmUnitTest/V4/ReferencesTest.cs b/RetailcrmUnitTest/V4/ReferencesTest.cs index 596d824..00aa3e1 100644 --- a/RetailcrmUnitTest/V4/ReferencesTest.cs +++ b/RetailcrmUnitTest/V4/ReferencesTest.cs @@ -1,11 +1,13 @@ -namespace RetailcrmUnitTest.V4 -{ - using System.Collections.Specialized; - using System.Configuration; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Retailcrm; - using Retailcrm.Versions.V4; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V4; +namespace RetailcrmUnitTest.V4 +{ [TestClass] public class ReferencesTest { @@ -27,5 +29,24 @@ Assert.IsInstanceOfType(response, typeof(Response)); Assert.IsTrue(response.GetResponse().ContainsKey("priceTypes")); } + + [TestMethod] + public void PriceTypesEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.PriceTypesEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestPriceType-{guid}" } + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } } } diff --git a/RetailcrmUnitTest/V4/StoresTest.cs b/RetailcrmUnitTest/V4/StoresTest.cs new file mode 100644 index 0000000..ee1598d --- /dev/null +++ b/RetailcrmUnitTest/V4/StoresTest.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V4; + +namespace RetailcrmUnitTest.V4 +{ + [TestClass] + public class StoresTest + { + private readonly Client _client; + private readonly NameValueCollection _appSettings; + + public StoresTest() + { + _appSettings = ConfigurationManager.AppSettings; + _client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"], _appSettings["site"]); + } + + [TestMethod] + public void StoreProducts() + { + Response response = _client.StoreProducts(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("products")); + } + + + } +} diff --git a/RetailcrmUnitTest/V4/TelephonyTest.cs b/RetailcrmUnitTest/V4/TelephonyTest.cs new file mode 100644 index 0000000..9b30814 --- /dev/null +++ b/RetailcrmUnitTest/V4/TelephonyTest.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V4; + +namespace RetailcrmUnitTest.V4 +{ + [TestClass] + public class TelephonyTest + { + private readonly Client _client; + private readonly NameValueCollection _appSettings; + private readonly string _phoneCode = "100"; + private readonly string _logoUrl = "http://www.onsitemaintenance.com/img/voip.svg"; + private readonly string _telephonyCode = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + public TelephonyTest() + { + _appSettings = ConfigurationManager.AppSettings; + _client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]); + } + + [TestMethod] + public void TelephonySettingsEdit() + { + Response response = _client.TelephonySettingsEdit( + new Dictionary + { + + { "code", _telephonyCode}, + { "clientId", _appSettings["customer"] }, + { "makeCallUrl", $"http://{_telephonyCode}.example.com/call"}, + { "name", $"TestTelephony-{_telephonyCode}"}, + { "image", _logoUrl}, + { "inputEventSupported", true}, + { "outputEventSupported", true}, + { "hangupEventSupported", true}, + { + "additionalCodes", + new List + { + new Dictionary + { + { "userId", _appSettings["manager"] }, + { "code", _phoneCode } + } + } + } + } + ); + + Debug.WriteLine(response.GetRawResponse()); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void TelephonyCallEvent() + { + Response response = _client.TelephonyCallEvent( + new Dictionary + { + { "phone", _appSettings["phone"] }, + { "type", "in" }, + { "hangupStatus", "failed"}, + { "codes", new List { _phoneCode }}, + { "userIds", new List { int.Parse(_appSettings["customer"]) }} + } + + ); + Debug.WriteLine(response.GetRawResponse()); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + } +} diff --git a/RetailcrmUnitTest/V4/UsersTest.cs b/RetailcrmUnitTest/V4/UsersTest.cs new file mode 100644 index 0000000..5a8a441 --- /dev/null +++ b/RetailcrmUnitTest/V4/UsersTest.cs @@ -0,0 +1,41 @@ +using System.Collections.Specialized; +using System.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V4; + +namespace RetailcrmUnitTest.V4 +{ + [TestClass] + public class UsersTest + { + private readonly Client _client; + private readonly NameValueCollection _appSettings; + + public UsersTest() + { + _appSettings = ConfigurationManager.AppSettings; + _client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]); + } + + [TestMethod] + public void UsersGroups() + { + Response usersGroups = _client.UsersGroups(); + Assert.IsTrue(usersGroups.IsSuccessfull()); + Assert.IsTrue(usersGroups.GetStatusCode() == 200); + Assert.IsInstanceOfType(usersGroups, typeof(Response)); + Assert.IsTrue(usersGroups.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void User() + { + Response usersGroups = _client.User(int.Parse(_appSettings["manager"])); + Assert.IsTrue(usersGroups.IsSuccessfull()); + Assert.IsTrue(usersGroups.GetStatusCode() == 200); + Assert.IsInstanceOfType(usersGroups, typeof(Response)); + Assert.IsTrue(usersGroups.GetResponse().ContainsKey("success")); + } + } +} diff --git a/RetailcrmUnitTest/V5/CostsTest.cs b/RetailcrmUnitTest/V5/CostsTest.cs new file mode 100644 index 0000000..77012dc --- /dev/null +++ b/RetailcrmUnitTest/V5/CostsTest.cs @@ -0,0 +1,226 @@ +using System; +using System.Configuration; +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V5; + +namespace RetailcrmUnitTest.V5 +{ + [TestClass] + public class CostsTest + { + private readonly Client _client; + + public CostsTest() + { + var appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void CostsCreateUpdateReadDelete() + { + DateTime datetime = DateTime.Now; + + string groupGuid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response groupResponse = _client.CostGroupsEdit( + new Dictionary + { + { "code", groupGuid}, + { "name", $"TestCostGroup-{groupGuid}" }, + { "color", "#60b29a" } + } + ); + + Debug.WriteLine(groupResponse.GetRawResponse()); + Assert.IsTrue(groupResponse.IsSuccessfull()); + Assert.IsTrue(groupResponse.GetStatusCode() == 200 || groupResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(groupResponse, typeof(Response)); + Assert.IsTrue(groupResponse.GetResponse().ContainsKey("success")); + + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response itemCostResponse = _client.CostItemsEdit( + new Dictionary + { + { "code", guid}, + { "group", groupGuid }, + { "name", $"TestCostItem-{guid}" }, + { "type", "const" } + } + ); + + Debug.WriteLine(itemCostResponse.GetRawResponse()); + Assert.IsTrue(itemCostResponse.IsSuccessfull()); + Assert.IsTrue(itemCostResponse.GetStatusCode() == 200 || itemCostResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(itemCostResponse, typeof(Response)); + Assert.IsTrue(itemCostResponse.GetResponse().ContainsKey("success")); + + Response costsCreateResponse = _client.CostsCreate( + new Dictionary + { + { "summ", 20000 }, + { "comment", "test cost" }, + { "costItem", guid }, + { "dateFrom", datetime.AddDays(-3).ToString("yyyy-MM-dd")}, + { "dateTo", datetime.AddDays(+3).ToString("yyyy-MM-dd")}, + } + ); + + Debug.WriteLine(costsCreateResponse.GetRawResponse()); + Assert.IsTrue(costsCreateResponse.IsSuccessfull()); + Assert.IsTrue(costsCreateResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(costsCreateResponse, typeof(Response)); + Assert.IsTrue(costsCreateResponse.GetResponse().ContainsKey("success")); + + Response costsUpdateResponse = _client.CostsUpdate( + new Dictionary + { + { "id", costsCreateResponse.GetResponse()["id"].ToString()}, + { "summ", 30000 }, + { "comment", "test cost update" }, + { "costItem", guid }, + { "dateFrom", datetime.AddDays(-3).ToString("yyyy-MM-dd")}, + { "dateTo", datetime.AddDays(+3).ToString("yyyy-MM-dd")}, + } + ); + + Debug.WriteLine(costsUpdateResponse.GetRawResponse()); + Assert.IsTrue(costsUpdateResponse.IsSuccessfull()); + Assert.IsTrue(costsUpdateResponse.GetStatusCode() == 200 || costsUpdateResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(costsUpdateResponse, typeof(Response)); + Assert.IsTrue(costsUpdateResponse.GetResponse().ContainsKey("success")); + + Response responseGet = _client.CostsGet(int.Parse(costsCreateResponse.GetResponse()["id"].ToString())); + + Debug.WriteLine(responseGet.GetRawResponse()); + Assert.IsTrue(responseGet.IsSuccessfull()); + Assert.IsTrue(responseGet.GetStatusCode() == 200); + Assert.IsInstanceOfType(responseGet, typeof(Response)); + Assert.IsTrue(responseGet.GetResponse().ContainsKey("success")); + + Response response = _client.CostsDelete(costsCreateResponse.GetResponse()["id"].ToString()); + + Debug.WriteLine(response.GetRawResponse()); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void CostsList() + { + DateTime datetime = DateTime.Now; + + Response responseFiltered = _client.CostsList( + new Dictionary + { + { "createdAtFrom", datetime.AddDays(-30).ToString("yyyy-MM-dd HH:mm:ss") } + }, + 2, + 50 + ); + + Debug.WriteLine(responseFiltered.GetRawResponse()); + Assert.IsTrue(responseFiltered.IsSuccessfull()); + Assert.IsTrue(responseFiltered.GetStatusCode() == 200); + Assert.IsInstanceOfType(responseFiltered, typeof(Response)); + Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("costs")); + } + + [TestMethod] + public void CostsUploadDelete() + { + DateTime datetime = DateTime.Now; + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + string groupGuid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response groupResponse = _client.CostGroupsEdit( + new Dictionary + { + { "code", groupGuid}, + { "name", $"TestCostGroup-{groupGuid}" }, + { "color", "#60b29a" } + } + ); + + Debug.WriteLine(groupResponse.GetRawResponse()); + Assert.IsTrue(groupResponse.IsSuccessfull()); + Assert.IsTrue(groupResponse.GetStatusCode() == 200 || groupResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(groupResponse, typeof(Response)); + Assert.IsTrue(groupResponse.GetResponse().ContainsKey("success")); + + Response itemCostResponse = _client.CostItemsEdit( + new Dictionary + { + { "code", guid}, + { "group", groupGuid }, + { "name", $"TestCostItem-{guid}" }, + { "type", "const" } + } + ); + + Debug.WriteLine(itemCostResponse.GetRawResponse()); + Assert.IsTrue(itemCostResponse.IsSuccessfull()); + Assert.IsTrue(itemCostResponse.GetStatusCode() == 200 || itemCostResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(itemCostResponse, typeof(Response)); + Assert.IsTrue(itemCostResponse.GetResponse().ContainsKey("success")); + + Response costsUploadResponse = _client.CostsUpload( + new List + { + new Dictionary + { + { "summ", 10000 }, + { "comment", "test cost 1" }, + { "costItem", guid }, + { "dateFrom", datetime.AddDays(-3).ToString("yyyy-MM-dd")}, + { "dateTo", datetime.AddDays(+3).ToString("yyyy-MM-dd")}, + }, + new Dictionary + { + { "summ", 20000 }, + { "comment", "test cost 2" }, + { "costItem", guid }, + { "dateFrom", datetime.AddDays(-3).ToString("yyyy-MM-dd")}, + { "dateTo", datetime.AddDays(+3).ToString("yyyy-MM-dd")}, + }, + new Dictionary + { + { "summ", 30000 }, + { "comment", "test cost 3" }, + { "costItem", guid }, + { "dateFrom", datetime.AddDays(-3).ToString("yyyy-MM-dd")}, + { "dateTo", datetime.AddDays(+3).ToString("yyyy-MM-dd")}, + }, + } + ); + + Debug.WriteLine(costsUploadResponse.GetRawResponse()); + Assert.IsTrue(costsUploadResponse.IsSuccessfull()); + Assert.IsTrue(costsUploadResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(costsUploadResponse, typeof(Response)); + Assert.IsTrue(costsUploadResponse.GetResponse().ContainsKey("success")); + + List uploadedCosts = new List(); + object[] uids = (object[]) costsUploadResponse.GetResponse()["uploadedCosts"]; + + foreach (var uid in uids) + { + uploadedCosts.Add(uid.ToString()); + } + + Response costsDeleteResponse = _client.CostsDelete(uploadedCosts); + + Debug.WriteLine(costsDeleteResponse.GetRawResponse()); + Assert.IsTrue(costsDeleteResponse.IsSuccessfull()); + Assert.IsTrue(costsDeleteResponse.GetStatusCode() == 200); + Assert.IsInstanceOfType(costsUploadResponse, typeof(Response)); + Assert.IsTrue(costsUploadResponse.GetResponse().ContainsKey("success")); + } + } +} diff --git a/RetailcrmUnitTest/V5/CustomFieldsTest.cs b/RetailcrmUnitTest/V5/CustomFieldsTest.cs new file mode 100644 index 0000000..ab42b21 --- /dev/null +++ b/RetailcrmUnitTest/V5/CustomFieldsTest.cs @@ -0,0 +1,163 @@ +using System; +using System.Configuration; +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V5; + +namespace RetailcrmUnitTest.V5 +{ + [TestClass] + public class CustomFieldsTest + { + private readonly Client _client; + + public CustomFieldsTest() + { + var appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void CustomFieldsList() + { + Response responseFiltered = _client.CustomFieldsList(new Dictionary { { "entity", "order" } }, 2, 50); + + Debug.WriteLine(responseFiltered.GetRawResponse()); + Assert.IsTrue(responseFiltered.IsSuccessfull()); + Assert.IsTrue(responseFiltered.GetStatusCode() == 200); + Assert.IsInstanceOfType(responseFiltered, typeof(Response)); + Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("customFields")); + } + + [TestMethod] + public void CustomFieldsCreateUpdateRead() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response customFieldsCreateResponse = _client.CustomFieldsCreate( + new Dictionary + { + { "code", $"customfield{guid}" }, + { "name", $"CustomField-{guid}"}, + { "type", "string"}, + { "entity", "order"} + } + ); + + Debug.WriteLine(customFieldsCreateResponse.GetRawResponse()); + Assert.IsTrue(customFieldsCreateResponse.IsSuccessfull()); + Assert.IsTrue(customFieldsCreateResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(customFieldsCreateResponse, typeof(Response)); + Assert.IsTrue(customFieldsCreateResponse.GetResponse().ContainsKey("code")); + + Response customFieldGetResponse = _client.CustomFieldsGet($"customfield{guid}", "order"); + + Debug.WriteLine(customFieldGetResponse.GetRawResponse()); + Assert.IsTrue(customFieldGetResponse.IsSuccessfull()); + Assert.IsTrue(customFieldGetResponse.GetStatusCode() == 200); + Assert.IsInstanceOfType(customFieldGetResponse, typeof(Response)); + Assert.IsTrue(customFieldGetResponse.GetResponse().ContainsKey("customField")); + + Response customFieldsUpdateResponse = _client.CustomFieldsUpdate( + new Dictionary + { + { "code", $"customfield{guid}" }, + { "name", $"CustomField-{guid}"}, + { "type", "string"}, + { "entity", "order"}, + { "inList", false} + } + ); + + Debug.WriteLine(customFieldsUpdateResponse.GetRawResponse()); + Assert.IsTrue(customFieldsUpdateResponse.IsSuccessfull()); + Assert.IsTrue(customFieldsUpdateResponse.GetStatusCode() == 200); + Assert.IsInstanceOfType(customFieldsUpdateResponse, typeof(Response)); + Assert.IsTrue(customFieldsUpdateResponse.GetResponse().ContainsKey("code")); + } + + [TestMethod] + public void CustomDictionaryList() + { + Response responseFiltered = _client.CustomDictionaryList(new Dictionary(), 2, 50); + + Debug.WriteLine(responseFiltered.GetRawResponse()); + Assert.IsTrue(responseFiltered.IsSuccessfull()); + Assert.IsTrue(responseFiltered.GetStatusCode() == 200); + Assert.IsInstanceOfType(responseFiltered, typeof(Response)); + Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("customDictionaries")); + } + + [TestMethod] + public void CustomDictionariesCreateUpdateRead() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + string fuid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response customDictionaryCreateResponse = _client.CustomDictionaryCreate( + new Dictionary + { + { "code", $"customdict{guid}" }, + { "name", $"CustomDict-{guid}"}, + { + "elements", + new List + { + new Dictionary + { + { "code", $"customdictelement-{fuid}" }, + { "name", $"CustomDictElement-{fuid}" } + } + } + } + } + ); + + Debug.WriteLine(customDictionaryCreateResponse.GetRawResponse()); + Assert.IsTrue(customDictionaryCreateResponse.IsSuccessfull()); + Assert.IsTrue(customDictionaryCreateResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(customDictionaryCreateResponse, typeof(Response)); + Assert.IsTrue(customDictionaryCreateResponse.GetResponse().ContainsKey("code")); + + Response customDictionaryGetResponse = _client.CustomDictionaryGet(customDictionaryCreateResponse.GetResponse()["code"].ToString()); + + Debug.WriteLine(customDictionaryGetResponse.GetRawResponse()); + Assert.IsTrue(customDictionaryGetResponse.IsSuccessfull()); + Assert.IsTrue(customDictionaryGetResponse.GetStatusCode() == 200); + Assert.IsInstanceOfType(customDictionaryGetResponse, typeof(Response)); + Assert.IsTrue(customDictionaryGetResponse.GetResponse().ContainsKey("customDictionary")); + + Response customDictionaryEditResponse = _client.CustomDictionaryUpdate( + new Dictionary + { + { "code", $"customdict{guid}" }, + { "name", $"CustomDict-{guid}Edited"}, + { + "elements", + new List + { + new Dictionary + { + { "code", $"customdictelement-{fuid}" }, + { "name", $"CustomDictElement-{fuid}" } + }, + new Dictionary + { + { "code", $"customdictelement-{fuid}1" }, + { "name", $"CustomDictElement-{fuid}1" } + } + } + } + } + ); + + Debug.WriteLine(customDictionaryEditResponse.GetRawResponse()); + Assert.IsTrue(customDictionaryEditResponse.IsSuccessfull()); + Assert.IsTrue(customDictionaryEditResponse.GetStatusCode() == 200); + Assert.IsInstanceOfType(customDictionaryEditResponse, typeof(Response)); + Assert.IsTrue(customDictionaryEditResponse.GetResponse().ContainsKey("code")); + } + } +} diff --git a/RetailcrmUnitTest/V5/IntegrationTest.cs b/RetailcrmUnitTest/V5/IntegrationTest.cs new file mode 100644 index 0000000..c53ca08 --- /dev/null +++ b/RetailcrmUnitTest/V5/IntegrationTest.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V5; + +namespace RetailcrmUnitTest.V5 +{ + [TestClass] + public class IntegrationTest + { + private readonly Client _client; + + public IntegrationTest() + { + var appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void IntegrationsSettingsEditSettingsGet() + { + string uid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.IntegrationsSettingsEdit( + new Dictionary + { + { "code", uid}, + { "name", $"TestIntegration-{uid}"}, + { "active", true}, + { "accountUrl", $"http://{uid}.example.com"}, + { "logo", "https://www.ibm.com/cloud-computing/images/cloud/products/cloud-integration/api-economy-icon.svg"}, + } + ); + + Debug.WriteLine(response.GetRawResponse()); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + + Response responseGet = _client.IntegrationsSettingGet(uid); + + Debug.WriteLine(responseGet.GetRawResponse()); + Assert.IsTrue(responseGet.IsSuccessfull()); + Assert.IsInstanceOfType(responseGet, typeof(Response)); + Assert.IsTrue(responseGet.GetResponse().ContainsKey("success")); + } + } +} diff --git a/RetailcrmUnitTest/V5/NotesTest.cs b/RetailcrmUnitTest/V5/NotesTest.cs new file mode 100644 index 0000000..a3711be --- /dev/null +++ b/RetailcrmUnitTest/V5/NotesTest.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Specialized; +using System.Configuration; +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V5; + +namespace RetailcrmUnitTest.V5 +{ + [TestClass] + public class NotesTest + { + private readonly Client _client; + private readonly NameValueCollection _appSettings; + + public NotesTest() + { + _appSettings = ConfigurationManager.AppSettings; + _client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]); + } + + [TestMethod] + public void NotesCreateDelete() + { + Response responseFiltered = _client.NotesCreate( + new Dictionary + { + { "text", "test task" }, + { "customer", new Dictionary { { "id", "2015" } }}, + { "managerId", _appSettings["manager"]} + } + ); + + Debug.WriteLine(responseFiltered.GetRawResponse()); + Assert.IsTrue(responseFiltered.IsSuccessfull()); + Assert.IsTrue(responseFiltered.GetStatusCode() == 201); + Assert.IsInstanceOfType(responseFiltered, typeof(Response)); + Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("success")); + + Response response = _client.NotesDelete(responseFiltered.GetResponse()["id"].ToString()); + + Debug.WriteLine(response.GetRawResponse()); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void NotesList() + { + DateTime datetime = DateTime.Now; + + Response responseFiltered = _client.NotesList( + new Dictionary + { + { "createdAtFrom", datetime.AddDays(-30).ToString("yyyy-MM-dd HH:mm:ss") } + }, + 2, + 50 + ); + + Debug.WriteLine(responseFiltered.GetRawResponse()); + Assert.IsTrue(responseFiltered.IsSuccessfull()); + Assert.IsTrue(responseFiltered.GetStatusCode() == 200); + Assert.IsInstanceOfType(responseFiltered, typeof(Response)); + Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("notes")); + } + } +} diff --git a/RetailcrmUnitTest/V5/OrdersTest.cs b/RetailcrmUnitTest/V5/OrdersTest.cs index 1b6c607..cfd3fd5 100644 --- a/RetailcrmUnitTest/V5/OrdersTest.cs +++ b/RetailcrmUnitTest/V5/OrdersTest.cs @@ -1,15 +1,14 @@ -using System.Diagnostics; +using System; +using System.Collections.Specialized; +using System.Configuration; +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V5; namespace RetailcrmUnitTest.V5 { - using System; - using System.Collections.Specialized; - using System.Configuration; - using System.Collections.Generic; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Retailcrm; - using Retailcrm.Versions.V5; - [TestClass] public class OrdersTest { diff --git a/RetailcrmUnitTest/V5/PaymentsTest.cs b/RetailcrmUnitTest/V5/PaymentsTest.cs new file mode 100644 index 0000000..ed931b8 --- /dev/null +++ b/RetailcrmUnitTest/V5/PaymentsTest.cs @@ -0,0 +1,83 @@ +using System; +using System.Configuration; +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V5; + +namespace RetailcrmUnitTest.V5 +{ + [TestClass] + public class PaymentsTest + { + private readonly Client _client; + + public PaymentsTest() + { + var appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void PaymentsCreateUpdateDelete() + { + DateTime datetime = DateTime.Now; + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response createResponse = _client.OrdersCreate(new Dictionary + { + {"externalId", guid}, + {"createdAt", datetime.ToString("yyyy-MM-dd HH:mm:ss")}, + {"lastName", "Doe"}, + {"firstName", "John"}, + {"email", "john@example.com"}, + {"phone", "+79999999999"} + }); + + Debug.WriteLine(createResponse.GetRawResponse()); + Assert.IsTrue(createResponse.IsSuccessfull()); + Assert.IsInstanceOfType(createResponse, typeof(Response)); + Assert.IsTrue(createResponse.GetResponse().ContainsKey("id")); + + Response paymentCreateResponse = _client.PaymentsCreate( + new Dictionary + { + { "externalId", guid }, + { "type", "cash" }, + { "comment", "test payment" }, + { "order", new Dictionary { { "id", createResponse.GetResponse()["id"].ToString() } } }, + } + ); + + Debug.WriteLine(paymentCreateResponse.GetRawResponse()); + Assert.IsTrue(paymentCreateResponse.IsSuccessfull()); + Assert.IsTrue(paymentCreateResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(paymentCreateResponse, typeof(Response)); + Assert.IsTrue(paymentCreateResponse.GetResponse().ContainsKey("success")); + + Response paymentUpdateResponse = _client.PaymentsUpdate( + new Dictionary + { + { "id", paymentCreateResponse.GetResponse()["id"].ToString()}, + { "status", "paid"}, + { "paidAt", datetime.ToString("yyyy-MM-dd HH:mm:ss")}, + { "amount", 4000 } + } + ); + + Debug.WriteLine(paymentUpdateResponse.GetRawResponse()); + Assert.IsTrue(paymentUpdateResponse.IsSuccessfull()); + Assert.IsInstanceOfType(paymentUpdateResponse, typeof(Response)); + Assert.IsTrue(paymentUpdateResponse.GetResponse().ContainsKey("success")); + + Response response = _client.PaymentsDelete(paymentCreateResponse.GetResponse()["id"].ToString()); + + Debug.WriteLine(response.GetRawResponse()); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + } +} diff --git a/RetailcrmUnitTest/V5/ReferencesTest.cs b/RetailcrmUnitTest/V5/ReferencesTest.cs index 05f4f47..662a87d 100644 --- a/RetailcrmUnitTest/V5/ReferencesTest.cs +++ b/RetailcrmUnitTest/V5/ReferencesTest.cs @@ -1,11 +1,14 @@ -namespace RetailcrmUnitTest.V5 -{ - using System.Collections.Specialized; - using System.Configuration; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Retailcrm; - using Retailcrm.Versions.V5; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V5; +namespace RetailcrmUnitTest.V5 +{ [TestClass] public class ReferencesTest { @@ -26,5 +29,105 @@ Assert.IsInstanceOfType(response, typeof(Response)); Assert.IsTrue(response.GetResponse().ContainsKey("costGroups")); } + + [TestMethod] + public void CostItems() + { + Response response = _client.CostItems(); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("costItems")); + } + + [TestMethod] + public void LegalEntities() + { + Response response = _client.LegalEntities(); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("legalEntities")); + } + + [TestMethod] + public void CostGroupsEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.CostGroupsEdit( + new Dictionary + { + { "code", guid}, + { "name", $"TestCostGroup-{guid}" }, + { "color", "#da5c98" } + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void CostItemsEdit() + { + string groupGuid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response groupResponse = _client.CostGroupsEdit( + new Dictionary + { + { "code", groupGuid}, + { "name", $"TestCostGroup-{groupGuid}" }, + { "color", "#60b29a" } + } + ); + + Assert.IsTrue(groupResponse.IsSuccessfull()); + Assert.IsTrue(groupResponse.GetStatusCode() == 200 || groupResponse.GetStatusCode() == 201); + Assert.IsInstanceOfType(groupResponse, typeof(Response)); + Assert.IsTrue(groupResponse.GetResponse().ContainsKey("success")); + + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.CostItemsEdit( + new Dictionary + { + { "code", guid}, + { "group", groupGuid }, + { "name", $"TestCostItem-{guid}" }, + { "type", "const" } + } + ); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void LegalEntitiesEdit() + { + string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6); + + Response response = _client.LegalEntitiesEdit( + new Dictionary + { + { "code", guid}, + { "legalName", $"Test LegalEntity-{guid}" }, + { "contragentType", "legal-entity"}, + { "countryIso", "RU"} + } + ); + + Debug.WriteLine(response.GetRawResponse()); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } } } diff --git a/RetailcrmUnitTest/V5/SegmentsTest.cs b/RetailcrmUnitTest/V5/SegmentsTest.cs new file mode 100644 index 0000000..713b009 --- /dev/null +++ b/RetailcrmUnitTest/V5/SegmentsTest.cs @@ -0,0 +1,39 @@ +using System.Collections.Specialized; +using System.Configuration; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V5; + +namespace RetailcrmUnitTest.V5 +{ + [TestClass] + public class SegmentsTest + { + private readonly Client _client; + + public SegmentsTest() + { + NameValueCollection appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void Segments() + { + Response responseFiltered = _client.Segments( + new Dictionary + { + { "active", "1" } + }, + 2, + 50 + ); + + Assert.IsTrue(responseFiltered.IsSuccessfull()); + Assert.IsTrue(responseFiltered.GetStatusCode() == 200); + Assert.IsInstanceOfType(responseFiltered, typeof(Response)); + Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("segments")); + } + } +} diff --git a/RetailcrmUnitTest/V5/TasksTest.cs b/RetailcrmUnitTest/V5/TasksTest.cs new file mode 100644 index 0000000..f13e78d --- /dev/null +++ b/RetailcrmUnitTest/V5/TasksTest.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Specialized; +using System.Configuration; +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V5; + +namespace RetailcrmUnitTest.V5 +{ + [TestClass] + public class TasksTest + { + private readonly Client _client; + private readonly NameValueCollection _appSettings; + + public TasksTest() + { + _appSettings = ConfigurationManager.AppSettings; + _client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]); + } + + [TestMethod] + public void TasksCreateUpdateGet() + { + DateTime datetime = DateTime.Now; + + Response responseFiltered = _client.TasksCreate( + new Dictionary + { + { "text", "test task" }, + { "commentary", "test commentary"}, + { "datetime", datetime.AddHours(+3).ToString("yyyy-MM-dd HH:mm")}, + { "performerId", _appSettings["manager"]} + } + ); + + Debug.WriteLine(responseFiltered.GetRawResponse()); + Assert.IsTrue(responseFiltered.IsSuccessfull()); + Assert.IsTrue(responseFiltered.GetStatusCode() == 201); + Assert.IsInstanceOfType(responseFiltered, typeof(Response)); + Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("success")); + + Response response = _client.TasksUpdate( + new Dictionary + { + { "id", responseFiltered.GetResponse()["id"].ToString()}, + { "text", "test task edited" }, + { "commentary", "test commentary"}, + { "datetime", datetime.AddHours(+4).ToString("yyyy-MM-dd HH:mm")}, + { "performerId", _appSettings["manager"]} + } + ); + + Debug.WriteLine(response.GetRawResponse()); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + + Response responseGet = _client.TasksGet(responseFiltered.GetResponse()["id"].ToString()); + + Debug.WriteLine(responseGet.GetRawResponse()); + Assert.IsTrue(responseGet.IsSuccessfull()); + Assert.IsTrue(responseGet.GetStatusCode() == 200); + Assert.IsInstanceOfType(responseGet, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("success")); + } + + [TestMethod] + public void TasksList() + { + Response responseFiltered = _client.TasksList( + new Dictionary + { + { "performers", new List { _appSettings["manager"] } }, + { "status", "performing" } + }, + 2, + 50 + ); + + Debug.WriteLine(responseFiltered.GetRawResponse()); + Assert.IsTrue(responseFiltered.IsSuccessfull()); + Assert.IsTrue(responseFiltered.GetStatusCode() == 200); + Assert.IsInstanceOfType(responseFiltered, typeof(Response)); + Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("tasks")); + } + } +} diff --git a/RetailcrmUnitTest/V5/TelephonyTest.cs b/RetailcrmUnitTest/V5/TelephonyTest.cs new file mode 100644 index 0000000..9a962da --- /dev/null +++ b/RetailcrmUnitTest/V5/TelephonyTest.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm.Versions.V5; + +namespace RetailcrmUnitTest.V5 +{ + [TestClass] + public class TelephonyTest + { + private readonly Client _client; + private readonly NameValueCollection _appSettings; + + public TelephonyTest() + { + _appSettings = ConfigurationManager.AppSettings; + _client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentException), "This method is unavailable in API V5")] + public void TelephonySettingsGetArgumentExeption() + { + _client.TelephonySettingsGet("anycode"); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentException), "This method is unavailable in API V5")] + public void TelephonySettingsGetTelephonySettingsEditArgumentExeption() + { + _client.TelephonySettingsEdit(new Dictionary()); + } + } +} diff --git a/RetailcrmUnitTest/V5/UsersTest.cs b/RetailcrmUnitTest/V5/UsersTest.cs new file mode 100644 index 0000000..18fc7ce --- /dev/null +++ b/RetailcrmUnitTest/V5/UsersTest.cs @@ -0,0 +1,43 @@ +using System.Collections.Specialized; +using System.Configuration; +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Retailcrm; +using Retailcrm.Versions.V5; + +namespace RetailcrmUnitTest.V5 +{ + [TestClass] + public class UsersTest + { + private readonly Client _client; + + public UsersTest() + { + NameValueCollection appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void UsersStatus() + { + Response users = _client.Users(); + Assert.IsTrue(users.IsSuccessfull()); + Assert.IsTrue(users.GetStatusCode() == 200); + Assert.IsInstanceOfType(users, typeof(Response)); + Assert.IsTrue(users.GetResponse().ContainsKey("success")); + + object[] list = (object[])users.GetResponse()["users"]; + var user = list[0] as Dictionary; + Debug.Assert(user != null, nameof(user) + " != null"); + int uid = int.Parse(user["id"].ToString()); + + Response status = _client.UsersStatus(uid, "break"); + Assert.IsTrue(status.IsSuccessfull()); + Assert.IsTrue(status.GetStatusCode() == 200); + Assert.IsInstanceOfType(status, typeof(Response)); + Assert.IsTrue(status.GetResponse().ContainsKey("success")); + } + } +}