Skip to content

Commit 97478a1

Browse files
committed
Add and update test cases
1 parent 123412b commit 97478a1

File tree

4 files changed

+68
-34
lines changed

4 files changed

+68
-34
lines changed

JsonSchema.Tests/JsonSchema.Tests.csproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<AssemblyName>RelogicLabs.JsonSchema.Tests</AssemblyName>
5+
<Description>This project contains test cases for JsonSchema project.</Description>
6+
<Authors>Relogic Labs</Authors>
7+
<Company>Relogic Labs</Company>
8+
<Version>1.7.0</Version>
9+
<PackageVersion>1.7.0</PackageVersion>
10+
<AssemblyVersion>1.7.0</AssemblyVersion>
11+
<Copyright>Copyright © Relogic Labs. All rights reserved.</Copyright>
12+
<NeutralLanguage>en</NeutralLanguage>
13+
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
514
<ImplicitUsings>enable</ImplicitUsings>
615
<Nullable>enable</Nullable>
716
<IsPackable>false</IsPackable>
8-
<AssemblyName>RelogicLabs.JsonSchema.Tests</AssemblyName>
9-
<Company>Relogic Labs</Company>
10-
<RootNamespace />
17+
<RootNamespace>RelogicLabs</RootNamespace>
18+
<LangVersion>preview</LangVersion>
1119
</PropertyGroup>
1220

1321
<ItemGroup>
@@ -21,4 +29,4 @@
2129
<ProjectReference Include="..\JsonSchema\JsonSchema.csproj" />
2230
</ItemGroup>
2331

24-
</Project>
32+
</Project>

