From 69a3baba6f998f230577dbf592ce94ef0c9b73f9 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Mon, 30 Mar 2020 22:13:34 +0200 Subject: [PATCH] add requester and tags properties to request (#468) --- src/ZendeskApi_v2/Models/Requests/Request.cs | 6 + test/ZendeskApi_v2.Test/RequestTests.cs | 110 +++++++++++-------- 2 files changed, 72 insertions(+), 44 deletions(-) diff --git a/src/ZendeskApi_v2/Models/Requests/Request.cs b/src/ZendeskApi_v2/Models/Requests/Request.cs index 2847d6d1..2cde38c4 100644 --- a/src/ZendeskApi_v2/Models/Requests/Request.cs +++ b/src/ZendeskApi_v2/Models/Requests/Request.cs @@ -52,6 +52,9 @@ public class Request [JsonProperty("requester_id")] public long? RequesterId { get; set; } + [JsonProperty("requester")] + public Requester Requester { get; set; } + [JsonProperty("assignee_id")] public long AssigneeId { get; set; } @@ -108,5 +111,8 @@ public class Request /// [JsonProperty("comment")] public Comment Comment { get; set; } + + [JsonProperty("tags")] + public IList Tags { get; set; } } } diff --git a/test/ZendeskApi_v2.Test/RequestTests.cs b/test/ZendeskApi_v2.Test/RequestTests.cs index 2dac7b34..123bed01 100644 --- a/test/ZendeskApi_v2.Test/RequestTests.cs +++ b/test/ZendeskApi_v2.Test/RequestTests.cs @@ -1,8 +1,11 @@ +using System; +using System.Collections.Generic; using NUnit.Framework; using System.Linq; using ZendeskApi_v2; using ZendeskApi_v2.Models.Requests; using ZendeskApi_v2.Models.Tickets; +using ZendeskApi_v2.Models.Users; namespace Tests { @@ -146,49 +149,68 @@ public void CanGetAllSolvedRequestsSorted() }); } - //[Test] - //[Ignore("")] - //public void CanCreateAndUpdateRequests() - //{ - // var req = new Request - // { - // Subject = "end user request test", - // Type = RequestType.incident, - // Comment = new Comment {Body = "end user test", HtmlBody = "end user test with
new line", Public = true} - // }; - - // var res = _api.Requests.CreateRequest(req); - // Assert.IsNotNull(res); - // Assert.IsNotNull(res.Request); - // Assert.IsTrue(res.Request.Id.HasValue); - // Assert.That(res.Request.Type == RequestType.incident); - // Assert.True(res.Request.Id.Value > 0); - - // var res1 = _api.Requests.GetRequestById(res.Request.Id.Value); - // Assert.AreEqual(res1.Request.Id, res.Request.Id); - - // res1.Request.Subject = "new subject"; - // res1.Request.Comment = new Comment - // { - // Body = "something more to say", - // Public = true - // }; - - // var res2 = _api.Requests.UpdateRequest(res1.Request); - // var res3 = _api.Requests.GetRequestCommentsById(res.Request.Id.Value); - - // Assert.AreEqual(res3.Comments.Last().Body.Replace("\n", ""), "something more to say"); - - // var res4 = _api.Requests.GetSpecificRequestComment(res.Request.Id.Value, res3.Comments.Last().Id.Value); - - // res1.Request.RequesterId = 56766413L; - // var res5 = _api.Requests.UpdateRequest(res1.Request); - // var res6 = _api.Requests.GetRequestById(res.Request.Id.Value); - - // Assert.AreEqual(res5.Request.RequesterId, res6.Request.RequesterId); - // Assert.AreEqual(res4.Comment.Id, res3.Comments.Last().Id); - - // Assert.True(_api.Tickets.Delete(res1.Request.Id.Value)); - //} + [Test] + // [Ignore("")] + public void CanCreateAndUpdateRequests() + { + var req = new Request + { + Subject = "end user request test", + Type = RequestType.incident, + Comment = new Comment + {Body = "end user test", HtmlBody = "end user test with
new line", Public = true}, + Requester = new Requester + { + Name = "Test Name" + }, + Tags = new List {"tag1", "tag2"} + }; + + var res = _api.Requests.CreateRequest(req); + + try + { + Assert.IsNotNull(res); + Assert.IsNotNull(res.Request); + Assert.IsTrue(res.Request.Id.HasValue); + Assert.That(res.Request.Type == RequestType.incident); + Assert.True(res.Request.Id.Value > 0); + + + IndividualUserResponse user = _api.Users.GetUser(res.Request.RequesterId.Value); + Assert.AreEqual("Test Name", user.User.Name); + + IndividualTicketResponse ticket = _api.Tickets.GetTicket(res.Request.Id.Value); + CollectionAssert.AreEquivalent(new[] {"tag1", "tag2"}, ticket.Ticket.Tags); + + var res1 = _api.Requests.GetRequestById(res.Request.Id.Value); + Assert.AreEqual(res1.Request.Id, res.Request.Id); + + res1.Request.Subject = "new subject"; + res1.Request.Comment = new Comment + { + Body = "something more to say", + Public = true + }; + + var res2 = _api.Requests.UpdateRequest(res1.Request); + var res3 = _api.Requests.GetRequestCommentsById(res.Request.Id.Value); + + Assert.AreEqual(res3.Comments.Last().Body.Replace("\n", ""), "something more to say"); + + var res4 = _api.Requests.GetSpecificRequestComment(res.Request.Id.Value, res3.Comments.Last().Id.Value); + + res1.Request.RequesterId = 56766413L; + var res5 = _api.Requests.UpdateRequest(res1.Request); + var res6 = _api.Requests.GetRequestById(res.Request.Id.Value); + + Assert.AreEqual(res5.Request.RequesterId, res6.Request.RequesterId); + Assert.AreEqual(res4.Comment.Id, res3.Comments.Last().Id); + } + finally + { + Assert.True(_api.Tickets.Delete(res.Request.Id.Value)); + } + } } }