Skip to content

Commit c51662f

Browse files
committed
Merge pull request #1 from relogiclabs/develop
Implement New Json Schema
2 parents 3ab9fc4 + 3c8b422 commit c51662f

File tree

320 files changed

+48479
-1
lines changed

Some content is hidden

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

320 files changed

+48479
-1
lines changed

.gitattributes

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

.github/workflows/static.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Workflow for deploying static content to GitHub Pages
2+
name: Deploy Documentations to GitHub Pages
3+
4+
on:
5+
# Runs on pushes targeting the default branch
6+
push:
7+
branches: ["master"]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
deploy:
26+
environment:
27+
name: github-pages
28+
url: ${{ steps.deployment.outputs.page_url }}
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v3
33+
- name: Setup Pages
34+
uses: actions/configure-pages@v3
35+
- name: Upload artifact
36+
uses: actions/upload-pages-artifact@v2
37+
with:
38+
path: './JsonSchema/docs'
39+
- name: Deploy to GitHub Pages
40+
id: deployment
41+
uses: actions/deploy-pages@v2

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.idea/*
2+
/JsonSchema/bin/*
3+
/JsonSchema/obj/*
4+
/JsonSchema/.vscode/*
5+
/JsonSchema.Tests/bin/*
6+
/JsonSchema.Tests/obj/*
7+
/JsonSchema.Tests/.vscode/*
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
<AssemblyName>RelogicLabs.JsonSchema.Tests</AssemblyName>
9+
<Company>Relogic Labs</Company>
10+
<RootNamespace/>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
15+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
16+
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
17+
<PackageReference Include="coverlet.collector" Version="3.1.2" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\JsonSchema\JsonSchema.csproj" />
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
using RelogicLabs.JsonSchema.Exceptions;
2+
using static RelogicLabs.JsonSchema.Message.ErrorCode;
3+
4+
namespace RelogicLabs.JsonSchema.Tests.Negative;
5+
6+
[TestClass]
7+
public class ArrayTests
8+
{
9+
[TestMethod]
10+
public void When_JsonNotArray_ExceptionThrown()
11+
{
12+
var schema = "#array";
13+
var json = "10";
14+
15+
JsonSchema.IsValid(schema, json);
16+
var exception = Assert.ThrowsException<JsonSchemaException>(
17+
() => JsonAssert.IsValid(schema, json));
18+
Assert.AreEqual(DTYP02, exception.ErrorCode);
19+
Console.WriteLine(exception);
20+
}
21+
22+
[TestMethod]
23+
public void When_JsonNotArrayInObject_ExceptionThrown()
24+
{
25+
var schema =
26+
"""
27+
{
28+
"key1": #array,
29+
"key2": #array,
30+
"key3": #array
31+
}
32+
""";
33+
var json =
34+
"""
35+
{
36+
"key1": "value1",
37+
"key2": {"key": "value"},
38+
"key3": 100000
39+
}
40+
""";
41+
42+
JsonSchema.IsValid(schema, json);
43+
var exception = Assert.ThrowsException<JsonSchemaException>(
44+
() => JsonAssert.IsValid(schema, json));
45+
Assert.AreEqual(DTYP02, exception.ErrorCode);
46+
Console.WriteLine(exception);
47+
}
48+
49+
[TestMethod]
50+
public void When_JsonNotArrayInArray_ExceptionThrown()
51+
{
52+
var schema =
53+
"""
54+
[#array, #array, #array]
55+
""";
56+
var json =
57+
"""
58+
[{}, "value1", 10.5]
59+
""";
60+
61+
JsonSchema.IsValid(schema, json);
62+
var exception = Assert.ThrowsException<JsonSchemaException>(
63+
() => JsonAssert.IsValid(schema, json));
64+
Assert.AreEqual(DTYP02, exception.ErrorCode);
65+
Console.WriteLine(exception);
66+
}
67+
68+
[TestMethod]
69+
public void When_NestedJsonNotArrayInArray_ExceptionThrown()
70+
{
71+
var schema =
72+
"""
73+
#array*
74+
""";
75+
var json =
76+
"""
77+
[true, "value1", false]
78+
""";
79+
80+
JsonSchema.IsValid(schema, json);
81+
var exception = Assert.ThrowsException<JsonSchemaException>(
82+
() => JsonAssert.IsValid(schema, json));
83+
Assert.AreEqual(DTYP02, exception.ErrorCode);
84+
Console.WriteLine(exception);
85+
}
86+
87+
[TestMethod]
88+
public void When_NestedJsonNotArrayInObject_ExceptionThrown()
89+
{
90+
var schema =
91+
"""
92+
#array*
93+
""";
94+
var json =
95+
"""
96+
{
97+
"key1": 10.11,
98+
"key2": true,
99+
"key3": "value1"
100+
}
101+
""";
102+
103+
JsonSchema.IsValid(schema, json);
104+
var exception = Assert.ThrowsException<JsonSchemaException>(
105+
() => JsonAssert.IsValid(schema, json));
106+
Assert.AreEqual(DTYP02, exception.ErrorCode);
107+
Console.WriteLine(exception);
108+
}
109+
110+
[TestMethod]
111+
public void When_ElementsWithWrongArray_ExceptionThrown()
112+
{
113+
var schema = "@elements(10, 20, 30, 40) #array";
114+
var json = "[5, 10, 15, 20, 25]";
115+
116+
JsonSchema.IsValid(schema, json);
117+
var exception = Assert.ThrowsException<JsonSchemaException>(
118+
() => JsonAssert.IsValid(schema, json));
119+
Assert.AreEqual(ELEM01, exception.ErrorCode);
120+
Console.WriteLine(exception);
121+
}
122+
123+
[TestMethod]
124+
public void When_NestedElementsWithWrongArrayInArray_ExceptionThrown()
125+
{
126+
var schema = "@elements*(5, 10) #array";
127+
var json = "[[5, 10], [], [5, 10, 15, 20]]";
128+
129+
JsonSchema.IsValid(schema, json);
130+
var exception = Assert.ThrowsException<JsonSchemaException>(
131+
() => JsonAssert.IsValid(schema, json));
132+
Assert.AreEqual(ELEM01, exception.ErrorCode);
133+
Console.WriteLine(exception);
134+
}
135+
136+
[TestMethod]
137+
public void When_EnumWithWrongValueInArray_ExceptionThrown()
138+
{
139+
var schema =
140+
"""
141+
[
142+
@enum(5, 10, 15),
143+
@enum(100, 150, 200),
144+
@enum("abc", "pqr", "xyz")
145+
] #array
146+
""";
147+
var json = """[11, 102, "efg"]""";
148+
149+
JsonSchema.IsValid(schema, json);
150+
var exception = Assert.ThrowsException<JsonSchemaException>(
151+
() => JsonAssert.IsValid(schema, json));
152+
Assert.AreEqual(ENUM02, exception.ErrorCode);
153+
Console.WriteLine(exception);
154+
}
155+
156+
[TestMethod]
157+
public void When_InvalidJsonInArray_ExceptionThrown()
158+
{
159+
var schema = "#array";
160+
var json = "[,,]";
161+
162+
//JsonSchema.IsValid(schema, json);
163+
var exception = Assert.ThrowsException<JsonParserException>(
164+
() => JsonAssert.IsValid(schema, json));
165+
Assert.AreEqual(JPRS01, exception.ErrorCode);
166+
Console.WriteLine(exception);
167+
}
168+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using RelogicLabs.JsonSchema.Exceptions;
2+
using static RelogicLabs.JsonSchema.Message.ErrorCode;
3+
4+
namespace RelogicLabs.JsonSchema.Tests.Negative;
5+
6+
[TestClass]
7+
public class BooleanTests
8+
{
9+
[TestMethod]
10+
public void When_JsonNotBoolean_ExceptionThrown()
11+
{
12+
var schema = "#boolean";
13+
var json = "5";
14+
15+
JsonSchema.IsValid(schema, json);
16+
var exception = Assert.ThrowsException<JsonSchemaException>(
17+
() => JsonAssert.IsValid(schema, json));
18+
Assert.AreEqual(DTYP02, exception.ErrorCode);
19+
Console.WriteLine(exception);
20+
}
21+
22+
[TestMethod]
23+
public void When_JsonValueNotEqualForBoolean_ExceptionThrown()
24+
{
25+
var schema = "true #boolean";
26+
var json = "false";
27+
28+
JsonSchema.IsValid(schema, json);
29+
var exception = Assert.ThrowsException<JsonSchemaException>(
30+
() => JsonAssert.IsValid(schema, json));
31+
Assert.AreEqual(BOOL01, exception.ErrorCode);
32+
Console.WriteLine(exception);
33+
}
34+
35+
[TestMethod]
36+
public void When_JsonNotBooleanInObject_ExceptionThrown()
37+
{
38+
var schema =
39+
"""
40+
{
41+
"key1": #boolean,
42+
"key2": #boolean,
43+
"key3": #boolean
44+
}
45+
""";
46+
var json =
47+
"""
48+
{
49+
"key1": null,
50+
"key2": 10.5,
51+
"key3": true
52+
}
53+
""";
54+
55+
JsonSchema.IsValid(schema, json);
56+
var exception = Assert.ThrowsException<JsonSchemaException>(
57+
() => JsonAssert.IsValid(schema, json));
58+
Assert.AreEqual(DTYP02, exception.ErrorCode);
59+
Console.WriteLine(exception);
60+
}
61+
62+
[TestMethod]
63+
public void When_JsonNotBooleanInArray_ExceptionThrown()
64+
{
65+
var schema =
66+
"""
67+
[#boolean, #boolean, #boolean]
68+
""";
69+
var json =
70+
"""
71+
[[], 11.5, "false"]
72+
""";
73+
74+
JsonSchema.IsValid(schema, json);
75+
var exception = Assert.ThrowsException<JsonSchemaException>(
76+
() => JsonAssert.IsValid(schema, json));
77+
Assert.AreEqual(DTYP02, exception.ErrorCode);
78+
Console.WriteLine(exception);
79+
}
80+
81+
[TestMethod]
82+
public void When_NestedJsonNotBooleanInArray_ExceptionThrown()
83+
{
84+
var schema =
85+
"""
86+
#boolean*
87+
""";
88+
var json =
89+
"""
90+
["true", {}, [true]]
91+
""";
92+
93+
JsonSchema.IsValid(schema, json);
94+
var exception = Assert.ThrowsException<JsonSchemaException>(
95+
() => JsonAssert.IsValid(schema, json));
96+
Assert.AreEqual(DTYP02, exception.ErrorCode);
97+
Console.WriteLine(exception);
98+
}
99+
100+
[TestMethod]
101+
public void When_NestedJsonNotBooleanInObject_ExceptionThrown()
102+
{
103+
var schema =
104+
"""
105+
#boolean*
106+
""";
107+
var json =
108+
"""
109+
{
110+
"key1": {"key": true},
111+
"key2": null,
112+
"key3": false
113+
}
114+
""";
115+
116+
JsonSchema.IsValid(schema, json);
117+
var exception = Assert.ThrowsException<JsonSchemaException>(
118+
() => JsonAssert.IsValid(schema, json));
119+
Assert.AreEqual(DTYP02, exception.ErrorCode);
120+
Console.WriteLine(exception);
121+
}
122+
}

0 commit comments

Comments
 (0)