JsonSchema.Tests/RelogicLabs/JsonSchema/Tests/Negative/DateTimeTests.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@ public class DateTimeTests
1010
public void When_JsonNotDate_ExceptionThrown()
1111
{
1212
var schema = "#date";
13-
var json = "\"This is not a valid date\"";
13+
var json = "\"This is not a date\"";
14+
15+
JsonSchema.IsValid(schema, json);
16+
var exception = Assert.ThrowsException<JsonSchemaException>(
17+
() => JsonAssert.IsValid(schema, json));
18+
Assert.AreEqual(DTYP04, exception.Code);
19+
Console.WriteLine(exception);
20+
}
21+
22+
[TestMethod]
23+
public void When_JsonNotValidDate_ExceptionThrown()
24+
{
25+
var schema = "#date";
26+
var json = "\"1939-02-29\"";
1427

1528
JsonSchema.IsValid(schema, json);
1629
var exception = Assert.ThrowsException<JsonSchemaException>(
@@ -23,7 +36,20 @@ public void When_JsonNotDate_ExceptionThrown()
2336
public void When_JsonNotTime_ExceptionThrown()
2437
{
2538
var schema = "#time";
26-
var json = "\"This is not a valid time\"";
39+
var json = "\"This is not a time\"";
40+
41+
JsonSchema.IsValid(schema, json);
42+
var exception = Assert.ThrowsException<JsonSchemaException>(
43+
() => JsonAssert.IsValid(schema, json));
44+
Assert.AreEqual(DTYP04, exception.Code);
45+
Console.WriteLine(exception);
46+
}
47+
48+
[TestMethod]
49+
public void When_JsonNotValidTime_ExceptionThrown()
50+
{
51+
var schema = "#time";
52+
var json = "\"1939-09-02T2:12:12.000Z\"";
2753

2854
JsonSchema.IsValid(schema, json);
2955
var exception = Assert.ThrowsException<JsonSchemaException>(

JsonSchema.Tests/RelogicLabs/JsonSchema/Tests/Negative/FunctionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public void When_FunctionAppliedOnWrongType_ExceptionThrown()
1919
"test"
2020
""";
2121

22-
//JsonSchema.IsValid(schema, json);
23-
var exception = Assert.ThrowsException<FunctionMismatchException>(
22+
JsonSchema.IsValid(schema, json);
23+
var exception = Assert.ThrowsException<JsonSchemaException>(
2424
() => JsonAssert.IsValid(schema, json));
2525
Assert.AreEqual(FUNC03, exception.Code);
2626
Console.WriteLine(exception);
@@ -32,7 +32,7 @@ public void When_ExternalIncludeNotInheritBaseClass_ExceptionThrown()
3232
var schema =
3333
"""
3434
%include: RelogicLabs.JsonSchema.Tests.Negative.ExternalFunctions1,
35-
RelogicLabs.JsonSchema.Tests
35+
RelogicLabs.JsonSchema.Tests
3636
%schema: @odd #integer
3737
""";
3838
var json = "10";

JsonSchema.Tests/RelogicLabs/JsonSchema/Tests/Positive/DateTimeTests.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ namespace RelogicLabs.JsonSchema.Tests.Positive;
33
[TestClass]
44
public class DateTimeTests
55
{
6-
6+
77
[TestMethod]
88
public void When_DataTypeDate_ValidTrue()
99
{
1010
var schema = "#date";
1111
var json = "\"2023-09-01\"";
1212
JsonAssert.IsValid(schema, json);
1313
}
14-
14+
1515
[TestMethod]
1616
public void When_DataTypeTime_ValidTrue()
1717
{
1818
var schema = "#time";
1919
var json = "\"2023-09-01T14:35:10.123+06:00\"";
2020
JsonAssert.IsValid(schema, json);
2121
}
22-
22+
2323
[TestMethod]
2424
public void When_DataTypeDateInObject_ValidTrue()
2525
{
@@ -41,7 +41,7 @@ public void When_DataTypeDateInObject_ValidTrue()
4141
""";
4242
JsonAssert.IsValid(schema, json);
4343
}
44-
44+
4545
[TestMethod]
4646
public void When_DataTypeTimeInObject_ValidTrue()
4747
{
@@ -56,14 +56,14 @@ public void When_DataTypeTimeInObject_ValidTrue()
5656
var json =
5757
"""
5858
{
59-
"key1": "1950-12-31T11:40:10.000+06:30",
60-
"key2": "0001-01-01T00:00:00.000+00:00",
61-
"key3": "1600-02-29T23:59:59.999Z"
59+
"key1": "1950-12-31T11:40:10.333+06:30",
60+
"key2": "0001-01-01T00:00:00.0+00:00",
61+
"key3": "1600-02-29T23:59:59.99999Z"
6262
}
6363
""";
6464
JsonAssert.IsValid(schema, json);
6565
}
66-
66+
6767
[TestMethod]
6868
public void When_DataTypeDateInArray_ValidTrue()
6969
{
@@ -77,7 +77,7 @@ public void When_DataTypeDateInArray_ValidTrue()
7777
""";
7878
JsonAssert.IsValid(schema, json);
7979
}
80-
80+
8181
[TestMethod]
8282
public void When_DataTypeTimeInArray_ValidTrue()
8383
{
@@ -87,11 +87,11 @@ public void When_DataTypeTimeInArray_ValidTrue()
8787
""";
8888
var json =
8989
"""
90-
["0001-01-01T00:00:00.000Z", "9999-12-31T23:59:59.999+12:59"]
90+
["0001-01-01T00:00:00.0Z", "9999-12-31T23:59:59.999999+12:59"]
9191
""";
9292
JsonAssert.IsValid(schema, json);
9393
}
94-
94+
9595
[TestMethod]
9696
public void When_NestedDataTypeDateInArray_ValidTrue()
9797
{
@@ -105,7 +105,7 @@ public void When_NestedDataTypeDateInArray_ValidTrue()
105105
""";
106106
JsonAssert.IsValid(schema, json);
107107
}
108-
108+
109109
[TestMethod]
110110
public void When_NestedDataTypeTimeInArray_ValidTrue()
111111
{
@@ -119,7 +119,7 @@ public void When_NestedDataTypeTimeInArray_ValidTrue()
119119
""";
120120
JsonAssert.IsValid(schema, json);
121121
}
122-
122+
123123
[TestMethod]
124124
public void When_NestedDataTypeDateInObject_ValidTrue()
125125
{
@@ -136,7 +136,7 @@ public void When_NestedDataTypeDateInObject_ValidTrue()
136136
""";
137137
JsonAssert.IsValid(schema, json);
138138
}
139-
139+
140140
[TestMethod]
141141
public void When_NestedDataTypeTimeInObject_ValidTrue()
142142
{
@@ -153,7 +153,7 @@ public void When_NestedDataTypeTimeInObject_ValidTrue()
153153
""";
154154
JsonAssert.IsValid(schema, json);
155155
}
156-
156+
157157
[TestMethod]
158158
public void When_DateFunctionWithYearMonthDay1InObject_ValidTrue()
159159
{
@@ -187,7 +187,7 @@ public void When_DateFunctionWithYearMonthDay1InObject_ValidTrue()
187187
""";
188188
JsonAssert.IsValid(schema, json);
189189
}
190-
190+
191191
[TestMethod]
192192
public void When_DateFunctionWithYearMonthDay2InObject_ValidTrue()
193193
{
@@ -217,7 +217,7 @@ public void When_DateFunctionWithYearMonthDay2InObject_ValidTrue()
217217
""";
218218
JsonAssert.IsValid(schema, json);
219219
}
220-
220+
221221
[TestMethod]
222222
public void When_TimeFunctionWithHourMinuteSecondInObject_ValidTrue()
223223
{
@@ -249,7 +249,7 @@ public void When_TimeFunctionWithHourMinuteSecondInObject_ValidTrue()
249249
""";
250250
JsonAssert.IsValid(schema, json);
251251
}
252-
252+
253253
[TestMethod]
254254
public void When_TimeFunctionWithUtcOffsetInObject_ValidTrue()
255255
{
@@ -275,7 +275,7 @@ public void When_TimeFunctionWithUtcOffsetInObject_ValidTrue()
275275
""";
276276
JsonAssert.IsValid(schema, json);
277277
}
278-
278+
279279
[TestMethod]
280280
public void When_DateFunctionWithPartialDateInObject_ValidTrue()
281281
{
@@ -301,7 +301,7 @@ public void When_DateFunctionWithPartialDateInObject_ValidTrue()
301301
""";
302302
JsonAssert.IsValid(schema, json);
303303
}
304-
304+
305305
[TestMethod]
306306
public void When_TimeFunctionWithPartialTimeInObject_ValidTrue()
307307
{
@@ -327,7 +327,7 @@ public void When_TimeFunctionWithPartialTimeInObject_ValidTrue()
327327
""";
328328
JsonAssert.IsValid(schema, json);
329329
}
330-
330+
331331
[TestMethod]
332332
public void When_NestedDateFunctionInArray_ValidTrue()
333333
{
@@ -345,7 +345,7 @@ public void When_NestedDateFunctionInArray_ValidTrue()
345345
""";
346346
JsonAssert.IsValid(schema, json);
347347
}
348-
348+
349349
[TestMethod]
350350
public void When_NestedDateFunctionInObject_ValidTrue()
351351
{
@@ -363,7 +363,7 @@ public void When_NestedDateFunctionInObject_ValidTrue()
363363
""";
364364
JsonAssert.IsValid(schema, json);
365365
}
366-
366+
367367
[TestMethod]
368368
public void When_NestedTimeFunctionInArray_ValidTrue()
369369
{
@@ -381,7 +381,7 @@ public void When_NestedTimeFunctionInArray_ValidTrue()
381381
""";
382382
JsonAssert.IsValid(schema, json);
383383
}
384-
384+
385385
[TestMethod]
386386
public void When_NestedTimeFunctionInObject_ValidTrue()
387387
{

0 commit comments

Comments
 (0)