-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathRequestInformationTests.cs
701 lines (622 loc) · 27.2 KB
/
RequestInformationTests.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Abstractions.Tests.Mocks;
using Moq;
using Xunit;
namespace Microsoft.Kiota.Abstractions.Tests
{
public class RequestInformationTests
{
[Fact]
public void SetUriExtractsQueryParameters()
{
// Arrange
var testRequest = new RequestInformation()
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/{path}/me?foo={foo}"
};
// Act
testRequest.QueryParameters.Add("foo", "bar");
testRequest.PathParameters.Add("path", "baz");
// Assert
Assert.Equal("http://localhost/baz/me?foo=bar", testRequest.URI.ToString());
Assert.NotEmpty(testRequest.QueryParameters);
Assert.Equal("foo", testRequest.QueryParameters.First().Key);
Assert.Equal("bar", testRequest.QueryParameters.First().Value.ToString());
}
[Fact]
public void AddsAndRemovesRequestOptions()
{
// Arrange
var testRequest = new RequestInformation()
{
HttpMethod = Method.GET,
URI = new Uri("http://localhost")
};
var testRequestOption = new Mock<IRequestOption>().Object;
Assert.Empty(testRequest.RequestOptions);
// Act
testRequest.AddRequestOptions(new IRequestOption[] { testRequestOption });
// Assert
Assert.NotEmpty(testRequest.RequestOptions);
Assert.Equal(testRequestOption, testRequest.RequestOptions.First());
// Act by removing the option
testRequest.RemoveRequestOptions(testRequestOption);
Assert.Empty(testRequest.RequestOptions);
}
[Fact]
public void SetsSelectQueryParameters()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?%24select}"
};
Action<GetQueryParameters> q = x => x.Select = new[] { "id", "displayName" };
var qParams = new GetQueryParameters();
q.Invoke(qParams);
// Act
requestInfo.AddQueryParameters(qParams);
// Assert
Assert.True(requestInfo.QueryParameters.ContainsKey("%24select"));
Assert.False(requestInfo.QueryParameters.ContainsKey("select"));
Assert.Equal("%24select", requestInfo.QueryParameters.First().Key);
}
[Fact]
public void DoesNotSetEmptyStringQueryParameters()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?%24search}"
};
Action<GetQueryParameters> q = x => x.Search = "";//empty string
var qParams = new GetQueryParameters();
q.Invoke(qParams);
// Act
requestInfo.AddQueryParameters(qParams);
// Assert
Assert.False(requestInfo.QueryParameters.ContainsKey($"%24search"));
Assert.False(requestInfo.QueryParameters.ContainsKey("search"));
}
[Fact]
public void DoesNotSetEmptyCollectionQueryParameters()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?%24select}"
};
Action<GetQueryParameters> q = x => x.Select = Array.Empty<string>(); //empty array
var qParams = new GetQueryParameters();
q.Invoke(qParams);
// Act
requestInfo.AddQueryParameters(qParams);
// Assert
Assert.False(requestInfo.QueryParameters.ContainsKey($"%24select"));
Assert.False(requestInfo.QueryParameters.ContainsKey("select"));
}
[Fact]
public void DoesNotSetQueryParametersToLowerCaseFirstCharacter()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?%TenantId}"
};
Action<GetQueryParameters> q = x => x.TenantId = "Tenant1";
var qParams = new GetQueryParameters();
q.Invoke(qParams);
// Act
requestInfo.AddQueryParameters(qParams);
// Assert
Assert.Contains("TenantId", requestInfo.QueryParameters.Keys);
Assert.DoesNotContain("tenantId", requestInfo.QueryParameters.Keys);
}
[Fact]
public void SetsPathParametersOfDateTimeOffsetType()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/getDirectRoutingCalls(fromDateTime='{fromDateTime}',toDateTime='{toDateTime}')"
};
// Act
var fromDateTime = new DateTimeOffset(2022, 8, 1, 0, 0, 0, TimeSpan.Zero);
var toDateTime = new DateTimeOffset(2022, 8, 2, 0, 0, 0, TimeSpan.Zero);
var pathParameters = new Dictionary<string, object>();
pathParameters.Add("fromDateTime", fromDateTime);
pathParameters.Add("toDateTime", toDateTime);
requestInfo.PathParameters = pathParameters;
// Assert
Assert.Contains("fromDateTime='2022-08-01T00%3A00%3A00.0000000%2B00%3A00'", requestInfo.URI.OriginalString);
Assert.Contains("toDateTime='2022-08-02T00%3A00%3A00.0000000%2B00%3A00'", requestInfo.URI.OriginalString);
}
[Fact]
public void SetsPathParametersOfBooleanType()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/users{?%24count}"
};
// Act
var count = true;
var pathParameters = new Dictionary<string, object>();
pathParameters.Add("%24count", count);
requestInfo.PathParameters = pathParameters;
// Assert
Assert.Contains("%24count=true", requestInfo.URI.OriginalString);
}
[Fact]
public void SetsPathParametersOfGuidType()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/users{?%24requestId}"
};
// Act
var guid = Guid.Parse("6d320a89-2d8f-4204-855d-b98a1bc176d4");
var pathParameters = new Dictionary<string, object>
{
{ "%24requestId", guid }
};
requestInfo.PathParameters = pathParameters;
// Assert
Assert.Contains($"%24requestId=6d320a89-2d8f-4204-855d-b98a1bc176d4", requestInfo.URI.OriginalString);
}
[Fact]
public void SetsPathParametersOfDateType()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/users{?%24date}"
};
// Act
var date = new Date(2023, 10, 26);
var pathParameters = new Dictionary<string, object>
{
{ "%24date", date }
};
requestInfo.PathParameters = pathParameters;
// Assert
Assert.Contains($"%24date=2023-10-26", requestInfo.URI.OriginalString);
}
[Fact]
public void SetsPathParametersOfTimeType()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/users{?%24time}"
};
// Act
var time = new Time(6, 0, 0);
var pathParameters = new Dictionary<string, object>
{
{ "%24time", time }
};
requestInfo.PathParameters = pathParameters;
// Assert
Assert.Contains($"%24time=06%3A00%3A00", requestInfo.URI.OriginalString);
}
[Fact]
public void ThrowsInvalidOperationExceptionWhenBaseUrlNotSet()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "{+baseurl}/users{?%24count}"
};
// Assert
var exception = Assert.Throws<InvalidOperationException>(() => requestInfo.URI);
Assert.Contains("baseurl", exception.Message);
}
[Fact]
public void BuildsUrlOnProvidedBaseUrl()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "{+baseurl}/users{?%24count}"
};
// Act
requestInfo.PathParameters = new Dictionary<string, object>()
{
{ "baseurl","http://localhost" }
};
// Assert
Assert.Contains("http://localhost", requestInfo.URI.OriginalString);
}
[Fact]
public void InitializeWithProxyBaseUrl()
{
var proxyUrl = "https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/beta";
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "{+baseurl}/users{?%24count}"
};
// Act
requestInfo.PathParameters = new Dictionary<string, object>()
{
{ "baseurl", proxyUrl },
{ "%24count", true }
};
// Assert we can build urls based on a Proxy based base url
Assert.Equal("https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/beta/users?%24count=true", requestInfo.URI.OriginalString);
}
[Fact]
public void GetsAndSetsResponseHandlerByType()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "{+baseurl}/users{?%24count}"
};
// Assert we have NO option
Assert.Null(requestInfo.GetRequestOption<ResponseHandlerOption>());
// Act
requestInfo.PathParameters = new Dictionary<string, object>()
{
{ "baseurl", "http://localhost" },
{ "%24count", true }
};
requestInfo.SetResponseHandler(new NativeResponseHandler());
// Assert we now have an option
Assert.NotNull(requestInfo.GetRequestOption<ResponseHandlerOption>());
}
[Fact]
public void SetsObjectContent()
{
var requestAdapterMock = new Mock<IRequestAdapter>();
var serializationWriterMock = new Mock<ISerializationWriter>();
var serializationWriterFactoryMock = new Mock<ISerializationWriterFactory>();
serializationWriterFactoryMock.Setup(x => x.GetSerializationWriter(It.IsAny<string>())).Returns(serializationWriterMock.Object);
requestAdapterMock.SetupGet(x => x.SerializationWriterFactory).Returns(serializationWriterFactoryMock.Object);
var requestInfo = new RequestInformation
{
HttpMethod = Method.POST,
UrlTemplate = "{+baseurl}/users{?%24count}"
};
requestInfo.SetContentFromParsable(requestAdapterMock.Object, "application/json", new TestEntity());
// Assert we now have an option
serializationWriterMock.Verify(x => x.WriteObjectValue(It.IsAny<string>(), It.IsAny<IParsable>()), Times.Once);
serializationWriterMock.Verify(x => x.WriteCollectionOfObjectValues(It.IsAny<string>(), It.IsAny<IEnumerable<IParsable>>()), Times.Never);
}
[Fact]
public void SetsObjectCollectionContentSingleElement()
{
var requestAdapterMock = new Mock<IRequestAdapter>();
var serializationWriterMock = new Mock<ISerializationWriter>();
var serializationWriterFactoryMock = new Mock<ISerializationWriterFactory>();
serializationWriterFactoryMock.Setup(x => x.GetSerializationWriter(It.IsAny<string>())).Returns(serializationWriterMock.Object);
requestAdapterMock.SetupGet(x => x.SerializationWriterFactory).Returns(serializationWriterFactoryMock.Object);
var requestInfo = new RequestInformation
{
HttpMethod = Method.POST,
UrlTemplate = "{+baseurl}/users{?%24count}"
};
requestInfo.SetContentFromParsable(requestAdapterMock.Object, "application/json", new[] { new TestEntity() });
// Assert we now have an option
serializationWriterMock.Verify(x => x.WriteObjectValue(It.IsAny<string>(), It.IsAny<IParsable>()), Times.Never);
serializationWriterMock.Verify(x => x.WriteCollectionOfObjectValues(It.IsAny<string>(), It.IsAny<IEnumerable<IParsable>>()), Times.Once);
}
[Fact]
public void SetsScalarContent()
{
var requestAdapterMock = new Mock<IRequestAdapter>();
var serializationWriterMock = new Mock<ISerializationWriter>();
var serializationWriterFactoryMock = new Mock<ISerializationWriterFactory>();
serializationWriterFactoryMock.Setup(x => x.GetSerializationWriter(It.IsAny<string>())).Returns(serializationWriterMock.Object);
requestAdapterMock.SetupGet(x => x.SerializationWriterFactory).Returns(serializationWriterFactoryMock.Object);
var requestInfo = new RequestInformation
{
HttpMethod = Method.POST,
UrlTemplate = "{+baseurl}/users{?%24count}"
};
requestInfo.SetContentFromScalar(requestAdapterMock.Object, "application/json", "foo");
// Assert we now have an option
serializationWriterMock.Verify(x => x.WriteStringValue(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
serializationWriterMock.Verify(x => x.WriteCollectionOfPrimitiveValues(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()), Times.Never);
}
[Fact]
public void SetsScalarCollectionContent()
{
var requestAdapterMock = new Mock<IRequestAdapter>();
var serializationWriterMock = new Mock<ISerializationWriter>();
var serializationWriterFactoryMock = new Mock<ISerializationWriterFactory>();
serializationWriterFactoryMock.Setup(x => x.GetSerializationWriter(It.IsAny<string>())).Returns(serializationWriterMock.Object);
requestAdapterMock.SetupGet(x => x.SerializationWriterFactory).Returns(serializationWriterFactoryMock.Object);
var requestInfo = new RequestInformation
{
HttpMethod = Method.POST,
UrlTemplate = "{+baseurl}/users{?%24count}"
};
requestInfo.SetContentFromScalarCollection(requestAdapterMock.Object, "application/json", new[] { "foo" });
// Assert we now have an option
serializationWriterMock.Verify(x => x.WriteStringValue(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
serializationWriterMock.Verify(x => x.WriteCollectionOfPrimitiveValues(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()), Times.Once);
}
[Fact]
public void GetUriResolvesParametersCaseSensitive()
{
// Arrange
var testRequest = new RequestInformation()
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/{URITemplate}/ParameterMapping?IsCaseSensitive={IsCaseSensitive}"
};
// Act
testRequest.PathParameters.Add("URITemplate", "UriTemplate");
testRequest.QueryParameters.Add("IsCaseSensitive", false);
// Assert
Assert.Equal("http://localhost/UriTemplate/ParameterMapping?IsCaseSensitive=false", testRequest.URI.ToString());
}
[Fact]
public void SetsBoundaryOnMultipartBody()
{
// Arrange
var testRequest = new RequestInformation()
{
HttpMethod = Method.POST,
UrlTemplate = "http://localhost/{URITemplate}/ParameterMapping?IsCaseSensitive={IsCaseSensitive}"
};
var requestAdapterMock = new Mock<IRequestAdapter>();
var serializationWriterFactoryMock = new Mock<ISerializationWriterFactory>();
var serializationWriterMock = new Mock<ISerializationWriter>();
serializationWriterFactoryMock.Setup(x => x.GetSerializationWriter(It.IsAny<string>())).Returns(serializationWriterMock.Object);
requestAdapterMock.SetupGet(x => x.SerializationWriterFactory).Returns(serializationWriterFactoryMock.Object);
// Given
var multipartBody = new MultipartBody
{
RequestAdapter = requestAdapterMock.Object
};
// When
testRequest.SetContentFromParsable(requestAdapterMock.Object, "multipart/form-data", multipartBody);
// Then
Assert.NotNull(multipartBody.Boundary);
Assert.True(testRequest.Headers.TryGetValue("Content-Type", out var contentType));
Assert.Single(contentType);
Assert.Equal("multipart/form-data; boundary=" + multipartBody.Boundary, contentType.First());
}
[Fact]
public void SetsEnumValueInQueryParameters()
{
// Arrange
var testRequest = new RequestInformation()
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?dataset}"
};
// Act
testRequest.AddQueryParameters(new GetQueryParameters { DataSet = TestEnum.First });
// Assert
Assert.Equal("http://localhost/me?dataset=1", testRequest.URI.ToString());
}
[Fact]
public void SetsEnumValuesInQueryParameters()
{
// Arrange
var testRequest = new RequestInformation()
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?datasets}"
};
// Act
testRequest.AddQueryParameters(new GetQueryParameters { DataSets = new TestEnum[] { TestEnum.First, TestEnum.Second } });
// Assert
Assert.Equal("http://localhost/me?datasets=1,2", testRequest.URI.ToString());
}
[Fact]
public void SetsEnumValueInPathParameters()
{
// Arrange
var testRequest = new RequestInformation()
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/{dataset}"
};
// Act
testRequest.PathParameters.Add("dataset", TestEnum.First);
// Assert
Assert.Equal("http://localhost/1", testRequest.URI.ToString());
}
[Fact]
public void SetsEnumValuesInPathParameters()
{
// Arrange
var testRequest = new RequestInformation()
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/{dataset}"
};
// Act
testRequest.PathParameters.Add("dataset", new TestEnum[] { TestEnum.First, TestEnum.Second });
// Assert
Assert.Equal("http://localhost/1,2", testRequest.URI.ToString());
}
[Fact]
public void SetsIntValueInQueryParameters()
{
// Arrange
var testRequest = new RequestInformation()
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?item}"
};
// Act
testRequest.AddQueryParameters(new GetQueryParameters { Item = 1 });
// Assert
Assert.Equal("http://localhost/me?item=1", testRequest.URI.ToString());
}
[Fact]
public void SetsIntValuesInQueryParameters()
{
// Arrange
var requestInfo = new RequestInformation()
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?items}"
};
// Act
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object []{1,2}});
// Assert
Assert.Equal("http://localhost/me?items=1,2", requestInfo.URI.ToString());
}
[Fact]
public void SetsBooleanValuesInQueryParameters()
{
// Arrange
var requestInfo = new RequestInformation()
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?items}"
};
// Act
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object [] { true, false } });
// Assert
Assert.Equal("http://localhost/me?items=true,false", requestInfo.URI.ToString());
}
[Fact]
public void SetsDateTimeOffsetValuesInQueryParameters()
{
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?items}"
};
// Act
var dateTime1 = new DateTimeOffset(2022, 8, 1, 0, 0, 0, TimeSpan.Zero);
var dateTime2 = new DateTimeOffset(2022, 8, 2, 0, 0, 0, TimeSpan.Zero);
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object[] { dateTime1, dateTime2 } });
// Assert
Assert.Equal("http://localhost/me?items=2022-08-01T00%3A00%3A00.0000000%2B00%3A00,2022-08-02T00%3A00%3A00.0000000%2B00%3A00", requestInfo.URI.OriginalString);
}
[Fact]
public void SetsDateTimeValuesInQueryParameters()
{
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?items}"
};
// Act
var dateTime1 = new DateTime(2022, 8, 1, 0, 0, 0);
var dateTime2 = new DateTime(2022, 8, 2, 0, 0, 0);
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object[] { dateTime1, dateTime2 } });
// Assert
Assert.Equal("http://localhost/me?items=2022-08-01T00%3A00%3A00.0000000,2022-08-02T00%3A00%3A00.0000000", requestInfo.URI.OriginalString);
}
[Fact]
public void SetsDateValuesInQueryParameters()
{
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?items}"
};
// Act
var date1 = new Date(2022, 8, 1);
var date2 = new Date(2022, 8, 2);
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object[] { date1, date2 } });
// Assert
Assert.Equal("http://localhost/me?items=2022-08-01,2022-08-02", requestInfo.URI.OriginalString);
}
[Fact]
public void SetsTimeValuesInQueryParameters()
{
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?items}"
};
// Act
var date1 = new Time(10,0,0);
var date2 = new Time(11, 1, 1);
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object[] { date1, date2 } });
// Assert
Assert.Equal("http://localhost/me?items=10%3A00%3A00,11%3A01%3A01", requestInfo.URI.OriginalString);
}
[Fact]
public void SetsGuidValuesInQueryParameters()
{
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?items}"
};
// Act
var g1 = Guid.Parse("55331110-6817-4A9B-83B2-57617E3E08E5");
var g2 = Guid.Parse("482DFF4F-63D6-47F4-A88B-5CAEC03180D4");
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object[] { g1, g2 } });
// Assert
Assert.Equal("http://localhost/me?items=55331110-6817-4a9b-83b2-57617e3e08e5,482dff4f-63d6-47f4-a88b-5caec03180d4", requestInfo.URI.OriginalString);
}
[Fact]
public void DoesNotExpandSecondLayerArrays()
{
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?items}"
};
// Act
requestInfo.AddQueryParameters(new GetQueryParameters { Items = new object[]{new int[]{1,2,3,4} } });
// Assert
Assert.Equal("http://localhost/me?items=System.Int32%5B%5D", requestInfo.URI.OriginalString);
}
}
/// <summary>The messages in a mailbox or folder. Read-only. Nullable.</summary>
internal class GetQueryParameters
{
/// <summary>Select properties to be returned</summary>\
[QueryParameter("%24select")]
public string[] Select { get; set; }
/// <summary>Unique id of the request</summary>
[QueryParameter("%24requestId")]
public Guid RequestId { get; set; }
/// <summary>Include count of items</summary>
[QueryParameter("%24count")]
public bool? Count { get; set; }
/// <summary>Expand related entities</summary>
[QueryParameter("%24filter")]
public string Filter { get; set; }
/// <summary>Order items by property values</summary>
[QueryParameter("%24orderby")]
public string[] Orderby { get; set; }
/// <summary>Search items by search phrases</summary>
[QueryParameter("%24search")]
public string Search { get; set; }
/// <summary>Restrict to TenantId</summary>
public string TenantId { get; set; }
/// <summary>Which Dataset to use</summary>
[QueryParameter("dataset")]
public TestEnum DataSet { get; set; }
/// <summary>Which Dataset to use</summary>
[QueryParameter("datasets")]
public TestEnum[] DataSets { get; set; }
[QueryParameter("item")]
public object Item { get; set; }
[QueryParameter("items")]
public object[] Items { get; set; }
}
}