513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
117 lines
4.9 KiB
C#
117 lines
4.9 KiB
C#
using ZB.MOM.WW.ScadaBridge.CentralUI.ScriptAnalysis;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.ScriptAnalysis;
|
|
|
|
public class JsonSchemaShapeParserTests
|
|
{
|
|
// ── JSON Schema (post-migration) ─────────────────────────────────────────
|
|
|
|
/// <summary>Verifies that a JSON schema parses into scalar parameters with their required flags.</summary>
|
|
[Fact]
|
|
public void Parameters_JsonSchema_ScalarsAndRequired()
|
|
{
|
|
const string json = """
|
|
{"type":"object","properties":{
|
|
"id":{"type":"integer"},
|
|
"label":{"type":"string"},
|
|
"active":{"type":"boolean"}
|
|
},"required":["id","active"]}
|
|
""";
|
|
var result = JsonSchemaShapeParser.ParseParameters(json);
|
|
|
|
Assert.Collection(result,
|
|
p => { Assert.Equal("id", p.Name); Assert.Equal("Integer", p.Type); Assert.True(p.Required); },
|
|
p => { Assert.Equal("label", p.Name); Assert.Equal("String", p.Type); Assert.False(p.Required); },
|
|
p => { Assert.Equal("active", p.Name); Assert.Equal("Boolean", p.Type); Assert.True(p.Required); });
|
|
}
|
|
|
|
/// <summary>Verifies that a JSON schema array of strings becomes a list of strings.</summary>
|
|
[Fact]
|
|
public void Parameters_JsonSchema_ArrayOfStringsBecomesListString()
|
|
{
|
|
const string json = """
|
|
{"type":"object","properties":{
|
|
"tags":{"type":"array","items":{"type":"string"}}
|
|
}}
|
|
""";
|
|
var result = JsonSchemaShapeParser.ParseParameters(json);
|
|
|
|
var tags = Assert.Single(result);
|
|
Assert.Equal("tags", tags.Name);
|
|
Assert.Equal("List<String>", tags.Type);
|
|
Assert.False(tags.Required);
|
|
}
|
|
|
|
/// <summary>Verifies that a JSON schema number return type parses as a number.</summary>
|
|
[Fact]
|
|
public void Return_JsonSchema_Number()
|
|
{
|
|
Assert.Equal("Float", JsonSchemaShapeParser.ParseReturnType(@"{""type"":""number""}"));
|
|
}
|
|
|
|
/// <summary>Verifies that a JSON schema array of integers return type parses as a list of integers.</summary>
|
|
[Fact]
|
|
public void Return_JsonSchema_ArrayOfIntegers()
|
|
{
|
|
Assert.Equal("List<Integer>",
|
|
JsonSchemaShapeParser.ParseReturnType(@"{""type"":""array"",""items"":{""type"":""integer""}}"));
|
|
}
|
|
|
|
// ── Legacy flat shape (pre-migration safety net) ─────────────────────────
|
|
|
|
/// <summary>Verifies that the legacy flat array parameter format still parses.</summary>
|
|
[Fact]
|
|
public void Parameters_Legacy_FlatArrayStillParses()
|
|
{
|
|
const string json = """[{"name":"x","type":"Integer"},{"name":"y","type":"String","required":false}]""";
|
|
var result = JsonSchemaShapeParser.ParseParameters(json);
|
|
|
|
Assert.Collection(result,
|
|
p => { Assert.Equal("x", p.Name); Assert.Equal("Integer", p.Type); Assert.True(p.Required); },
|
|
p => { Assert.Equal("y", p.Name); Assert.Equal("String", p.Type); Assert.False(p.Required); });
|
|
}
|
|
|
|
/// <summary>Verifies that the legacy list sentinel return format still parses.</summary>
|
|
[Fact]
|
|
public void Return_Legacy_ListSentinelStillParses()
|
|
{
|
|
Assert.Equal("List<String>",
|
|
JsonSchemaShapeParser.ParseReturnType(@"{""type"":""List"",""itemType"":""String""}"));
|
|
}
|
|
|
|
// ── Edge cases ────────────────────────────────────────────────────────────
|
|
|
|
/// <summary>Verifies that null parameters yield an empty list.</summary>
|
|
[Fact]
|
|
public void Parameters_Null_ReturnsEmpty()
|
|
{
|
|
Assert.Empty(JsonSchemaShapeParser.ParseParameters(null));
|
|
Assert.Empty(JsonSchemaShapeParser.ParseParameters(""));
|
|
Assert.Empty(JsonSchemaShapeParser.ParseParameters(" "));
|
|
}
|
|
|
|
/// <summary>Verifies that malformed parameters yield an empty list.</summary>
|
|
[Fact]
|
|
public void Parameters_Malformed_ReturnsEmpty()
|
|
{
|
|
Assert.Empty(JsonSchemaShapeParser.ParseParameters("{not json"));
|
|
Assert.Empty(JsonSchemaShapeParser.ParseParameters("42"));
|
|
}
|
|
|
|
/// <summary>Verifies that a null return definition yields null.</summary>
|
|
[Fact]
|
|
public void Return_Null_ReturnsNull()
|
|
{
|
|
Assert.Null(JsonSchemaShapeParser.ParseReturnType(null));
|
|
Assert.Null(JsonSchemaShapeParser.ParseReturnType(""));
|
|
}
|
|
|
|
/// <summary>Verifies that a schema with no properties yields an empty parameter list.</summary>
|
|
[Fact]
|
|
public void Parameters_SchemaWithNoProperties_ReturnsEmpty()
|
|
{
|
|
Assert.Empty(JsonSchemaShapeParser.ParseParameters(@"{""type"":""object""}"));
|
|
Assert.Empty(JsonSchemaShapeParser.ParseParameters(@"{""type"":""object"",""properties"":{}}"));
|
|
}
|
|
}
|