-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathSchemaTests.cs
52 lines (37 loc) · 1.44 KB
/
SchemaTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using Newtonsoft.Json.Schema;
namespace SchemaTesting.UnitTest;
public class SchemaTests
{
private readonly ISchemaReader _schemaReader;
public SchemaTests()
{
this._schemaReader = new LocalDiskSchemaReader();
}
[Fact]
public async Task EventPayloadMatchesSchema_ShouldPass()
{
// Initial test to check success
var sampleEventJson = await SampleEventReader.ParseRawJsonFromEventVersion("1.0.0");
var schema = await this._schemaReader.ReadJsonSchemaAsync("1.0.0");
var isValid = sampleEventJson.IsValid(schema);
isValid.Should().BeTrue();
}
[Fact]
public async Task AdditionalOptionalPropertiesAdded_ShouldPass()
{
// Schema version 1.1.0 adds an additional email property
var sampleEventJson = await SampleEventReader.ParseRawJsonFromEventVersion("1.1.0");
var schema = await this._schemaReader.ReadJsonSchemaAsync("1.0.0");
var isValid = sampleEventJson.IsValid(schema);
isValid.Should().BeTrue();
}
[Fact]
public async Task RemoveElementsFromPayload_ShouldFail()
{
// Schema version 1.2.0 removes the address property
var sampleEventJson = await SampleEventReader.ParseRawJsonFromEventVersion("1.2.0");
var schema = await this._schemaReader.ReadJsonSchemaAsync("1.0.0");
var isValid = sampleEventJson.IsValid(schema);
isValid.Should().BeFalse();
}
}