Update test classes, add packs & statistic methods

This commit is contained in:
Alex Lushpai 2017-10-03 16:01:29 +03:00
parent 0ca69b2e53
commit e201d82166
8 changed files with 345 additions and 2 deletions

View file

@ -47,6 +47,7 @@
<Compile Include="QueryStringBuilder.cs" />
<Compile Include="Request.cs" />
<Compile Include="Response.cs" />
<Compile Include="Versions\V3\Statistic.cs" />
<Compile Include="Versions\V3\Client.cs" />
<Compile Include="Versions\V3\Orders.cs" />
<Compile Include="Versions\V3\Customer.cs" />

View file

@ -6,5 +6,108 @@
public partial class Client
{
public Response PacksList(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("/orders/packs", Request.MethodGet, parameters);
}
public Response PacksCreate(Dictionary<string, object> pack)
{
if (pack.Count < 1)
{
throw new ArgumentException("Parameter `pack` must contains a data");
}
return _request.MakeRequest(
"/orders/packs/create",
Request.MethodPost,
new Dictionary<string, object>
{
{ "pack", new JavaScriptSerializer().Serialize(pack) }
}
);
}
public Response PacksUpdate(Dictionary<string, object> pack)
{
if (pack.Count < 1)
{
throw new ArgumentException("Parameter `pack` must contains a data");
}
if (!pack.ContainsKey("id"))
{
throw new ArgumentException("Parameter `pack` must contains an id");
}
return _request.MakeRequest(
$"/orders/packs/{pack["id"].ToString()}/edit",
Request.MethodPost,
new Dictionary<string, object>
{
{ "pack", new JavaScriptSerializer().Serialize(pack) }
}
);
}
public Response PacksDelete(string id)
{
if (id.Length < 1)
{
throw new ArgumentException("Parameter `id` must contains a data");
}
return _request.MakeRequest(
$"/orders/packs/{id}/delete",
Request.MethodPost
);
}
public Response PacksGet(string id)
{
return _request.MakeRequest(
$"/orders/packs/{id}",
Request.MethodGet
);
}
public Response PacksHistory(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
if (filter != null && filter.Count > 0)
{
parameters.Add("filter", filter);
}
if (page > 1)
{
parameters.Add("page", page);
}
if (limit > 0)
{
parameters.Add("limit", limit);
}
return _request.MakeRequest("/orders/packs/history", Request.MethodGet, parameters);
}
}
}

View file

@ -0,0 +1,13 @@
namespace Retailcrm.Versions.V3
{
public partial class Client
{
public Response StatisticUpdate()
{
return _request.MakeRequest(
"/statistic/update",
Request.MethodGet
);
}
}
}

View file

@ -3,5 +3,6 @@
<appSettings>
<add key="apiUrl" value="https://example.retailcrm.ru"/>
<add key="apiKey" value="BBBBBBBBBBBBBBBBBBBBBBBBBBBB"/>
<add key="site" value="default"/>
</appSettings>
</configuration>

View file

@ -53,9 +53,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApiTest.cs" />
<Compile Include="V3\ClientTest.cs" />
<Compile Include="V3\CustomersTest.cs" />
<Compile Include="V3\OrdersTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="V3\PacksTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

View file

@ -0,0 +1,42 @@
namespace RetailcrmUnitTest.V3
{
using System.Collections.Specialized;
using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Retailcrm;
using Retailcrm.Versions.V3;
[TestClass]
public class ClientTest
{
private readonly Client _client;
public ClientTest()
{
NameValueCollection appSettings = ConfigurationManager.AppSettings;
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"], appSettings["site"]);
}
[TestMethod]
public void InitTest()
{
Assert.IsInstanceOfType(_client, typeof(Client));
string siteCode = "default";
_client.SetSite(siteCode);
Assert.AreEqual(_client.GetSite(), siteCode);
}
[TestMethod]
public void StatisticUpdate()
{
Response response = _client.StatisticUpdate();
Assert.IsTrue(response.IsSuccessfull());
Assert.IsInstanceOfType(response, typeof(Response));
Assert.IsTrue(response.GetStatusCode() == 200);
}
}
}

View file

