-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from gregsdennis/schema/configurable-error-me…
…ssages Schema/configurable error messages
- Loading branch information
Showing
60 changed files
with
1,570 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Globalization; | ||
using System.Text.Json; | ||
using NUnit.Framework; | ||
|
||
namespace Json.Schema.Tests; | ||
|
||
public class LocalizationTests | ||
{ | ||
[Test] | ||
public void MinimumReturnsDefaultErrorMessage() | ||
{ | ||
JsonSchema schema = new JsonSchemaBuilder() | ||
.Type(SchemaValueType.Number) | ||
.Minimum(10); | ||
|
||
var instance = JsonDocument.Parse("5"); | ||
|
||
var results = schema.Validate(instance.RootElement, new ValidationOptions { OutputFormat = OutputFormat.Basic }); | ||
|
||
var message = results.Message; | ||
|
||
Assert.AreEqual("5 is less than or equal to 10", message); | ||
} | ||
|
||
[Test] | ||
public void MinimumReturnsDefaultErrorMessageButInSpanish() | ||
{ | ||
try | ||
{ | ||
ErrorMessages.Culture = CultureInfo.GetCultureInfo("es"); | ||
|
||
JsonSchema schema = new JsonSchemaBuilder() | ||
.Type(SchemaValueType.Number) | ||
.Minimum(10); | ||
|
||
var instance = JsonDocument.Parse("5"); | ||
|
||
var results = schema.Validate(instance.RootElement, new ValidationOptions { OutputFormat = OutputFormat.Basic }); | ||
|
||
var message = results.Message; | ||
|
||
Assert.AreEqual("5 es menor o igual que 10", message); | ||
} | ||
finally | ||
{ | ||
ErrorMessages.Culture = null; | ||
} | ||
} | ||
|
||
[Test] | ||
public void MinimumReturnsCustomErrorMessage() | ||
{ | ||
try | ||
{ | ||
ErrorMessages.Minimum = "This is a custom error message with [[received]] and [[limit]]"; | ||
|
||
JsonSchema schema = new JsonSchemaBuilder() | ||
.Type(SchemaValueType.Number) | ||
.Minimum(10); | ||
|
||
var instance = JsonDocument.Parse("5"); | ||
|
||
var results = schema.Validate(instance.RootElement, new ValidationOptions { OutputFormat = OutputFormat.Basic }); | ||
|
||
var message = results.Message; | ||
|
||
Assert.AreEqual("This is a custom error message with 5 and 10", message); | ||
} | ||
finally | ||
{ | ||
ErrorMessages.Minimum = null!; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.