diff --git a/Retailcrm/Versions/V5/References.cs b/Retailcrm/Versions/V5/References.cs index 2a724cf..9a23f47 100644 --- a/Retailcrm/Versions/V5/References.cs +++ b/Retailcrm/Versions/V5/References.cs @@ -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 { @@ -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 { @@ -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 { @@ -153,5 +153,42 @@ namespace Retailcrm.Versions.V5 } ); } + + public Response Couriers() + { + return Request.MakeRequest( + "/reference/couriers", + Request.MethodGet + ); + } + + public Response CouriersCreate(Dictionary courier) + { + return Request.MakeRequest( + "/reference/couriers/create", + Request.MethodPost, + new Dictionary + { + { "courier", new JavaScriptSerializer().Serialize(courier) } + } + ); + } + + public Response CouriersEdit(Dictionary courier) + { + if (!courier.ContainsKey("id")) + { + throw new ArgumentException("Parameter `id` is missing"); + } + + return Request.MakeRequest( + $"/reference/couriers/{courier["id"]}/edit", + Request.MethodPost, + new Dictionary + { + { "courier", new JavaScriptSerializer().Serialize(courier) } + } + ); + } } } diff --git a/RetailcrmUnitTest/V5/ReferencesTest.cs b/RetailcrmUnitTest/V5/ReferencesTest.cs index 662a87d..1a9ba72 100644 --- a/RetailcrmUnitTest/V5/ReferencesTest.cs +++ b/RetailcrmUnitTest/V5/ReferencesTest.cs @@ -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 + { + { "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 + { + { "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 + { + { "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")); + } } }