-
-
Notifications
You must be signed in to change notification settings - Fork 535
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 #793 from RSuter/master
Release v9.11.1
- Loading branch information
Showing
10 changed files
with
434 additions
and
137 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,62 @@ | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace NJsonSchema.Tests.Validation | ||
{ | ||
public class OneOfValidationTests | ||
{ | ||
private string example_schema = @"{ | ||
""type"": ""object"", | ||
""properties"": { | ||
""A"": { ""type"": ""string"" }, | ||
""B"": { ""type"": ""integer"" }, | ||
""C"": { ""type"": ""number"" } | ||
}, | ||
""required"": [""A""], | ||
""additionalProperties"": false, | ||
""oneOf"": [ | ||
{ | ||
""required"": [""B""] | ||
}, | ||
{ | ||
""required"": [""C""] | ||
} | ||
] | ||
}"; | ||
|
||
[Fact] | ||
public async Task When_has_one_of_then_it_is_validated_correctly() | ||
{ | ||
var schema = await JsonSchema4.FromJsonAsync(example_schema); | ||
var matches = new string[] { @"{ ""A"": ""string"", ""B"": 3 }", | ||
@"{ ""A"": ""string"", ""C"": 2 }" }; | ||
|
||
foreach (var match in matches) | ||
{ | ||
var errors = schema.Validate(match); | ||
|
||
Assert.Equal(0, errors.Count); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task When_does_not_have_one_of_then_it_is_invalid() | ||
{ | ||
var schema = await JsonSchema4.FromJsonAsync(example_schema); | ||
|
||
var errors = schema.Validate(@"{ ""A"": ""string"" }"); | ||
|
||
Assert.Equal(1, errors.Count); | ||
} | ||
|
||
[Fact] | ||
public async Task When_has_more_than_one_of_then_it_is_invalid() | ||
{ | ||
var schema = await JsonSchema4.FromJsonAsync(example_schema); | ||
|
||
var errors = schema.Validate(@"{ ""A"": ""string"", ""B"": 1, ""C"": 2 }"); | ||
|
||
Assert.Equal(1, errors.Count); | ||
} | ||
} | ||
} |
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