public void ShouldDeleteTemplate() { IRestRequest savedRequest = null; mockClient.Setup(trc => trc.Execute<DeleteResult>(It.IsAny<IRestRequest>())) .Callback<IRestRequest>((request) => savedRequest = request) .Returns(new DeleteResult()); var client = mockClient.Object; var template = new Template() { Id = templateId, Name = templateName, Content = templateContent, }; client.DeleteTemplate(template); mockClient.Verify(trc => trc.Execute<DeleteResult>(It.IsAny<IRestRequest>()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("templates/{id}", savedRequest.Resource); Assert.AreEqual(Method.DELETE, savedRequest.Method); Assert.AreEqual(1, savedRequest.Parameters.Count); Assert.AreEqual(templateId.ToString(), savedRequest.Parameters.Find(x => x.Name == "id").Value); var content = "{}"; var testClient = Common.CreateClient<DeleteResult>(content, null, null); client = new Client(testClient); var result = client.DeleteTemplate(template); Assert.IsTrue(result.Success); }
/// <summary> /// Delete a single template. /// </summary> /// <param name="template">Template object</param> /// <returns></returns> public DeleteResult DeleteTemplate(Template template) { return DeleteTemplate(template.Id); }
public void ShouldUpdateTemplate() { IRestRequest savedRequest = null; mockClient.Setup(trc => trc.Execute<LinkResult>(It.IsAny<IRestRequest>())) .Callback<IRestRequest>((request) => savedRequest = request) .Returns(new LinkResult()); var client = mockClient.Object; var template = new Template() { Id = templateId, Name = templateName, Content = templateContent, }; client.UpdateTemplate(template); mockClient.Verify(trc => trc.Execute<LinkResult>(It.IsAny<IRestRequest>()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("templates/{id}", savedRequest.Resource); Assert.AreEqual(Method.PUT, savedRequest.Method); Assert.AreEqual(3, savedRequest.Parameters.Count); Assert.AreEqual(templateId.ToString(), savedRequest.Parameters.Find(x => x.Name == "id").Value); Assert.AreEqual(templateName, savedRequest.Parameters.Find(x => x.Name == "name").Value); Assert.AreEqual(templateContent, savedRequest.Parameters.Find(x => x.Name == "body").Value); var content = "{ \"id\": \"31337\", \"href\": \"/api/v2/contacts/31337\"}"; var testClient = Common.CreateClient<LinkResult>(content, null, null); client = new Client(testClient); var link = client.UpdateTemplate(template); Assert.IsTrue(link.Success); Assert.AreEqual(31337, link.Id); Assert.AreEqual("/api/v2/contacts/31337", link.Href); }
/// <summary> /// Update existing template. /// </summary> /// <param name="template">Template object</param> /// <returns></returns> public LinkResult UpdateTemplate(Template template) { var request = new RestRequest(Method.PUT); request.Resource = "templates/{id}"; request.AddUrlSegment("id", template.Id.ToString()); request.AddParameter("name", template.Name); request.AddParameter("body", template.Content); return Execute<LinkResult>(request); }