зеркало из https://github.com/microsoft/Forge.git
use linked rules instead of single dictionary rule, modify two origin rules file, and fix the tests.
This commit is contained in:
Родитель
f5d1a07472
Коммит
6d8e6556f3
|
@ -1,27 +1,10 @@
|
|||
{
|
||||
"Tree": {
|
||||
"Root": {
|
||||
"Type": "Action",
|
||||
"Actions": {
|
||||
"Root_CollectDiagnosticsAction": {
|
||||
"Action": "CollectDiagnosticsAction",
|
||||
"Input": {
|
||||
"Command": "TheCommand"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ChildSelector": [
|
||||
{
|
||||
"Child": "LeafNodeSummaryTest",
|
||||
"Lable": "Lable"
|
||||
}
|
||||
]
|
||||
},
|
||||
"LeafNodeSummaryTest": {
|
||||
"Type": "Leaf",
|
||||
"Actions": {
|
||||
"LeafNodeSummaryTest_LeafNodeSummaryAction": {
|
||||
"Action": "NoInputAction"
|
||||
"LeafActionWithoutRequiredActionInput": {
|
||||
"Action": "LeafNodeSummaryAction"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace Microsoft.Forge.TreeWalker.UnitTests
|
|||
private string schemaDirectoryPath;
|
||||
private string stringRules;
|
||||
private string rulesForDictionary;
|
||||
private JSchema linkedRulesForDictionary;
|
||||
private JSchema jschemaRules;
|
||||
private string invalidSchemaDirectoryPath;
|
||||
private string invalidSchemaWithErrorContent;
|
||||
|
@ -41,6 +42,7 @@ namespace Microsoft.Forge.TreeWalker.UnitTests
|
|||
schemaDirectoryPath = Path.Combine(Environment.CurrentDirectory, "test\\ExampleSchemas");
|
||||
stringRules = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "contracts\\ForgeSchemaValidationRules.json"));
|
||||
rulesForDictionary = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "contracts\\ForgeSchemaDictionaryValidationRules.json"));
|
||||
linkedRulesForDictionary = ForgeSchemaValidator.GetLinkedJSchemaRules(rulesForDictionary, stringRules, "//ForgeSchemaValidationRules.json");
|
||||
jschemaRules = JSchema.Parse(stringRules);
|
||||
forgeTreeAsString = File.ReadAllText(forgeTreeFromPath);
|
||||
forgeTreeDictionaryAsString = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "test\\ExampleSchemas\\SubroutineSchema.json"));
|
||||
|
@ -58,8 +60,9 @@ namespace Microsoft.Forge.TreeWalker.UnitTests
|
|||
{
|
||||
try
|
||||
{
|
||||
JSchema linkedRules = ForgeSchemaValidator.GetLinkedJSchemaRules(stringRules, stringRules, "//ForgeSchemaValidationRules.json");
|
||||
ForgeSchemaValidator.ValidateSchemaAsForgeTree(treeSchema, linkedRules, out IList<ValidationError> errorList);
|
||||
JSchema linkedRules = ForgeSchemaValidator.GetLinkedJSchemaRules(rulesForDictionary, stringRules, "//ForgeSchemaValidationRules.json");
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaAsForgeTreeDictionary(treeSchemas, linkedRules, true, out IList<ValidationError> errorList);
|
||||
Assert.IsTrue(res);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -71,7 +74,7 @@ namespace Microsoft.Forge.TreeWalker.UnitTests
|
|||
public void Test_ValidateSchemaAsForgeTree_WithRulesAsString()
|
||||
{
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaAsForgeTree(treeSchema, stringRules, out IList<ValidationError> errorList);
|
||||
Assert.AreEqual(true, res);
|
||||
Assert.IsTrue(res);
|
||||
Assert.AreEqual(0, errorList.Count);
|
||||
}
|
||||
|
||||
|
@ -79,7 +82,7 @@ namespace Microsoft.Forge.TreeWalker.UnitTests
|
|||
public void Test_ValidateSchemaAsForgeTree_WithRulesAsJSchema()
|
||||
{
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaAsForgeTree(treeSchema, jschemaRules, out IList<ValidationError> errorList);
|
||||
Assert.AreEqual(true, res);
|
||||
Assert.IsTrue(res);
|
||||
Assert.AreEqual(0, errorList.Count);
|
||||
}
|
||||
|
||||
|
@ -87,15 +90,15 @@ namespace Microsoft.Forge.TreeWalker.UnitTests
|
|||
public void Test_ValidateSchemaAsForgeTreeDictionary_WithoutValidateAsDictionary()
|
||||
{
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaAsForgeTreeDictionary(treeSchemas, stringRules, false, out IList<ValidationError> errorList);
|
||||
Assert.AreEqual(true, res);
|
||||
Assert.IsTrue(res);
|
||||
Assert.AreEqual(0, errorList.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_ValidateSchemaAsForgeTreeDictionary_WithValidateAsDictionary()
|
||||
{
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaAsForgeTreeDictionary(treeSchemas, rulesForDictionary, true, out IList<ValidationError> errorList);
|
||||
Assert.AreEqual(true, res);
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaAsForgeTreeDictionary(treeSchemas, linkedRulesForDictionary, true, out IList<ValidationError> errorList);
|
||||
Assert.IsTrue(res);
|
||||
Assert.AreEqual(0, errorList.Count);
|
||||
}
|
||||
|
||||
|
@ -103,15 +106,15 @@ namespace Microsoft.Forge.TreeWalker.UnitTests
|
|||
public void Test_ValidateSchemaAsString_WithForgeTree()
|
||||
{
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaAsString(forgeTreeAsString, stringRules, false, out IList<ValidationError> errorList);
|
||||
Assert.AreEqual(true, res);
|
||||
Assert.IsTrue(res);
|
||||
Assert.AreEqual(0, errorList.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_ValidateSchemaAsString_WithValidateAsDictionary()
|
||||
{
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaAsString(forgeTreeDictionaryAsString, rulesForDictionary, true, out IList<ValidationError> errorList);
|
||||
Assert.AreEqual(true, res);
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaAsString(forgeTreeDictionaryAsString, linkedRulesForDictionary, true, out IList<ValidationError> errorList);
|
||||
Assert.IsTrue(res);
|
||||
Assert.AreEqual(0, errorList.Count);
|
||||
}
|
||||
|
||||
|
@ -119,7 +122,7 @@ namespace Microsoft.Forge.TreeWalker.UnitTests
|
|||
public void Test_ValidateSchemaFromPath_WithoutValidateAsDictionary()
|
||||
{
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaFromPath(forgeTreeFromPath, stringRules, false, out IList<ValidationError> errorList);
|
||||
Assert.AreEqual(true, res);
|
||||
Assert.IsTrue(res);
|
||||
Assert.AreEqual(0, errorList.Count);
|
||||
}
|
||||
|
||||
|
@ -127,14 +130,14 @@ namespace Microsoft.Forge.TreeWalker.UnitTests
|
|||
public void Test_ValidateSchemasFromDirectory_WithValidateAsSeparateFiles()
|
||||
{
|
||||
bool res = ForgeSchemaValidator.ValidateSchemaFromDirectory(schemaDirectoryPath, stringRules, false, out IList<ValidationError> errorList);
|
||||
Assert.AreEqual(true, res);
|
||||
Assert.IsTrue(res);
|
||||
Assert.AreEqual(0, errorList.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_GetLinkedJSchemaRules_WithInvalidUrl__Fail()
|
||||
{
|
||||
Assert.ThrowsException<UriFormatException>(() => ForgeSchemaValidator.GetLinkedJSchemaRules(stringRules, stringRules, "//"));
|
||||
Assert.ThrowsException<JSchemaReaderException>(() => ForgeSchemaValidator.GetLinkedJSchemaRules(rulesForDictionary, stringRules, "//nameImadeup.json"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
@ -158,9 +161,15 @@ namespace Microsoft.Forge.TreeWalker.UnitTests
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_ValidateSchemaFromDirectory_WithValidateAsDictionary_DirectoryContainsForgeTrees_Fail()
|
||||
public void Test_ValidateSchemaFromDirectory_WithValidateAsDictionary_DirectoryContainsForgeTree_Fail()
|
||||
{
|
||||
Assert.ThrowsException<NullReferenceException>(() => ForgeSchemaValidator.ValidateSchemaFromDirectory(schemaDirectoryPath, rulesForDictionary, true, out IList<ValidationError> errorList));
|
||||
Assert.ThrowsException<NullReferenceException>(() => ForgeSchemaValidator.ValidateSchemaFromDirectory(schemaDirectoryPath, linkedRulesForDictionary, true, out IList<ValidationError> errorList));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_ValidateSchemaAsForgeTreeDictionary_WithRulesUnlinked_Fail()
|
||||
{
|
||||
Assert.ThrowsException<JSchemaReaderException>(() => ForgeSchemaValidator.ValidateSchemaAsForgeTreeDictionary(treeSchemas, rulesForDictionary, true, out IList<ValidationError> errorList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Microsoft.Forge.TreeWalker</RootNamespace>
|
||||
<AssemblyName>Microsoft.Forge.TreeWalker</AssemblyName>
|
||||
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
|
||||
<Deterministic>true</Deterministic>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Authors>Microsoft</Authors>
|
||||
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
|
||||
<PackageDescription>A Generic Low-Code Framework Built on a Config-Driven Tree Walker.</PackageDescription>
|
||||
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
|
||||
<PackageProjectUrl>https://github.com/microsoft/Forge</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/microsoft/Forge</RepositoryUrl>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
<PackageOutputPath>bin\Release</PackageOutputPath>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<PackageTags>Forge;TreeWalker;Roslyn;async;dynamic;generic;workflow engine;decision tree;config;stateful;low-code;tree visualization;workflow framework;JSON</PackageTags>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GitVersionTask" Version="5.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Scripting" Version="3.8.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.11" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\LICENSE.txt" Pack="true" PackagePath="$(PackageLicenseFile)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="contracts\ForgeSchemaDictionaryValidationRules.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<PackageCopyToOutput>true</PackageCopyToOutput>
|
||||
<Pack>true</Pack>
|
||||
</Content>
|
||||
<Content Include="contracts\ForgeSchemaValidationRules.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<PackageCopyToOutput>true</PackageCopyToOutput>
|
||||
<Pack>true</Pack>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Microsoft.Forge.TreeWalker</RootNamespace>
|
||||
<AssemblyName>Microsoft.Forge.TreeWalker</AssemblyName>
|
||||
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
|
||||
<Deterministic>true</Deterministic>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Authors>Microsoft</Authors>
|
||||
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
|
||||
<PackageDescription>A Generic Low-Code Framework Built on a Config-Driven Tree Walker.</PackageDescription>
|
||||
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
|
||||
<PackageProjectUrl>https://github.com/microsoft/Forge</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/microsoft/Forge</RepositoryUrl>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
<PackageOutputPath>bin\Release</PackageOutputPath>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<PackageTags>Forge;TreeWalker;Roslyn;async;dynamic;generic;workflow engine;decision tree;config;stateful;low-code;tree visualization;workflow framework;JSON</PackageTags>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GitVersionTask" Version="5.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Scripting" Version="3.8.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.11" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\LICENSE.txt" Pack="true" PackagePath="$(PackageLicenseFile)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="contracts\ForgeSchemaDictionaryValidationRules.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<PackageCopyToOutput>true</PackageCopyToOutput>
|
||||
<Pack>true</Pack>
|
||||
</Content>
|
||||
<Content Include="contracts\ForgeSchemaValidationRules.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<PackageCopyToOutput>true</PackageCopyToOutput>
|
||||
<Pack>true</Pack>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -8,24 +8,16 @@
|
|||
"additionalProperties": false,
|
||||
"definitions": {
|
||||
"ForgeTreeDefinition": {
|
||||
"additionalProperties": false,
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Tree": {
|
||||
"$ref": "#/definitions/TreeDefinition"
|
||||
"$ref": "file://ForgeSchemaValidationRules.json#/definitions/TreeDefinition"
|
||||
},
|
||||
"RootTreeNodeKey": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"TreeDefinition": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
".*?": {
|
||||
"$dynamicRef": "file://ForgeSchemaValidationRules.json#/definitions/TreeDefinition"
|
||||
}
|
||||
}
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
|
@ -175,7 +175,7 @@
|
|||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [ "Label", "Child" ]
|
||||
"required": [ "Child" ]
|
||||
},
|
||||
"RetryPolicy": {
|
||||
"type": "object",
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Microsoft.Forge.TreeWalker
|
|||
/// <param name="parentRules">The parent rules to absorb the child rules</param>
|
||||
/// <param name="referenceUri">The address of childRules</param>
|
||||
/// <returns>The result of schema combination.</returns>
|
||||
public static JSchema GetLinkedJSchemaRules(string childRules, string parentRules, string referenceUri)
|
||||
public static JSchema GetLinkedJSchemaRules(string parentRules, string childRules, string referenceUri)
|
||||
{
|
||||
JSchemaPreloadedResolver resolver = new JSchemaPreloadedResolver();
|
||||
resolver.Add(new Uri(referenceUri), childRules);
|
||||
|
|
Загрузка…
Ссылка в новой задаче