-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
RequestTests.cs
265 lines (226 loc) · 11.3 KB
/
RequestTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using ZendeskApi_v2.Models.Requests;
using ZendeskApi_v2.Models.Tickets;
using ZendeskApi_v2.Models.Users;
using ZendeskApi_v2.Tests.Base;
namespace ZendeskApi_v2.Tests
{
[TestFixture]
public class RequestTests : TestBase
{
[Test]
public void CanGetAllRequests()
{
var res = Api.Requests.GetAllRequests();
Assert.That(res.Count, Is.GreaterThan(0));
}
[TestCase(1, 1)]
[TestCase(1, 2)]
public void CanGetAllRequestsPaged(int perPage, int page)
{
Assert.DoesNotThrow(() =>
{
var res = Api.Requests.GetAllRequests(perPage: perPage, page: page);
Assert.That(res, Is.Not.Null);
Assert.That(res.Requests, Is.Not.Null);
Assert.That(res.PageSize, Is.EqualTo(perPage));
Assert.That(res.Page, Is.EqualTo(page));
});
}
[Test]
public void CanGetAllRequestsSorted()
{
Assert.DoesNotThrow(() =>
{
var unsorted = Api.Requests.GetAllRequests();
Assert.That(unsorted, Is.Not.Null);
Assert.That(unsorted.Requests, Is.Not.Null);
#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(unsorted.Requests.AsQueryable(), Is.EqualTo(unsorted.Requests.AsQueryable()));
#pragma warning restore NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(unsorted.Requests.AsQueryable(), Is.Not.EqualTo(unsorted.Requests.OrderBy(request => request.UpdatedAt).AsQueryable()));
var sorted = Api.Requests.GetAllRequests(sortCol: "updated_at", sortAscending: true);
Assert.That(sorted, Is.Not.Null);
Assert.That(sorted.Requests, Is.Not.Null);
#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(sorted.Requests.AsQueryable(), Is.EqualTo(sorted.Requests.AsQueryable()));
#pragma warning restore NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(sorted.Requests.AsQueryable(), Is.EqualTo(sorted.Requests.OrderBy(request => request.UpdatedAt).AsQueryable()));
});
}
[Test]
public void CanGetOpenRequests()
{
var res = Api.Requests.GetAllOpenRequests();
Assert.That(res.Count, Is.GreaterThan(0));
}
[TestCase(1, 1)]
[TestCase(1, 2)]
public void CanGetAllOpenRequestsPaged(int perPage, int page)
{
Assert.DoesNotThrow(() =>
{
var res = Api.Requests.GetAllOpenRequests(perPage: perPage, page: page);
Assert.That(res, Is.Not.Null);
Assert.That(res.Requests, Is.Not.Null);
Assert.That(res.PageSize, Is.EqualTo(perPage));
Assert.That(res.Page, Is.EqualTo(page));
});
}
[Test]
public void CanGetAllOpenRequestsSorted()
{
Assert.DoesNotThrow(() =>
{
var unsorted = Api.Requests.GetAllOpenRequests();
Assert.That(unsorted, Is.Not.Null);
Assert.That(unsorted.Requests, Is.Not.Null);
#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(unsorted.Requests.AsQueryable(), Is.EqualTo(unsorted.Requests.AsQueryable()));
#pragma warning restore NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(unsorted.Requests.AsQueryable(), Is.Not.EqualTo(unsorted.Requests.OrderBy(request => request.UpdatedAt).AsQueryable()));
var sorted = Api.Requests.GetAllOpenRequests(sortCol: "updated_at", sortAscending: true);
Assert.That(sorted, Is.Not.Null);
Assert.That(sorted.Requests, Is.Not.Null);
#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(sorted.Requests.AsQueryable(), Is.EqualTo(sorted.Requests.AsQueryable()));
#pragma warning restore NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(sorted.Requests.AsQueryable(), Is.EqualTo(sorted.Requests.OrderBy(request => request.UpdatedAt).AsQueryable()));
});
}
[Test]
public void CanGetAllSolvedRequests()
{
var res = Api.Requests.GetAllSolvedRequests();
Assert.That(res.Count, Is.GreaterThan(0));
}
[TestCase(1, 1)]
[TestCase(1, 2)]
public void CanGetAllSolvedRequestsPaged(int perPage, int page)
{
Assert.DoesNotThrow(() =>
{
var res = Api.Requests.GetAllSolvedRequests(perPage: perPage, page: page);
Assert.That(res, Is.Not.Null);
Assert.That(res.Requests, Is.Not.Null);
Assert.That(res.PageSize, Is.EqualTo(perPage));
Assert.That(res.Page, Is.EqualTo(page));
});
}
[Test]
public void CanGetAllSolvedRequestsSorted()
{
Assert.DoesNotThrow(() =>
{
var unsorted = Api.Requests.GetAllSolvedRequests();
Assert.That(unsorted, Is.Not.Null);
Assert.That(unsorted.Requests, Is.Not.Null);
#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(unsorted.Requests.AsQueryable(), Is.EqualTo(unsorted.Requests.AsQueryable()));
#pragma warning restore NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(unsorted.Requests.AsQueryable(), Is.Not.EqualTo(unsorted.Requests.OrderBy(request => request.UpdatedAt).AsQueryable()));
var sorted = Api.Requests.GetAllSolvedRequests(sortCol: "updated_at", sortAscending: true);
Assert.That(sorted, Is.Not.Null);
Assert.That(sorted.Requests, Is.Not.Null);
#pragma warning disable NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(sorted.Requests.AsQueryable(), Is.EqualTo(sorted.Requests.AsQueryable()));
#pragma warning restore NUnit2009 // The same value has been provided as both the actual and the expected argument
Assert.That(sorted.Requests.AsQueryable(), Is.EqualTo(sorted.Requests.OrderBy(request => request.UpdatedAt).AsQueryable()));
});
}
[Test]
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 </br> new line", Public = true },
Requester = new Requester
{
Name = "Test Name"
},
Tags = new List<string> { "tag1", "tag2" }
};
var res = Api.Requests.CreateRequest(req);
try
{
Assert.That(res, Is.Not.Null);
Assert.That(res.Request, Is.Not.Null);
Assert.That(res.Request.Id.HasValue, Is.True);
Assert.That(res.Request.Type, Is.EqualTo(RequestType.Incident));
Assert.That(res.Request.Id.Value, Is.GreaterThan(0));
IndividualUserResponse user = Api.Users.GetUser(res.Request.RequesterId.Value);
Assert.That(user.User.Name, Is.EqualTo("Test 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.That(res.Request.Id, Is.EqualTo(res1.Request.Id));
res1.Request.Subject = "new subject";
res1.Request.Comment = new Comment
{
Body = "something more to say",
Public = true
};
_ = Api.Requests.UpdateRequest(res1.Request);
var res3 = Api.Requests.GetRequestCommentsById(res.Request.Id.Value);
Assert.That(res3.Comments.Last().Body.Replace("\n", ""), Is.EqualTo("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.That(res6.Request.RequesterId, Is.EqualTo(res5.Request.RequesterId));
Assert.That(res3.Comments.Last().Id, Is.EqualTo(res4.Comment.Id));
}
finally
{
Assert.That(Api.Tickets.Delete(res.Request.Id.Value), Is.True);
}
}
[Test]
public void CanCreateRequestWithEmailCCs()
{
var emailCCs = new List<EmailCC>
{
new EmailCC{ UserEmail = "test1@test.com" },
new EmailCC{ UserEmail = "test2@test.com" }
};
var req = new Request
{
Subject = "end user request test",
Type = RequestType.Incident,
Comment = new Comment
{ Body = "end user test", HtmlBody = "end user test with </br> new line", Public = true },
Requester = new Requester
{
Name = "Test Name"
},
Tags = new List<string> { "tag1", "tag2" },
EmailCCs = emailCCs
};
var res = Api.Requests.CreateRequest(req);
try
{
Assert.That(res, Is.Not.Null);
Assert.That(res.Request, Is.Not.Null);
Assert.That(res.Request.Id.HasValue, Is.True);
Assert.That(res.Request.Id.Value, Is.GreaterThan(0));
Assert.That(res.Request.Type, Is.EqualTo(RequestType.Incident));
IndividualUserResponse user = Api.Users.GetUser(res.Request.RequesterId.Value);
Assert.That(user.User.Name, Is.EqualTo("Test Name"));
IndividualTicketResponse ticket = Api.Tickets.GetTicket(res.Request.Id.Value);
CollectionAssert.AreEquivalent(new[] { "tag1", "tag2" }, ticket.Ticket.Tags);
IList<long> collaboratorsIds = ticket.Ticket.CollaboratorIds;
GroupUserResponse collaborators = Api.Users.GetMultipleUsers(collaboratorsIds.AsEnumerable());
CollectionAssert.AreEquivalent(emailCCs.Select(e => e.UserEmail), collaborators.Users.Select(u => u.Email));
}
finally
{
Assert.That(Api.Tickets.Delete(res.Request.Id.Value), Is.True);
}
}
}
}