Skip to content

Commit

Permalink
Merge pull request #8 from relogiclabs/develop
Browse files Browse the repository at this point in the history
Refactor and Optimize Code
  • Loading branch information
zhossain-info authored Nov 2, 2023
2 parents db36fc9 + 4acf0de commit fc4b09e
Show file tree
Hide file tree
Showing 253 changed files with 833 additions and 1,138 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: './JsonSchema/docs'
path: './JsonSchema/doc'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
15 changes: 11 additions & 4 deletions JsonSchema.Tests/JsonSchema.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AssemblyName>RelogicLabs.JsonSchema.Tests</AssemblyName>
<Description>This project contains test cases for JsonSchema project.</Description>
<Authors>Relogic Labs</Authors>
<Company>Relogic Labs</Company>
<Version>1.7.0</Version>
<AssemblyVersion>1.7.0</AssemblyVersion>
<Copyright>Copyright © Relogic Labs. All rights reserved.</Copyright>
<NeutralLanguage>en</NeutralLanguage>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<AssemblyName>RelogicLabs.JsonSchema.Tests</AssemblyName>
<Company>Relogic Labs</Company>
<RootNamespace />
<RootNamespace>RelogicLabs</RootNamespace>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ public class DateTimeTests
public void When_JsonNotDate_ExceptionThrown()
{
var schema = "#date";
var json = "\"This is not a valid date\"";
var json = "\"This is not a date\"";

JsonSchema.IsValid(schema, json);
var exception = Assert.ThrowsException<JsonSchemaException>(
() => JsonAssert.IsValid(schema, json));
Assert.AreEqual(DTYP04, exception.Code);
Console.WriteLine(exception);
}

