Skip to content

Commit ff8d2da

Browse files
committed
Merge pull request #8 from relogiclabs/develop
Refactor and Optimize Code
2 parents db36fc9 + 4acf0de commit ff8d2da

File tree

254 files changed

+834
-1139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

254 files changed

+834
-1139
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
JsonSchema/docs/** linguist-documentation
1+
JsonSchema/doc/** linguist-documentation

.github/workflows/static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Upload artifact
3636
uses: actions/upload-pages-artifact@v2
3737
with:
38-
path: './JsonSchema/docs'
38+
path: './JsonSchema/doc'
3939
- name: Deploy to GitHub Pages
4040
id: deployment
4141
uses: actions/deploy-pages@v2

JsonSchema.Tests/JsonSchema.Tests.csproj

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
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+
<AssemblyVersion>1.7.0</AssemblyVersion>
10+
<Copyright>Copyright © Relogic Labs. All rights reserved.</Copyright>
11+
<NeutralLanguage>en</NeutralLanguage>
12+
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
513
<ImplicitUsings>enable</ImplicitUsings>
614
<Nullable>enable</Nullable>
715
<IsPackable>false</IsPackable>
8-
<AssemblyName>RelogicLabs.JsonSchema.Tests</AssemblyName>
9-
<Company>Relogic Labs</Company>
10-
<RootNamespace />
16+
<RootNamespace>RelogicLabs</RootNamespace>
17+
<LangVersion>preview</LangVersion>
1118
</PropertyGroup>
1219

1320
<ItemGroup>

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
{

JsonSchema/JsonSchema.csproj

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
<Description>New JSON Schema prioritizes simplicity, conciseness, readability, and efficiency.
66
It offers precise JSON document definition through ample functionalities and extensibility
77
to meet the diverse web service requirements.</Description>
8+
<AssemblyName>RelogicLabs.JsonSchema</AssemblyName>
89
<Authors>Relogic Labs</Authors>
910
<Company>Relogic Labs</Company>
10-
<Version>1.6.0</Version>
11-
<PackageVersion>1.6.0</PackageVersion>
12-
<AssemblyVersion>1.6.0</AssemblyVersion>
11+
<Version>1.7.0</Version>
12+
<PackageVersion>1.7.0</PackageVersion>
13+
<AssemblyVersion>1.7.0</AssemblyVersion>
1314
<PackageTags>JsonSchema;Schema;Json;Validation;Assert;Test</PackageTags>
1415
<Copyright>Copyright © Relogic Labs. All rights reserved.</Copyright>
1516
<NeutralLanguage>en</NeutralLanguage>
16-
<AssemblyName>RelogicLabs.JsonSchema</AssemblyName>
17-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
17+
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
1818
<ImplicitUsings>enable</ImplicitUsings>
1919
<Nullable>enable</Nullable>
2020
<RootNamespace>RelogicLabs</RootNamespace>
@@ -28,6 +28,7 @@
2828
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
2929
<IncludeSymbols>true</IncludeSymbols>
3030
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
31+
<LangVersion>preview</LangVersion>
3132
</PropertyGroup>
3233

3334
<ItemGroup>
@@ -38,8 +39,8 @@
3839
</AssemblyAttribute>
3940
<None Include="resources\icon.png" Pack="true" PackagePath="\"/>
4041
<None Include="..\README.md" Pack="true" PackagePath="\"/>
41-
<Compile Remove="docs\**"/>
42-
<EmbeddedResource Remove="docs\**"/>
43-
<None Remove="docs\**"/>
42+
<Compile Remove="doc\**"/>
43+
<EmbeddedResource Remove="doc\**"/>
44+
<None Remove="doc\**"/>
4445
</ItemGroup>
45-
</Project>
46+
</Project>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace RelogicLabs.JsonSchema.Collections;
22

3-
public interface IKeyer<TK>
3+
public interface IKeyer<out TK>
44
{
55
TK GetKey();
66
}

JsonSchema/RelogicLabs/JsonSchema/Collections/IndexHashMap.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace RelogicLabs.JsonSchema.Collections;
55

6-
public class IndexHashMap<TK, TV> : IIndexMap<TK, TV>
6+
public sealed class IndexHashMap<TK, TV> : IIndexMap<TK, TV>
77
where TV : IKeyer<TK> where TK : notnull
88
{
99
private IDictionary<TK, TV> _dictionary;
@@ -71,6 +71,7 @@ public bool TryGetValue(TK key, out TV? value)
7171

7272
public IIndexMap<TK, TV> AsReadOnly()
7373
{
74+
if(IsReadOnly) return this;
7475
_list = new ReadOnlyCollection<TV>(_list);
7576
_dictionary = new ReadOnlyDictionary<TK, TV>(_dictionary);
7677
return this;

JsonSchema/RelogicLabs/JsonSchema/Exceptions/FunctionMismatchException.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)