From defcfac7940345d806ae6627c6c89c7277609574 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Tue, 3 Oct 2017 18:05:44 +0300 Subject: [PATCH] minor update in customers & orders methods for V3, add store methods --- Retailcrm/Retailcrm.csproj | 1 + Retailcrm/Versions/V3/Customer.cs | 2 +- Retailcrm/Versions/V3/Orders.cs | 2 +- Retailcrm/Versions/V3/Store.cs | 56 +++++++++++ RetailcrmUnitTest/RetailcrmUnitTest.csproj | 1 + RetailcrmUnitTest/V3/CustomersTest.cs | 2 +- RetailcrmUnitTest/V3/OrdersTest.cs | 2 +- RetailcrmUnitTest/V3/StoreTest.cs | 104 +++++++++++++++++++++ 8 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 Retailcrm/Versions/V3/Store.cs create mode 100644 RetailcrmUnitTest/V3/StoreTest.cs diff --git a/Retailcrm/Retailcrm.csproj b/Retailcrm/Retailcrm.csproj index a6ae6f5..b65922f 100644 --- a/Retailcrm/Retailcrm.csproj +++ b/Retailcrm/Retailcrm.csproj @@ -52,6 +52,7 @@ + diff --git a/Retailcrm/Versions/V3/Customer.cs b/Retailcrm/Versions/V3/Customer.cs index e175135..9ea59b8 100644 --- a/Retailcrm/Versions/V3/Customer.cs +++ b/Retailcrm/Versions/V3/Customer.cs @@ -115,7 +115,7 @@ if (customers.Count > 50) { - throw new ArgumentException("Parameter `customers` must contain less or 50 records"); + throw new ArgumentException("Parameter `customers` must contain 50 or less records"); } return _request.MakeRequest( diff --git a/Retailcrm/Versions/V3/Orders.cs b/Retailcrm/Versions/V3/Orders.cs index b047cce..0b625ab 100644 --- a/Retailcrm/Versions/V3/Orders.cs +++ b/Retailcrm/Versions/V3/Orders.cs @@ -183,7 +183,7 @@ if (orders.Count > 50) { - throw new ArgumentException("Parameter `orders` must contain less or 50 records"); + throw new ArgumentException("Parameter `orders` must contain 50 or less records"); } return _request.MakeRequest( diff --git a/Retailcrm/Versions/V3/Store.cs b/Retailcrm/Versions/V3/Store.cs new file mode 100644 index 0000000..549783d --- /dev/null +++ b/Retailcrm/Versions/V3/Store.cs @@ -0,0 +1,56 @@ +namespace Retailcrm.Versions.V3 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response StoreInventoriesGet(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter != null && filter.Count > 0) + { + parameters.Add("filter", filter); + } + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return _request.MakeRequest("/store/inventories", Request.MethodGet, parameters); + } + + public Response StoreInventoriesUpload(List offers, string site = "") + { + if (offers.Count< 1) + { + throw new ArgumentException("Parameter `offers` must contains a data"); + } + + if (offers.Count > 250) + { + throw new ArgumentException("Parameter `offers` must contain 250 or less records"); + } + + return _request.MakeRequest( + "/store/inventories/upload", + Request.MethodPost, + FillSite( + site, + new Dictionary + { + { "offers", new JavaScriptSerializer().Serialize(offers) } + } + ) + ); + } + } +} diff --git a/RetailcrmUnitTest/RetailcrmUnitTest.csproj b/RetailcrmUnitTest/RetailcrmUnitTest.csproj index 4e9d20e..361a45f 100644 --- a/RetailcrmUnitTest/RetailcrmUnitTest.csproj +++ b/RetailcrmUnitTest/RetailcrmUnitTest.csproj @@ -58,6 +58,7 @@ + diff --git a/RetailcrmUnitTest/V3/CustomersTest.cs b/RetailcrmUnitTest/V3/CustomersTest.cs index 6380d28..3d13e9b 100644 --- a/RetailcrmUnitTest/V3/CustomersTest.cs +++ b/RetailcrmUnitTest/V3/CustomersTest.cs @@ -185,7 +185,7 @@ } [TestMethod] - [ExpectedException(typeof(ArgumentException), "Parameter `customers` must contains a data")] + [ExpectedException(typeof(ArgumentException), "Parameter `customers` must contain 50 or less records")] public void CustomersUploadLimitArgumentExeption() { List customers = new List(); diff --git a/RetailcrmUnitTest/V3/OrdersTest.cs b/RetailcrmUnitTest/V3/OrdersTest.cs index 5749826..6074bb5 100644 --- a/RetailcrmUnitTest/V3/OrdersTest.cs +++ b/RetailcrmUnitTest/V3/OrdersTest.cs @@ -276,7 +276,7 @@ } [TestMethod] - [ExpectedException(typeof(ArgumentException), "Parameter `orders` must contains a data")] + [ExpectedException(typeof(ArgumentException), "Parameter `orders` must contain 50 or less records")] public void OrdersUploadLimitArgumentExeption() { List orders = new List(); diff --git a/RetailcrmUnitTest/V3/StoreTest.cs b/RetailcrmUnitTest/V3/StoreTest.cs new file mode 100644 index 0000000..02b1b52 --- /dev/null +++ b/RetailcrmUnitTest/V3/StoreTest.cs @@ -0,0 +1,104 @@ +using System.Diagnostics; + +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 StoreTest + { + private readonly Client _client; + private readonly NameValueCollection _appSettings; + + public StoreTest() + { + _appSettings = ConfigurationManager.AppSettings; + _client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"], _appSettings["site"]); + } + + [TestMethod] + public void InventoriesUpload() + { + List offers = new List + { + new Dictionary + { + { "xmlId", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)}, + { "stores", new List + { + new Dictionary + { + { "code", _appSettings["store"] }, + { "available", 500 }, + { "purchasePrice", 300} + } + } + } + }, + new Dictionary + { + { "xmlId", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)}, + { "stores", new List + { + new Dictionary + { + { "code", _appSettings["store"] }, + { "available", 600 }, + { "purchasePrice", 350} + } + } + } + }, + new Dictionary + { + { "xmlId", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)}, + { "stores", new List + { + new Dictionary + { + { "code", _appSettings["store"] }, + { "available", 700 }, + { "purchasePrice", 400} + } + } + } + } + }; + + Response response = _client.StoreInventoriesUpload(offers); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("processedOffersCount")); + + Debug.WriteLine(response.GetRawResponse()); + } + + [TestMethod] + public void Inventories() + { + Dictionary filter = new Dictionary + { + { "site", _appSettings["site"]}, + { "details", 1} + }; + + Response response = _client.StoreInventoriesGet(filter, 1, 50); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("offers")); + + Debug.WriteLine(response.GetRawResponse()); + } + } +}