Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update manifest tests to newest format #219

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions firely-validator-api-tests.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Firely.Fhir.Packages" Version="4.2.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Specification.Source;
using Hl7.Fhir.Specification.Terminology;
using Hl7.Fhir.Support;
Expand All @@ -8,11 +9,13 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;
using static Hl7.Fhir.Model.OperationOutcome;

namespace Firely.Fhir.Validation.Compilation.Tests
{
internal class WipValidator : ITestValidator
internal class DotNetValidator : ITestValidator
{
private readonly string[] _unsupportedTests = new[]
{
Expand All @@ -25,21 +28,54 @@ internal class WipValidator : ITestValidator
private static readonly IResourceResolver BASE_RESOLVER = new CachedResolver(new StructureDefinitionCorrectionsResolver(ZipSource.CreateValidationSource()));
private static readonly IElementSchemaResolver SCHEMA_RESOLVER = StructureDefinitionToElementSchemaResolver.CreatedCached(BASE_RESOLVER.AsAsync());
private readonly Stopwatch _stopWatch;
private readonly JsonSerializerOptions _serializerOptions;

public WipValidator(Stopwatch? stopwatch = null)
public DotNetValidator(Stopwatch? stopwatch = null)
{
_stopWatch = stopwatch ?? new();
_serializerOptions = new JsonSerializerOptions().ForFhir(ModelInfo.ModelInspector).Pretty();
}

public static ITestValidator Create() => new WipValidator();
public static ITestValidator Create() => new DotNetValidator();

public string Name => "Wip";
public string Name => "dotnet-current";

public string[] UnvalidatableTests => _unsupportedTests;

public bool CannotValidateTest(TestCase c) => UnvalidatableTests.Contains(c.Name);
public ExpectedResult? GetExpectedResults(IValidatorEnginesResults engine) => engine.FirelySDKWip;
public void SetExpectedResults(IValidatorEnginesResults engine, ExpectedResult result) => engine.FirelySDKWip = result;

public OperationOutcome? GetExpectedOperationOutcome(IValidatorEnginesResults engine)
{
var json = engine.FirelyDotNet?.Outcome;
if (json is null)
{
return null;
}
else
{
try
{
return JsonSerializer.Deserialize<OperationOutcome>(json.ToJsonString(), _serializerOptions);
}
catch (DeserializationFailedException e)
{
return e.PartialResult as OperationOutcome;
}
}
}

public void SetOperationOutcome(IValidatorEnginesResults engine, OperationOutcome outcome)
{
var oo = JsonSerializer.Serialize(outcome, _serializerOptions);
if (engine.FirelyDotNet is null)
{
engine.FirelyDotNet = new ExpectedOutcome() { Outcome = JsonNode.Parse(oo)?.AsObject() };
}
else
{
engine.FirelyDotNet.Outcome = JsonNode.Parse(oo)?.AsObject();
}
}

/// <summary>
/// Validator engine based in this solution: the work in progress (wip) validator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ internal interface ITestValidator

OperationOutcome Validate(ITypedElement instance, IResourceResolver? resolver, string? profile = null);

ExpectedResult? GetExpectedResults(IValidatorEnginesResults engine);
OperationOutcome? GetExpectedOperationOutcome(IValidatorEnginesResults engine);

void SetExpectedResults(IValidatorEnginesResults engine, ExpectedResult result);
void SetOperationOutcome(IValidatorEnginesResults engine, OperationOutcome outcome);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
*/

using System.Collections.Generic;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

namespace Firely.Fhir.Validation.Compilation.Tests
{
public interface IValidatorEnginesResults
{
public ExpectedResult? Java { get; set; }
public ExpectedOutcome? Java { get; set; }

public ExpectedResult? FirelySDKCurrent { get; set; }
public ExpectedOutcome? FirelyDotNet { get; set; }
}

public ExpectedResult? FirelySDKWip { get; set; }
public class ExpectedOutcome
{
[JsonPropertyName("outcome")]
public JsonObject? Outcome { get; set; }
[JsonPropertyName("comment")]
public string? Comment { get; set; }
[JsonPropertyName("explanation")]
public string? Explanation { get; set; }
}

public class ExpectedResult
Expand Down Expand Up @@ -50,6 +59,9 @@ public class Profile : IValidatorEnginesResults
[JsonPropertyName("source")]
public string? Source { get; set; }

[JsonPropertyName("packages")]
public string[]? Packages { get; set; }

// Is this needed? Should be a part of ExpectedResult
[JsonPropertyName("errorCount")]
public int? ErrorCount { get; set; }
Expand All @@ -61,13 +73,10 @@ public class Profile : IValidatorEnginesResults
public List<string>? Supporting { get; set; }

[JsonPropertyName("java")]
public ExpectedResult? Java { get; set; }

[JsonPropertyName("firely-sdk-current")]
public ExpectedResult? FirelySDKCurrent { get; set; }
public ExpectedOutcome? Java { get; set; }

[JsonPropertyName("firely-sdk-wip")]
public ExpectedResult? FirelySDKWip { get; set; }
[JsonPropertyName("firely-dotnet")]
public ExpectedOutcome? FirelyDotNet { get; set; }
}

public class BundleParameter
Expand All @@ -90,17 +99,14 @@ public class Logical
[JsonPropertyName("expressions")]
public string[]? Expressions { get; set; }

[JsonPropertyName("explanation")]
public string? Explanation { get; set; }
[JsonPropertyName("format")]
public string? Format { get; set; }

[JsonPropertyName("java")]
public ExpectedResult? Java { get; set; }

[JsonPropertyName("firely-sdk-current")]
public ExpectedResult? FirelySDKCurrent { get; set; }
public ExpectedOutcome? Java { get; set; }

[JsonPropertyName("firely-sdk-wip")]
public ExpectedResult? FirelySDKWip { get; set; }
[JsonPropertyName("firely-dotnet")]
public ExpectedOutcome? FirelyDotNet { get; set; }
}

public class TestCase : IValidatorEnginesResults
Expand All @@ -111,15 +117,54 @@ public class TestCase : IValidatorEnginesResults
[JsonPropertyName("file")]
public string? FileName { get; set; }

[JsonPropertyName("default-version")]
public bool? DefaultVersion { get; set; }

[JsonPropertyName("description")]
public string? Description { get; set; }

[JsonPropertyName("documentation")]
public string? Documentation { get; set; }

[JsonPropertyName("noHtmlInMarkDown")]
public bool? NoHtmlInMarkdown { get; set; }

[JsonPropertyName("for-publication")]
public string? ForPublication { get; set; }

[JsonPropertyName("fetcher")]
public string? Fetcher { get; set; }

[JsonPropertyName("module")]
public string? Module { get; set; }

[JsonPropertyName("allow-comments")]
public bool? AllowComments { get; set; }

[JsonPropertyName("no-tx")]
public bool? NoTx { get; set; }

[JsonPropertyName("ips")]
public string? Ips { get; set; }

[JsonPropertyName("close-up")]
public bool? CloseUp { get; set; }

[JsonPropertyName("packages")]
public List<string>? Packages { get; set; }

[JsonPropertyName("version")]
public string? Version { get; set; }

[JsonPropertyName("supporting")]
public List<string>? Supporting { get; set; }

[JsonPropertyName("validateReference")]
public string? ValidateReference { get; set; }

[JsonPropertyName("validateContains")]
public string? ValidateContains { get; set; }

// Is this needed?
[JsonPropertyName("x-errors")]
public string[]? XErrors { get; set; }
Expand All @@ -146,11 +191,6 @@ public class TestCase : IValidatorEnginesResults
[JsonPropertyName("language")]
public string? Language { get; set; }

[JsonPropertyName("packages")]
public List<string>? Packages { get; set; }

[JsonPropertyName("supporting")]
public List<string>? Supporting { get; set; }

[JsonPropertyName("error")]
public string? Error { get; set; }
Expand Down Expand Up @@ -182,31 +222,52 @@ public class TestCase : IValidatorEnginesResults
[JsonPropertyName("crumb-trail")]
public bool? CrumbTrail { get; set; }

[JsonPropertyName("profile")]
public Profile? Profile { get; set; }

[JsonPropertyName("explanation")]
public string? Explanation { get; set; }

[JsonPropertyName("logical")]
public Logical? Logical { get; set; }

[JsonPropertyName("java")]
public ExpectedResult? Java { get; set; }
public ExpectedOutcome? Java { get; set; }

[JsonPropertyName("firely-sdk-current")]
public ExpectedResult? FirelySDKCurrent { get; set; }
[JsonPropertyName("firely-dotnet")]
public ExpectedOutcome? FirelyDotNet { get; set; }

[JsonPropertyName("firely-sdk-wip")]
public ExpectedResult? FirelySDKWip { get; set; }
[JsonPropertyName("profile")]
public Profile? Profile { get; set; }
}

public class Manifest
{
[JsonPropertyName("documentation")]
public List<string>? Documentation { get; set; }

[JsonPropertyName("modules")]
public Modules? Modules { get; set; }

[JsonPropertyName("test-cases")]
public List<TestCase>? TestCases { get; set; }
}

public class Modules
{
[JsonPropertyName("(default)")]
ewoutkramer marked this conversation as resolved.
Show resolved Hide resolved
public string? Default { get; set; }

[JsonPropertyName("cda")]
public string? Cda { get; set; }

[JsonPropertyName("cdshooks")]
public string? CdsHooks { get; set; }

[JsonPropertyName("shc")]
public string? Hhc { get; set; }

[JsonPropertyName("notes:")]
ewoutkramer marked this conversation as resolved.
Show resolved Hide resolved
public string? Notes { get; set; }

[JsonPropertyName("json5")]
public string? Json5 { get; set; }
}
}
Loading