Couriers references (#8)

This commit is contained in:
Alex Lushpai 2017-12-21 16:07:54 +03:00 committed by GitHub
parent a75db4fe7f
commit b5261b02b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 115 additions and 3 deletions

View File

@ -65,7 +65,7 @@ namespace Retailcrm.Versions.V5
}
return Request.MakeRequest(
$"/reference/cost-groups/{group["code"].ToString()}/edit",
$"/reference/cost-groups/{@group["code"]}/edit",
Request.MethodPost,
new Dictionary<string, object>
{
@ -108,7 +108,7 @@ namespace Retailcrm.Versions.V5
}
return Request.MakeRequest(
$"/reference/cost-items/{item["code"].ToString()}/edit",
$"/reference/cost-items/{item["code"]}/edit",
Request.MethodPost,
new Dictionary<string, object>
{
@ -145,7 +145,7 @@ namespace Retailcrm.Versions.V5
}
return Request.MakeRequest(
$"/reference/legal-entities/{entity["code"].ToString()}/edit",
$"/reference/legal-entities/{entity["code"]}/edit",
Request.MethodPost,
new Dictionary<string, object>
{
@ -153,5 +153,42 @@ namespace Retailcrm.Versions.V5
}
);
}
public Response Couriers()
{
return Request.MakeRequest(
"/reference/couriers",
Request.MethodGet
);
}
public Response CouriersCreate(Dictionary<string, object> courier)
{
return Request.MakeRequest(
"/reference/couriers/create",
Request.MethodPost,
new Dictionary<string, object>
{
{ "courier", new JavaScriptSerializer().Serialize(courier) }
}
);
}
public Response CouriersEdit(Dictionary<string, object> courier)
{
if (!courier.ContainsKey("id"))
{
throw new ArgumentException("Parameter `id` is missing");
}
return Request.MakeRequest(
$"/reference/couriers/{courier["id"]}/edit",
Request.MethodPost,
new Dictionary<string, object>
{
{ "courier", new JavaScriptSerializer().Serialize(courier) }
}
);
}
}
}

View File

@ -129,5 +129,80 @@ namespace RetailcrmUnitTest.V5
Assert.IsInstanceOfType(response, typeof(Response));
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
}
[TestMethod]
public void Couriers()
{
Response response = _client.Couriers();
Assert.IsTrue(response.IsSuccessfull());
Assert.IsTrue(response.GetStatusCode() == 200);
Assert.IsInstanceOfType(response, typeof(Response));
Assert.IsTrue(response.GetResponse().ContainsKey("couriers"));
}
[TestMethod]
public void CouriersCreate()
{
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 3);
Response response = _client.CouriersCreate(
new Dictionary<string, object>
{
{ "firstName", $"CourierFirstName-{guid}"},
{ "lastName", $"CourierLastName-{guid}" },
{ "active", false},
{ "email", $"{guid}@example.com"}
}
);
Debug.WriteLine(response.GetRawResponse());
Assert.IsTrue(response.IsSuccessfull());
Assert.IsTrue(response.GetStatusCode() == 201);
Assert.IsInstanceOfType(response, typeof(Response));
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
}
[TestMethod]
public void CouriersEdit()
{
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 3);
Response response = _client.CouriersCreate(
new Dictionary<string, object>
{
{ "firstName", $"CourierFirstName-{guid}"},
{ "lastName", $"CourierLastName-{guid}" },
{ "active", false},
{ "email", $"{guid}@example.com"}
}
);
Debug.WriteLine(response.GetRawResponse());
Assert.IsTrue(response.IsSuccessfull());
Assert.IsTrue(response.GetStatusCode() == 201);
Assert.IsInstanceOfType(response, typeof(Response));
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
string id = response.GetResponse()["id"].ToString();
Response responseEdit = _client.CouriersEdit(
new Dictionary<string, object>
{
{ "id", id},
{ "firstName", "CourierFirstName"},
{ "lastName", "CourierLastName" },
{ "active", true}
}
);
Debug.WriteLine(responseEdit.GetRawResponse());
Assert.IsTrue(responseEdit.IsSuccessfull());
Assert.IsTrue(responseEdit.GetStatusCode() == 200);
Assert.IsInstanceOfType(response, typeof(Response));
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
}
}
}