[TestMethod]
public void When_JsonNotValidDate_ExceptionThrown()
{
var schema = "#date";
var json = "\"1939-02-29\"";

JsonSchema.IsValid(schema, json);
var exception = Assert.ThrowsException<JsonSchemaException>(
Expand All @@ -23,7 +36,20 @@ public void When_JsonNotDate_ExceptionThrown()
public void When_JsonNotTime_ExceptionThrown()
{
var schema = "#time";
var json = "\"This is not a valid time\"";
var json = "\"This is not a time\"";

JsonSchema.IsValid(schema, json);
var exception = Assert.ThrowsException<JsonSchemaException>(
() => JsonAssert.IsValid(schema, json));
Assert.AreEqual(DTYP04, exception.Code);
Console.WriteLine(exception);
}

[TestMethod]
public void When_JsonNotValidTime_ExceptionThrown()
{
var schema = "#time";
var json = "\"1939-09-02T2:12:12.000Z\"";

JsonSchema.IsValid(schema, json);
var exception = Assert.ThrowsException<JsonSchemaException>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public void When_FunctionAppliedOnWrongType_ExceptionThrown()
"test"
""";

//JsonSchema.IsValid(schema, json);
var exception = Assert.ThrowsException<FunctionMismatchException>(
JsonSchema.IsValid(schema, json);
var exception = Assert.ThrowsException<JsonSchemaException>(
() => JsonAssert.IsValid(schema, json));
Assert.AreEqual(FUNC03, exception.Code);
Console.WriteLine(exception);
Expand All @@ -32,7 +32,7 @@ public void When_ExternalIncludeNotInheritBaseClass_ExceptionThrown()
var schema =
"""
%include: RelogicLabs.JsonSchema.Tests.Negative.ExternalFunctions1,
RelogicLabs.JsonSchema.Tests
RelogicLabs.JsonSchema.Tests
%schema: @odd #integer
""";
var json = "10";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ namespace RelogicLabs.JsonSchema.Tests.Positive;
[TestClass]
public class DateTimeTests
{

[TestMethod]
public void When_DataTypeDate_ValidTrue()
{
var schema = "#date";
var json = "\"2023-09-01\"";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_DataTypeTime_ValidTrue()
{
var schema = "#time";
var json = "\"2023-09-01T14:35:10.123+06:00\"";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_DataTypeDateInObject_ValidTrue()
{
Expand All @@ -41,7 +41,7 @@ public void When_DataTypeDateInObject_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_DataTypeTimeInObject_ValidTrue()
{
Expand All @@ -56,14 +56,14 @@ public void When_DataTypeTimeInObject_ValidTrue()
var json =
"""
{
"key1": "1950-12-31T11:40:10.000+06:30",
"key2": "0001-01-01T00:00:00.000+00:00",
"key3": "1600-02-29T23:59:59.999Z"
"key1": "1950-12-31T11:40:10.333+06:30",
"key2": "0001-01-01T00:00:00.0+00:00",
"key3": "1600-02-29T23:59:59.99999Z"
}
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_DataTypeDateInArray_ValidTrue()
{
Expand All @@ -77,7 +77,7 @@ public void When_DataTypeDateInArray_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_DataTypeTimeInArray_ValidTrue()
{
Expand All @@ -87,11 +87,11 @@ public void When_DataTypeTimeInArray_ValidTrue()
""";
var json =
"""
["0001-01-01T00:00:00.000Z", "9999-12-31T23:59:59.999+12:59"]
["0001-01-01T00:00:00.0Z", "9999-12-31T23:59:59.999999+12:59"]
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_NestedDataTypeDateInArray_ValidTrue()
{
Expand All @@ -105,7 +105,7 @@ public void When_NestedDataTypeDateInArray_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_NestedDataTypeTimeInArray_ValidTrue()
{
Expand All @@ -119,7 +119,7 @@ public void When_NestedDataTypeTimeInArray_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_NestedDataTypeDateInObject_ValidTrue()
{
Expand All @@ -136,7 +136,7 @@ public void When_NestedDataTypeDateInObject_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_NestedDataTypeTimeInObject_ValidTrue()
{
Expand All @@ -153,7 +153,7 @@ public void When_NestedDataTypeTimeInObject_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_DateFunctionWithYearMonthDay1InObject_ValidTrue()
{
Expand Down Expand Up @@ -187,7 +187,7 @@ public void When_DateFunctionWithYearMonthDay1InObject_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_DateFunctionWithYearMonthDay2InObject_ValidTrue()
{
Expand Down Expand Up @@ -217,7 +217,7 @@ public void When_DateFunctionWithYearMonthDay2InObject_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_TimeFunctionWithHourMinuteSecondInObject_ValidTrue()
{
Expand Down Expand Up @@ -249,7 +249,7 @@ public void When_TimeFunctionWithHourMinuteSecondInObject_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_TimeFunctionWithUtcOffsetInObject_ValidTrue()
{
Expand All @@ -275,7 +275,7 @@ public void When_TimeFunctionWithUtcOffsetInObject_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_DateFunctionWithPartialDateInObject_ValidTrue()
{
Expand All @@ -301,7 +301,7 @@ public void When_DateFunctionWithPartialDateInObject_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_TimeFunctionWithPartialTimeInObject_ValidTrue()
{
Expand All @@ -327,7 +327,7 @@ public void When_TimeFunctionWithPartialTimeInObject_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_NestedDateFunctionInArray_ValidTrue()
{
Expand All @@ -345,7 +345,7 @@ public void When_NestedDateFunctionInArray_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_NestedDateFunctionInObject_ValidTrue()
{
Expand All @@ -363,7 +363,7 @@ public void When_NestedDateFunctionInObject_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_NestedTimeFunctionInArray_ValidTrue()
{
Expand All @@ -381,7 +381,7 @@ public void When_NestedTimeFunctionInArray_ValidTrue()
""";
JsonAssert.IsValid(schema, json);
}

[TestMethod]
public void When_NestedTimeFunctionInObject_ValidTrue()
{
Expand Down
19 changes: 10 additions & 9 deletions JsonSchema/JsonSchema.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
<Description>New JSON Schema prioritizes simplicity, conciseness, readability, and efficiency.
It offers precise JSON document definition through ample functionalities and extensibility
to meet the diverse web service requirements.</Description>
<AssemblyName>RelogicLabs.JsonSchema</AssemblyName>
<Authors>Relogic Labs</Authors>
<Company>Relogic Labs</Company>
<Version>1.6.0</Version>
<PackageVersion>1.6.0</PackageVersion>
<AssemblyVersion>1.6.0</AssemblyVersion>
<Version>1.7.0</Version>
<PackageVersion>1.7.0</PackageVersion>
<AssemblyVersion>1.7.0</AssemblyVersion>
<PackageTags>JsonSchema;Schema;Json;Validation;Assert;Test</PackageTags>
<Copyright>Copyright © Relogic Labs. All rights reserved.</Copyright>
<NeutralLanguage>en</NeutralLanguage>
<AssemblyName>RelogicLabs.JsonSchema</AssemblyName>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>RelogicLabs</RootNamespace>
Expand All @@ -28,6 +28,7 @@
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -38,8 +39,8 @@
</AssemblyAttribute>
<None Include="resources\icon.png" Pack="true" PackagePath="\"/>
<None Include="..\README.md" Pack="true" PackagePath="\"/>
<Compile Remove="docs\**"/>
<EmbeddedResource Remove="docs\**"/>
<None Remove="docs\**"/>
<Compile Remove="doc\**"/>
<EmbeddedResource Remove="doc\**"/>
<None Remove="doc\**"/>
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion JsonSchema/RelogicLabs/JsonSchema/Collections/IKeyer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace RelogicLabs.JsonSchema.Collections;

public interface IKeyer<TK>
public interface IKeyer<out TK>
{
TK GetKey();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace RelogicLabs.JsonSchema.Collections;

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

public IIndexMap<TK, TV> AsReadOnly()
{
if(IsReadOnly) return this;
_list = new ReadOnlyCollection<TV>(_list);
_dictionary = new ReadOnlyDictionary<TK, TV>(_dictionary);
return this;
Expand Down

This file was deleted.

Loading

0 comments on commit fc4b09e

Please sign in to comment.