@ -12,11 +12,12 @@
public class CustomersTest
{
private readonly Client _client;
private readonly NameValueCollection _appSettings;
public CustomersTest()
{
NameValueCollection appSettings = ConfigurationManager.AppSettings;
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
_appSettings = ConfigurationManager.AppSettings;
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]);
}
[TestMethod]
@ -101,6 +102,8 @@
[TestMethod]
public void CustomersList()
{
_client.SetSite(_appSettings["site"]);
Response response = _client.CustomersList();
Assert.IsTrue(response.IsSuccessfull());

View file

@ -0,0 +1,178 @@
using System.Globalization;
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
{
private readonly Client _client;
private readonly NameValueCollection _appSettings;
public PacksTest()
{
_appSettings = ConfigurationManager.AppSettings;
_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()
{
string uid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12);
Dictionary<string, object> order = new Dictionary<string, object>
{
{ "number", $"packs-test-{uid}" },
{ "firstName", $"John_{uid}" },
{ "lastName", $"Doe_{uid}"},
{ "email", $"{uid}@example.com"},
{
"items", new List<object>
{
new Dictionary<string, object>
{
{ "initialPrice", 500 },
{ "quantity", 2},
{ "productId", "_jAjMfjjgs6ukFxOiTE433"},
{ "productName", "Test"}
}
}
}
};
Response orderCreateResponse = _client.OrdersCreate(order);
Assert.IsTrue(orderCreateResponse.IsSuccessfull());
Assert.IsTrue(orderCreateResponse.GetStatusCode() == 201);
Assert.IsInstanceOfType(orderCreateResponse, typeof(Response));
Assert.IsTrue(orderCreateResponse.GetResponse().ContainsKey("id"));
Response orderGetResponse = _client.OrdersGet(orderCreateResponse.GetResponse()["id"].ToString(), "id");
Assert.IsTrue(orderGetResponse.IsSuccessfull());
Assert.IsTrue(orderGetResponse.GetStatusCode() == 200);
Assert.IsInstanceOfType(orderGetResponse, typeof(Response));
Assert.IsTrue(orderGetResponse.GetResponse().ContainsKey("order"));
Dictionary<string, object> orderFromResponse =
(Dictionary<string, object>) orderGetResponse.GetResponse()["order"];
object[] arr = (object[])orderFromResponse["items"];
int[] id = new int[1];
foreach (Dictionary<string, object> s in arr.OfType<Dictionary<string, object>>())
{
int itemId;
int.TryParse(s["id"].ToString(), NumberStyles.Any, null, out itemId);
id[0] = itemId;
}
Dictionary<string, object> pack = new Dictionary<string, object>
{
{ "purchasePrice", 100 },
{ "quantity", 1},
{ "store", _appSettings["store"]},
{ "itemId", id[0]}
};
Response packsCreateResponse = _client.PacksCreate(pack);
Assert.IsTrue(packsCreateResponse.IsSuccessfull());
Assert.IsTrue(packsCreateResponse.GetStatusCode() == 201);
Assert.IsInstanceOfType(packsCreateResponse, typeof(Response));
Assert.IsTrue(packsCreateResponse.GetResponse().ContainsKey("id"));
string packId = packsCreateResponse.GetResponse()["id"].ToString();
Dictionary<string, object> packEdit = new Dictionary<string, object>
{
{ "id", packId },
{ "quantity", 2}
};
Response packsUpdateResponse = _client.PacksUpdate(packEdit);
Assert.IsTrue(packsUpdateResponse.IsSuccessfull());
Assert.IsTrue(packsUpdateResponse.GetStatusCode() == 200);
Assert.IsInstanceOfType(packsUpdateResponse, typeof(Response));
Assert.IsTrue(packsUpdateResponse.GetResponse().ContainsKey("id"));
Response packsGetResponse = _client.PacksGet(packId);
Assert.IsTrue(packsGetResponse.IsSuccessfull());
Assert.IsTrue(packsGetResponse.GetStatusCode() == 200);
Assert.IsInstanceOfType(packsGetResponse, typeof(Response));
Assert.IsTrue(packsGetResponse.GetResponse().ContainsKey("pack"));
Response packsDeleteResponse = _client.PacksGet(packId);
Assert.IsTrue(packsDeleteResponse.IsSuccessfull());
Assert.IsTrue(packsDeleteResponse.GetStatusCode() == 200);
Assert.IsInstanceOfType(packsDeleteResponse, typeof(Response));
}
[TestMethod]
public void PacksList()
{
Dictionary<string, object> filter = new Dictionary<string, object>
{
{ "store", _appSettings["store"]}
};
Response response = _client.PacksList(filter, 1, 100);
Assert.IsTrue(response.IsSuccessfull());
Assert.IsTrue(response.GetStatusCode() == 200);
Assert.IsInstanceOfType(response, typeof(Response));
Assert.IsTrue(response.GetResponse().ContainsKey("packs"));
}
[TestMethod]
public void PacksHistory()
{
Dictionary<string, object> filter = new Dictionary<string, object>
{
{ "endDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
};
Response response = _client.PacksHistory(filter, 1, 100);
Assert.IsTrue(response.IsSuccessfull());
Assert.IsTrue(response.GetStatusCode() == 200);
Assert.IsInstanceOfType(response, typeof(Response));
Assert.IsTrue(response.GetResponse().ContainsKey("history"));
}
}
}