minor update in customers & orders methods for V3, add store methods

This commit is contained in:
Alex Lushpai 2017-10-03 18:05:44 +03:00
parent e201d82166
commit defcfac794
8 changed files with 166 additions and 4 deletions

View file

@ -52,6 +52,7 @@
<Compile Include="Versions\V3\Orders.cs" />
<Compile Include="Versions\V3\Customer.cs" />
<Compile Include="Versions\V3\Packs.cs" />
<Compile Include="Versions\V3\Store.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Versions\V4\" />

View file

@ -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(

View file

@ -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(

View file

@ -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<string, object> filter = null, int page = 0, int limit = 0)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
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<object> 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<string, object>
{
{ "offers", new JavaScriptSerializer().Serialize(offers) }
}
)
);
}
}
}

View file

@ -58,6 +58,7 @@
<Compile Include="V3\OrdersTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="V3\PacksTest.cs" />
<Compile Include="V3\StoreTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

View file

@ -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<object> customers = new List<object>();

View file

@ -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<object> orders = new List<object>();

View file

@ -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<object> offers = new List<object>
{
new Dictionary<string, object>
{
{ "xmlId", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)},
{ "stores", new List<object>
{
new Dictionary<string, object>
{
{ "code", _appSettings["store"] },
{ "available", 500 },
{ "purchasePrice", 300}
}
}
}
},
new Dictionary<string, object>
{
{ "xmlId", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)},
{ "stores", new List<object>
{
new Dictionary<string, object>
{
{ "code", _appSettings["store"] },
{ "available", 600 },
{ "purchasePrice", 350}
}
}
}
},
new Dictionary<string, object>
{
{ "xmlId", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)},
{ "stores", new List<object>
{
new Dictionary<string, object>
{
{ "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<string, object> filter = new Dictionary<string, object>
{
{ "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());
}
}
}