Skip to content

Commit d3cdef4

Browse files
committed
json
1 parent 146a543 commit d3cdef4

File tree

3 files changed

+57
-29
lines changed

3 files changed

+57
-29
lines changed

tests/CommandQuery.Tests/Client/Internal/QueryExtensionsTests.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace CommandQuery.Tests.Client.Internal
77
public class QueryExtensionsTests
88
{
99
[Test]
10-
public void GetRequestUri()
10+
public void GetRequestUri_with_complex_query()
1111
{
1212
var result = TestData.FakeComplexQuery.GetRequestUri();
1313
result.Should()
@@ -16,6 +16,7 @@ public void GetRequestUri()
1616
.Contain("Boolean=True").And
1717
.Contain("Byte=1").And
1818
.Contain("Char=C").And
19+
.Contain("DateOnly=07%2F09%2F2021").And
1920
.Contain("DateTime=2021-07-09T18%3A37%3A53.2473503").And
2021
.Contain("DateTimeOffset=2021-07-09T20%3A39%3A07.8226113%2B02%3A00").And
2122
.Contain("Decimal=2.1").And
@@ -28,25 +29,36 @@ public void GetRequestUri()
2829
.Contain("SByte=7").And
2930
.Contain("Single=8").And
3031
.Contain("String=String").And
31-
//.Contain("TimeSpan=1%3A02%3A03%3A04").And
32+
.Contain("TimeOnly=18%3A37").And
33+
.Contain("TimeSpan=1.02%3A03%3A04").And
3234
.Contain("UInt16=9").And
3335
.Contain("UInt32=10").And
3436
.Contain("UInt64=11").And
3537
.Contain("Uri=https%3A%2F%2Fgithub.com%2Fhlaueriksson%2FCommandQuery").And
38+
.Contain("Version=1.2.3.4").And
3639

3740
.Contain("Nullable=12").And
41+
//.Contain("Tuple=(13,14)").And
3842

39-
.Contain("Array=13&Array=14").And
40-
.Contain("IEnumerable=15&IEnumerable=16").And
41-
.Contain("IList=17&IList=18").And
42-
.Contain("IReadOnlyList=19&IReadOnlyList=20");
43+
.Contain("Array=15&Array=16").And
44+
//.Contain("IDictionary=17:18").And
45+
.Contain("IEnumerable=19&IEnumerable=20").And
46+
.Contain("IList=21&IList=22").And
47+
.Contain("IReadOnlyList=23&IReadOnlyList=24");
4348

44-
result = TestData.FakeDateTimeQuery.GetRequestUri();
49+
Action act = () => ((object)null).GetRequestUri();
50+
act.Should().Throw<ArgumentNullException>();
51+
}
52+
53+
[Test]
54+
public void GetRequestUri_with_datetime_query()
55+
{
56+
var result = TestData.FakeDateTimeQuery.GetRequestUri();
4557
result.Should()
4658
.Contain("DateTimeUnspecified=2021-07-10T09%3A48%3A41.0000000").And
4759
.Contain("DateTimeUtc=2021-07-10T09%3A48%3A41.0000000Z").And
4860
//.Contain("DateTimeLocal=2021-07-10T09%3A48%3A41.0000000%2B02%3A00").And
49-
.Contain("DateTimeArray=2021-07-10T09%3A48%3A41.0000000&DateTimeArray=2021-07-10T09%3A48%3A41.0000000Z"/*&DateTimeArray=2021-07-10T09%3A48%3A41.0000000%2B02%3A00*/);
61+
.Contain("DateTimeArray=2021-07-10T09%3A48%3A41.0000000&DateTimeArray=2021-07-10T09%3A48%3A41.0000000Z"/*&DateTimeArray=2021-07-10T09%3A48%3A41.0000000%2B02%3A00"*/);
5062

5163
Action act = () => ((object)null).GetRequestUri();
5264
act.Should().Throw<ArgumentNullException>();

tests/CommandQuery.Tests/Fake.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class FakeComplexQuery : IQuery<IEnumerable<FakeResult>>
5959
public bool Boolean { get; set; }
6060
public byte Byte { get; set; }
6161
public char Char { get; set; }
62+
public DateOnly DateOnly { get; set; }
6263
public DateTime DateTime { get; set; }
6364
public DateTimeOffset DateTimeOffset { get; set; }
6465
public decimal Decimal { get; set; }
@@ -71,6 +72,7 @@ public class FakeComplexQuery : IQuery<IEnumerable<FakeResult>>
7172
public sbyte SByte { get; set; }
7273
public float Single { get; set; }
7374
public string String { get; set; }
75+
public TimeOnly TimeOnly { get; set; }
7476
public TimeSpan TimeSpan { get; set; }
7577
public ushort UInt16 { get; set; }
7678
public uint UInt32 { get; set; }
@@ -79,8 +81,10 @@ public class FakeComplexQuery : IQuery<IEnumerable<FakeResult>>
7981
public Version Version { get; set; }
8082

8183
public int? Nullable { get; set; }
84+
public (int, int) Tuple { get; set; }
8285

8386
public int[] Array { get; set; }
87+
public IDictionary<int, int> IDictionary { get; set; }
8488
public IEnumerable<int> IEnumerable { get; set; }
8589
public IList<int> IList { get; set; }
8690
public IReadOnlyList<int> IReadOnlyList { get; set; }

tests/CommandQuery.Tests/TestData.cs

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static class TestData
77
Boolean = true,
88
Byte = 1,
99
Char = 'C',
10+
DateOnly = DateOnly.Parse("2021-07-09"),
1011
DateTime = DateTime.Parse("2021-07-09T18:37:53.2473503"),
1112
DateTimeOffset = DateTimeOffset.Parse("2021-07-09T20:39:07.8226113+02:00"),
1213
Decimal = 2.1M,
@@ -19,26 +20,30 @@ public static class TestData
1920
SByte = 7,
2021
Single = 8.1f,
2122
String = "String",
22-
//TimeSpan = TimeSpan.Parse("1:02:03:04"),
23+
TimeOnly = TimeOnly.Parse("18:37:53.2473503"),
24+
TimeSpan = TimeSpan.Parse("1.02:03:04"),
2325
UInt16 = 9,
2426
UInt32 = 10U,
2527
UInt64 = 11UL,
2628
Uri = new Uri("https://github.com/hlaueriksson/CommandQuery"),
27-
//Version = Version.Parse("1.2.3.4"),
29+
Version = Version.Parse("1.2.3.4"),
2830

2931
Nullable = 12,
32+
//Tuple = (13, 14),
3033

31-
Array = new[] { 13, 14 },
32-
IEnumerable = new[] { 15, 16 },
33-
IList = new[] { 17, 18 },
34-
IReadOnlyList = new[] { 19, 20 },
34+
Array = new[] { 15, 16 },
35+
//IDictionary = new Dictionary<int, int>() { { 17, 18 } },
36+
IEnumerable = new[] { 19, 20 },
37+
IList = new[] { 21, 22 },
38+
IReadOnlyList = new[] { 23, 24 },
3539
};
3640

3741
public static readonly Dictionary<string, object> FakeComplexQuery_As_Dictionary_Of_String_Object = new()
3842
{
3943
{ "Boolean", "true" },
4044
{ "Byte", "1" },
4145
{ "Char", "C" },
46+
{ "DateOnly", "2021-07-09" },
4247
{ "DateTime", "2021-07-09T18:37:53.2473503" },
4348
{ "DateTimeOffset", "2021-07-09T20:39:07.8226113+02:00" },
4449
{ "Decimal", "2.1" },
@@ -51,19 +56,22 @@ public static class TestData
5156
{ "SByte", "7" },
5257
{ "Single", "8.1" },
5358
{ "String", "String" },
54-
//{ "TimeSpan", "1:02:03:04" },
59+
{ "TimeOnly", "18:37:53.2473503" },
60+
{ "TimeSpan", "1.02:03:04" },
5561
{ "UInt16", "9" },
5662
{ "UInt32", "10" },
5763
{ "UInt64", "11" },
5864
{ "Uri", "https://github.com/hlaueriksson/CommandQuery" },
59-
//{ "Version", "1.2.3.4" },
65+
{ "Version", "1.2.3.4" },
6066

6167
{ "Nullable", "12" },
68+
//{ "Tuple", (13, 14) },
6269

63-
{ "Array", new[] { "13", "14" } },
64-
{ "IEnumerable", new[] { "15", "16" } },
65-
{ "IList", new[] { "17", "18" } },
66-
{ "IReadOnlyList", new[] { "19", "20" } },
70+
{ "Array", new[] { "15", "16" } },
71+
//{ "IDictionary", new Dictionary<int, int> { { 17, 18 } } },
72+
{ "IEnumerable", new[] { "19", "20" } },
73+
{ "IList", new[] { "21", "22" } },
74+
{ "IReadOnlyList", new[] { "23", "24" } },
6775

6876
{ "UndefinedProperty", "should_not_be_used" },
6977
};
@@ -73,6 +81,7 @@ public static class TestData
7381
{ "Boolean", new[] { "true" } },
7482
{ "Byte", new[] { "1" } },
7583
{ "Char", new[] { "C" } },
84+
{ "DateOnly", new[] { "2021-07-09" } },
7685
{ "DateTime", new[] { "2021-07-09T18:37:53.2473503" } },
7786
{ "DateTimeOffset", new[] { "2021-07-09T20:39:07.8226113+02:00" } },
7887
{ "Decimal", new[] { "2.1" } },
@@ -85,19 +94,22 @@ public static class TestData
8594
{ "SByte", new[] { "7" } },
8695
{ "Single", new[] { "8.1" } },
8796
{ "String", new[] { "String" } },
88-
//{ "TimeSpan", new[] { "1:02:03:04,0000005" } },
97+
{ "TimeOnly", new[] { "18:37:53.2473503" } },
98+
{ "TimeSpan", new[] { "1.02:03:04" } },
8999
{ "UInt16", new[] { "9" } },
90100
{ "UInt32", new[] { "10" } },
91101
{ "UInt64", new[] { "11" } },
92102
{ "Uri", new[] { "https://github.com/hlaueriksson/CommandQuery" } },
93-
//{ "Version", new[] { "1.2.3.4" } },
103+
{ "Version", new[] { "1.2.3.4" } },
94104

95105
{ "Nullable", new[] { "12" } },
106+
//{ "Tuple", new[] { "13", "14" } },
96107

97-
{ "Array", new[] { "13", "14" } },
98-
{ "IEnumerable", new[] { "15", "16" } },
99-
{ "IList", new[] { "17", "18" } },
100-
{ "IReadOnlyList", new[] { "19", "20" } },
108+
{ "Array", new[] { "15", "16" } },
109+
//{ "IDictionary", new[] { "{\"17\": 18}" } },
110+
{ "IEnumerable", new[] { "19", "20" } },
111+
{ "IList", new[] { "21", "22" } },
112+
{ "IReadOnlyList", new[] { "23", "24" } },
101113

102114
{ "UndefinedProperty", new[] { "should_not_be_used" } },
103115
};
@@ -107,12 +119,12 @@ public static class TestData
107119
DateTimeUnspecified = new DateTime(2021, 7, 10, 9, 48, 41, DateTimeKind.Unspecified),
108120
DateTimeUtc = new DateTime(2021, 7, 10, 9, 48, 41, DateTimeKind.Utc),
109121
//DateTimeLocal = new DateTime(2021, 7, 10, 9, 48, 41, DateTimeKind.Local),
110-
DateTimeArray = new[]
111-
{
122+
DateTimeArray =
123+
[
112124
new DateTime(2021, 7, 10, 9, 48, 41, DateTimeKind.Unspecified),
113125
new DateTime(2021, 7, 10, 9, 48, 41, DateTimeKind.Utc),
114126
//new DateTime(2021, 7, 10, 9, 48, 41, DateTimeKind.Local),
115-
}
127+
]
116128
};
117129

118130
public static readonly Dictionary<string, object> FakeDateTimeQuery_As_Dictionary_Of_String_Object = new()

0 commit comments

Comments
 (0)