From 7ca29590c85a69db03503b741986997a1ea6637c Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 21 Mar 2018 18:10:57 +0300 Subject: [PATCH 1/3] update packages, setup VSTS build --- README.md | 1 + Retailcrm/Versions/V5/References.cs | 14 ++++++++++++++ RetailcrmUnitTest/RetailcrmUnitTest.csproj | 20 +++++++++----------- RetailcrmUnitTest/V4/StoresTest.cs | 2 -- RetailcrmUnitTest/packages.config | 4 ++-- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f115734..d6012b4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +![Visual Studio Team services](https://img.shields.io/vso/build/gwinn/f01d2ec1-f511-4908-8c02-d48757d71370/3.svg?style=flat-square [![NuGet](https://img.shields.io/nuget/v/Retailcrm.SDK.svg)](https://www.nuget.org/packages/Retailcrm.SDK/) diff --git a/Retailcrm/Versions/V5/References.cs b/Retailcrm/Versions/V5/References.cs index 9a23f47..fd5a5d3 100644 --- a/Retailcrm/Versions/V5/References.cs +++ b/Retailcrm/Versions/V5/References.cs @@ -154,6 +154,10 @@ namespace Retailcrm.Versions.V5 ); } + /// + /// Couriers list + /// + /// public Response Couriers() { return Request.MakeRequest( @@ -162,6 +166,11 @@ namespace Retailcrm.Versions.V5 ); } + /// + /// Create a courier + /// + /// + /// public Response CouriersCreate(Dictionary courier) { return Request.MakeRequest( @@ -174,6 +183,11 @@ namespace Retailcrm.Versions.V5 ); } + /// + /// Edit a courier + /// + /// + /// public Response CouriersEdit(Dictionary courier) { if (!courier.ContainsKey("id")) diff --git a/RetailcrmUnitTest/RetailcrmUnitTest.csproj b/RetailcrmUnitTest/RetailcrmUnitTest.csproj index d6132f2..da35e67 100644 --- a/RetailcrmUnitTest/RetailcrmUnitTest.csproj +++ b/RetailcrmUnitTest/RetailcrmUnitTest.csproj @@ -1,6 +1,6 @@  - + Debug AnyCPU @@ -39,10 +39,10 @@ - ..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll @@ -80,25 +80,23 @@ - - - Designer - - {9c378ef4-9f9b-4214-a9aa-1fc3c44edb41} Retailcrm + + + Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}. - - + + - + \ No newline at end of file diff --git a/RetailcrmUnitTest/V4/StoresTest.cs b/RetailcrmUnitTest/V4/StoresTest.cs index fd98a7f..5bddc64 100644 --- a/RetailcrmUnitTest/V4/StoresTest.cs +++ b/RetailcrmUnitTest/V4/StoresTest.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Specialized; using Microsoft.VisualStudio.TestTools.UnitTesting; using Retailcrm; using Retailcrm.Versions.V4; @@ -10,7 +9,6 @@ namespace RetailcrmUnitTest.V4 public class StoresTest { private readonly Client _client; - private readonly NameValueCollection _appSettings; public StoresTest() { diff --git a/RetailcrmUnitTest/packages.config b/RetailcrmUnitTest/packages.config index fc2bbdd..03805ce 100644 --- a/RetailcrmUnitTest/packages.config +++ b/RetailcrmUnitTest/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file From 2bfeac24e8885a66673cfa14fc5ad7c84c22f778 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 21 Mar 2018 18:13:15 +0300 Subject: [PATCH 2/3] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6012b4..019ea17 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Visual Studio Team services](https://img.shields.io/vso/build/gwinn/f01d2ec1-f511-4908-8c02-d48757d71370/3.svg?style=flat-square +[![Visual Studio Team services](https://img.shields.io/vso/build/gwinn/f01d2ec1-f511-4908-8c02-d48757d71370/3.svg?style=flat-square)](https://visualstudio.com) [![NuGet](https://img.shields.io/nuget/v/Retailcrm.SDK.svg)](https://www.nuget.org/packages/Retailcrm.SDK/) From c6b1050d04eb932ce2a146c920581e5882bded9a Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 28 Jan 2019 22:14:50 +0300 Subject: [PATCH 3/3] fix big data urlencode --- Retailcrm/Properties/AssemblyInfo.cs | 4 +- Retailcrm/QueryBuilder.cs | 5 +- Retailcrm/Request.cs | 2 - Retailcrm/Retailcrm.csproj | 1 + Retailcrm/Retailcrm.nuspec | 18 ++-- RetailcrmUnitTest/ApiTest.cs | 4 +- RetailcrmUnitTest/RetailcrmUnitTest.csproj | 12 +-- RetailcrmUnitTest/V3/OrdersTest.cs | 2 - RetailcrmUnitTest/V4/OrdersTest.cs | 108 +++++++++++++++++++++ RetailcrmUnitTest/packages.config | 4 +- 10 files changed, 132 insertions(+), 28 deletions(-) diff --git a/Retailcrm/Properties/AssemblyInfo.cs b/Retailcrm/Properties/AssemblyInfo.cs index 30a418d..1bd10a6 100644 --- a/Retailcrm/Properties/AssemblyInfo.cs +++ b/Retailcrm/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ using System.Runtime.InteropServices; // набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения, // связанные со сборкой. [assembly: AssemblyTitle("Retailcrm.SDK")] -[assembly: AssemblyDescription("Multiversion API client for RetailCRM")] +[assembly: AssemblyDescription("Multiversion API client for retailCRM")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("RetailDriver LLC")] [assembly: AssemblyProduct("Retailcrm.SDK")] -[assembly: AssemblyCopyright("Copyright © RetailDriver LLC 2017")] +[assembly: AssemblyCopyright("Copyright © RetailDriver LLC 2019")] [assembly: AssemblyTrademark("RetailDriver LLC")] [assembly: AssemblyCulture("")] diff --git a/Retailcrm/QueryBuilder.cs b/Retailcrm/QueryBuilder.cs index 0f8fa0e..165ed10 100644 --- a/Retailcrm/QueryBuilder.cs +++ b/Retailcrm/QueryBuilder.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Web; namespace Retailcrm { @@ -37,8 +38,8 @@ namespace Retailcrm return String.Join(argSeperator, _keyValuePairs.Select(kvp => { - var key = Uri.EscapeDataString(kvp.Key); - var value = Uri.EscapeDataString(kvp.Value.ToString()); + var key = HttpUtility.UrlEncode(kvp.Key); + var value = HttpUtility.UrlEncode(kvp.Value.ToString()); return $"{key}={value}"; })); } diff --git a/Retailcrm/Request.cs b/Retailcrm/Request.cs index 403b472..7b7492a 100644 --- a/Retailcrm/Request.cs +++ b/Retailcrm/Request.cs @@ -77,7 +77,6 @@ namespace Retailcrm } Exception exception = null; - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(path); request.Method = method; @@ -112,7 +111,6 @@ namespace Retailcrm throw new WebException(exception.ToString(), exception); } - // ReSharper disable once AssignNullToNotNullAttribute StreamReader reader = new StreamReader(response.GetResponseStream()); string responseBody = reader.ReadToEnd(); int statusCode = (int)response.StatusCode; diff --git a/Retailcrm/Retailcrm.csproj b/Retailcrm/Retailcrm.csproj index 00071af..2e23b14 100644 --- a/Retailcrm/Retailcrm.csproj +++ b/Retailcrm/Retailcrm.csproj @@ -34,6 +34,7 @@ + diff --git a/Retailcrm/Retailcrm.nuspec b/Retailcrm/Retailcrm.nuspec index 68d6bef..a2f15f3 100644 --- a/Retailcrm/Retailcrm.nuspec +++ b/Retailcrm/Retailcrm.nuspec @@ -2,17 +2,17 @@ Retailcrm.SDK - 5.1.1 + 5.1.2 $title$ - Retailcrm - Retailcrm - https://opensource.org/licenses/MIT - http://retailcrm.ru - http://www.retailcrm.ru/favicon.ico + retailCRM + retailCRM + MIT + https://retailcrm.ru + https://help.retailcrm.ru/favicon.ico false - Multiversion API client for RetailCRM - Update tests, setup auto builds - Copyright 2017-2018 + Multiversion API client for retailCRM + Fix POST request for big data + Copyright 2017-2019 crm ecommerce retailcrm sdk \ No newline at end of file diff --git a/RetailcrmUnitTest/ApiTest.cs b/RetailcrmUnitTest/ApiTest.cs index d59c744..a3e6352 100644 --- a/RetailcrmUnitTest/ApiTest.cs +++ b/RetailcrmUnitTest/ApiTest.cs @@ -1,6 +1,4 @@ -using System.Collections.Specialized; -using System.Configuration; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Retailcrm; namespace RetailcrmUnitTest diff --git a/RetailcrmUnitTest/RetailcrmUnitTest.csproj b/RetailcrmUnitTest/RetailcrmUnitTest.csproj index da35e67..750ecf1 100644 --- a/RetailcrmUnitTest/RetailcrmUnitTest.csproj +++ b/RetailcrmUnitTest/RetailcrmUnitTest.csproj @@ -1,6 +1,6 @@  - + Debug AnyCPU @@ -39,10 +39,10 @@ - ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll @@ -95,8 +95,8 @@ Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}. - - + + - + \ No newline at end of file diff --git a/RetailcrmUnitTest/V3/OrdersTest.cs b/RetailcrmUnitTest/V3/OrdersTest.cs index bbc307c..2125370 100644 --- a/RetailcrmUnitTest/V3/OrdersTest.cs +++ b/RetailcrmUnitTest/V3/OrdersTest.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; -using System.Configuration; using Microsoft.VisualStudio.TestTools.UnitTesting; using Retailcrm; using Retailcrm.Versions.V3; diff --git a/RetailcrmUnitTest/V4/OrdersTest.cs b/RetailcrmUnitTest/V4/OrdersTest.cs index b28ce04..a4b1af5 100644 --- a/RetailcrmUnitTest/V4/OrdersTest.cs +++ b/RetailcrmUnitTest/V4/OrdersTest.cs @@ -37,5 +37,113 @@ namespace RetailcrmUnitTest.V4 Assert.IsInstanceOfType(response, typeof(Response)); Assert.IsTrue(response.GetResponse().ContainsKey("history")); } + + [TestMethod] + public void BigOrderCreateUpdate() + { + long epochTicks = new DateTime(1970, 1, 1).Ticks; + long unixTime = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond); + + List> items = new List>(); + Dictionary properties = new Dictionary(); + + for (int j = 0; j < 10; j++) + { + properties.Add( + $"property_{j}", + new Dictionary { + { "name", $"Property_{j}" }, + { "code", $"property_{j}" }, + { "value", $"{Guid.NewGuid().ToString()}" }, + } + ); + } + + for (int i = 0; i < 100; i++) { + Dictionary item = new Dictionary { + { "initialPrice", i + 100 }, + { "purchasePrice", i + 90 }, + { "productName", $"Product_{i}" }, + { "quantity", 2 }, + { + "offer", + new Dictionary { + { "name", $"Product_{i}" }, + { "xmlId", $"{Guid.NewGuid().ToString()}" } + } + }, + { "properties", properties } + }; + + items.Add(item); + } + + Dictionary order = new Dictionary + { + {"number", unixTime}, + {"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + {"lastName", "Doe"}, + {"firstName", "John"}, + {"email", "john@example.com"}, + {"phone", "+79999999999"}, + {"items", items}, + { + "delivery", + new Dictionary { + { "code", "self-delivery" }, + { "cost", "300" }, + { + "address", new Dictionary { + { "city", "Москва" }, + { "street", "Ярославская" }, + { "building", "10" }, + { "flat", "2" }, + } + } + } + } + }; + + Response createResponse = _client.OrdersCreate(order); + + Assert.IsTrue(createResponse.IsSuccessfull()); + Assert.IsInstanceOfType(createResponse, typeof(Response)); + Assert.AreEqual(createResponse.GetStatusCode(), 201); + Assert.IsTrue(createResponse.GetResponse().ContainsKey("id")); + + List> newItems = new List>(); + + for (int i = 0; i < 120; i++) + { + Dictionary item = new Dictionary { + { "initialPrice", i + 100 }, + { "purchasePrice", i + 90 }, + { "productName", $"Product_{i}" }, + { "quantity", 2 }, + { + "offer", + new Dictionary { + { "name", $"Product_{i}" }, + { "xmlId", $"{Guid.NewGuid().ToString()}" } + } + }, + { "properties", properties } + }; + + newItems.Add(item); + } + + Response updateResponse = _client.OrdersUpdate( + new Dictionary { + { "id", createResponse.GetResponse()["id"].ToString()}, + { "items", newItems } + }, + "id" + ); + + Assert.IsTrue(updateResponse.IsSuccessfull()); + Assert.IsInstanceOfType(updateResponse, typeof(Response)); + Assert.AreEqual(updateResponse.GetStatusCode(), 200); + } } } diff --git a/RetailcrmUnitTest/packages.config b/RetailcrmUnitTest/packages.config index 03805ce..06aa648 100644 --- a/RetailcrmUnitTest/packages.config +++ b/RetailcrmUnitTest/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file