-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTestJsonSchemaGeneration.cs
69 lines (62 loc) · 2.14 KB
/
TestJsonSchemaGeneration.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Linq;
using BO4E.BO;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Schema;
namespace TestBO4E;
[TestClass]
public class TestJsonSchemaGeneration
{
[TestMethod]
public void BasicTest()
{
var melo = new Messlokation();
var result = melo.GetJsonScheme().ToString();
var em = new Energiemenge();
result = em.GetJsonScheme().ToString();
var result2 = BusinessObject.GetJsonSchema(typeof(Energiemenge)).ToString();
Assert.AreEqual(result, result2);
}
[TestMethod]
public void NegativeTest()
{
Assert.ThrowsException<ArgumentException>(
() => BusinessObject.GetJsonSchema(typeof(string)),
"Illegal types must result in a ArgumentException."
);
}
private const int LastDataRowOffset = 50;
private const int MaxSchemasPerHour = 10;
[TestMethod]
[DataRow(0)]
[DataRow(10)]
[DataRow(20)]
[DataRow(30)]
[DataRow(40)]
[DataRow(LastDataRowOffset)] // using these different data rows allows you to workaround the 10schema per hour limitation (MaxSchemasPerHour)
public void TestJSchemaFileGenerationBo(int offset)
{
var relevantBusinessObjectTypes = typeof(BusinessObject)
.Assembly.GetTypes()
.Where(t => t.IsSubclassOf(typeof(BusinessObject)));
relevantBusinessObjectTypes
.Count()
.Should()
.BeLessThan(LastDataRowOffset + MaxSchemasPerHour); // if this fails, add another data row to this test method
try // generate plain json schemas
{
foreach (var type in relevantBusinessObjectTypes.Skip(offset).Take(MaxSchemasPerHour))
{
var schema = BusinessObject.GetJsonSchema(type);
Assert.IsNotNull(schema);
// writing the schemas has moved to the SchemaGenerator project/generate-json-schemas.sh
}
}
catch (JSchemaException jse)
{
Console.Out.WriteLine(jse.Message);
// thats life. pay for it if you'd like to :P
}
}
}