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

Remove the use of the TestXXXX classes. #2780

Merged
merged 4 commits into from
May 15, 2024
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: 0 additions & 1 deletion src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

<ItemGroup>
<ProjectReference Include="..\Hl7.Fhir.R5\Hl7.Fhir.R5.csproj" />
<ProjectReference Include="..\Hl7.Fhir.Support.Poco.Tests\Hl7.Fhir.Support.Poco.Tests.csproj" />
<ProjectReference Include="..\Hl7.Fhir.Specification.Data.R5\Hl7.Fhir.Specification.Data.R5.csproj" />
</ItemGroup>

Expand Down
16 changes: 8 additions & 8 deletions src/Benchmarks/DeserializationBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ public void BenchmarkSetup()
var xmlFileName = Path.Combine("TestData", "fp-test-patient.xml");
XmlData = File.ReadAllText(xmlFileName);

XmlDeserializer = new BaseFhirXmlPocoDeserializer(typeof(TestPatient).Assembly);
JsonDeserializer = new BaseFhirJsonPocoDeserializer(typeof(TestPatient).Assembly);
XmlDeserializer = new FhirXmlPocoDeserializer();
JsonDeserializer = new FhirJsonPocoDeserializer();
ewoutkramer marked this conversation as resolved.
Show resolved Hide resolved

options = new JsonSerializerOptions().ForFhir(typeof(TestPatient).Assembly);
options = new JsonSerializerOptions().ForFhir();
}

[Benchmark]
public Resource JsonDictionaryDeserializer()
{
try
{
return JsonSerializer.Deserialize<TestPatient>(JsonData, options);
return JsonSerializer.Deserialize<Patient>(JsonData, options);
}
catch (DeserializationFailedException e)
{
Expand All @@ -64,15 +64,15 @@ public Resource XmlDictionaryDeserializer()


[Benchmark]
public TestPatient TypedElementDeserializerJson()
public Patient TypedElementDeserializerJson()
{
return FhirJsonNode.Parse(JsonData).ToPoco<TestPatient>(ModelInspector.ForType<TestPatient>());
return FhirJsonNode.Parse(JsonData).ToPoco<Patient>();
}

[Benchmark]
public Resource TypedElementDeserializerXml()
{
return FhirXmlNode.Parse(XmlData).ToPoco<TestPatient>(ModelInspector.ForType<TestPatient>());
return FhirXmlNode.Parse(XmlData).ToPoco<Patient>();
}
}
}
}
14 changes: 7 additions & 7 deletions src/Benchmarks/SerializationBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Firely.Sdk.Benchmarks
[MemoryDiagnoser]
public class SerializationBenchmarks
{
internal TestPatient Patient;
internal Patient Patient;
JsonSerializerOptions Options;
BaseFhirXmlPocoSerializer XmlSerializer;

Expand All @@ -24,9 +24,9 @@ public void BenchmarkSetup()
var data = File.ReadAllText(filename);
// For now, deserialize with the existing deserializer, until we have completed
// the dynamicserializer too.
Patient = FhirJsonNode.Parse(data).ToPoco<TestPatient>(ModelInspector.ForType<TestPatient>());
Options = new JsonSerializerOptions().ForFhir(typeof(TestPatient).Assembly);
XmlSerializer = new BaseFhirXmlPocoSerializer(Hl7.Fhir.Specification.FhirRelease.STU3);
Patient = FhirJsonNode.Parse(data).ToPoco<Patient>();
Options = new JsonSerializerOptions().ForFhir();
XmlSerializer = new FhirXmlPocoSerializer();
}

[Benchmark]
Expand All @@ -44,13 +44,13 @@ public string XmlDictionarySerializer()
[Benchmark]
public string TypedElementSerializerJson()
{
return Patient.ToTypedElement(ModelInspector.ForType<TestPatient>()).ToJson();
return Patient.ToTypedElement().ToJson();
}

[Benchmark]
public string TypedElementSerializerXml()
{
return Patient.ToTypedElement(ModelInspector.ForType<TestPatient>()).ToXml();
return Patient.ToTypedElement().ToXml();
}
}
}
}
4 changes: 2 additions & 2 deletions src/Hl7.Fhir.Base/FhirPath/Expressions/ExpressionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public class ConstantExpression : Expression, Sprache.IPositionAware<ConstantExp
public ConstantExpression(object value, TypeSpecifier type, ISourcePositionInfo location = null) : base(type, location)
{
if (value == null) Error.ArgumentNull("value");
if (value is P.Any && (value is P.Boolean || value is P.Decimal || value is P.Integer || value is P.Long || value is P.String))
if (value is P.Any and (P.Boolean or P.Decimal or P.Integer or P.Long or P.String))
throw new ArgumentException("Internal error: not yet ready to handle Any-based primitives in FhirPath.");

Value = value;
Expand Down Expand Up @@ -627,4 +627,4 @@ public string AxisName
public static readonly AxisExpression That = new AxisExpression("that");
AxisExpression IPositionAware<AxisExpression>.SetPos(Position startPos, int length) => SetPos<AxisExpression>(startPos, length);
}
}
}
4 changes: 2 additions & 2 deletions src/Hl7.Fhir.Base/Model/CodeOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal bool TryParseObjectValue(out T? value)
{
value = default;

if (ObjectValue is string s && EnumUtility.ParseLiteral<T>(s) is T parsed)
if (ObjectValue is string s && EnumUtility.ParseLiteral<T>(s) is { } parsed)
{
value = parsed;
return true;
Expand All @@ -109,4 +109,4 @@ public override IEnumerable<ValidationResult> Validate(ValidationContext validat
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static JsonSerializerOptions Pretty(this JsonSerializerOptions options)
}

// internal for testing purposes
internal static JsonConverter? FindCustomConverter(IEnumerable<JsonConverter> converters)
internal static JsonConverter? FindCustomConverter(this IEnumerable<JsonConverter> converters)
{
return converters.FirstOrDefault(jsonConverter => jsonConverter.CanConvert(typeof(Resource)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Hl7.Fhir.Base/Serialization/PrimitiveValueReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal object Deserialize(Type nativeType)
{
// The POCO's know nothing about the special partial date/time classes used by ITypedElement,
// instead FhirDateTime, Time and FhirDate all represent these values as simple strings.
if (primitiveValue is P.DateTime || primitiveValue is P.Time || primitiveValue is P.Date)
if (primitiveValue is P.DateTime or P.Time or P.Date)
return PrimitiveTypeConverter.ConvertTo(primitiveValue.ToString(), nativeType);
else
return PrimitiveTypeConverter.ConvertTo(primitiveValue, nativeType);
Expand All @@ -50,4 +50,4 @@ internal object Deserialize(Type nativeType)
}
}
#pragma warning restore 612,618
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Net;
using System.Text;
using System.Threading.Tasks;
using T = System.Threading.Tasks;
using Tasks = System.Threading.Tasks;

namespace Hl7.Fhir.Specification.Terminology
{
Expand All @@ -35,32 +35,32 @@ protected CustomValueSetTerminologyService(string terminologyType, string codeSy
}

///<inheritdoc />
public T.Task<Resource> Closure(Parameters parameters, bool useGet = false) =>
public Tasks.Task<Resource> Closure(Parameters parameters, bool useGet = false) =>
throw new NotImplementedException();

///<inheritdoc />
public T.Task<Parameters>
public Tasks.Task<Parameters>
CodeSystemValidateCode(Parameters parameters, string? id = null, bool useGet = false) =>
throw new NotImplementedException();

///<inheritdoc />
public T.Task<Resource> Expand(Parameters parameters, string? id = null, bool useGet = false) =>
public Tasks.Task<Resource> Expand(Parameters parameters, string? id = null, bool useGet = false) =>
throw new NotImplementedException();

///<inheritdoc />
public T.Task<Parameters> Lookup(Parameters parameters, bool useGet = false) =>
public Tasks.Task<Parameters> Lookup(Parameters parameters, bool useGet = false) =>
throw new NotImplementedException();

///<inheritdoc />
public T.Task<Parameters> Subsumes(Parameters parameters, string? id = null, bool useGet = false) =>
public Tasks.Task<Parameters> Subsumes(Parameters parameters, string? id = null, bool useGet = false) =>
throw new NotImplementedException();

///<inheritdoc />
public T.Task<Parameters> Translate(Parameters parameters, string? id = null, bool useGet = false) =>
public Tasks.Task<Parameters> Translate(Parameters parameters, string? id = null, bool useGet = false) =>
throw new NotImplementedException();

///<inheritdoc />
public async T.Task<Parameters> ValueSetValidateCode(Parameters parameters, string? id = null,
public async Tasks.Task<Parameters> ValueSetValidateCode(Parameters parameters, string? id = null,
bool useGet = false)
{
parameters.CheckForValidityOfValidateCodeParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using T = System.Threading.Tasks;
using Tasks = System.Threading.Tasks;

namespace Hl7.Fhir.Specification
{
Expand Down Expand Up @@ -90,7 +90,7 @@ public StructureDefinitionWalker(StructureDefinitionWalker other)
public StructureDefinitionWalker FromCanonical(string canonical, IEnumerable<string>? targetProfiles = null) =>
TaskHelper.Await(() => FromCanonicalAsync(canonical, targetProfiles));

public async T.Task<StructureDefinitionWalker> FromCanonicalAsync(string canonical, IEnumerable<string>? targetProfiles = null)
public async Tasks.Task<StructureDefinitionWalker> FromCanonicalAsync(string canonical, IEnumerable<string>? targetProfiles = null)
{
var sd = await AsyncResolver.FindStructureDefinitionAsync(canonical).ConfigureAwait(false);
if (sd == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using T = System.Threading.Tasks;
using Tasks = System.Threading.Tasks;

namespace Hl7.Fhir.Specification.Snapshot
{
Expand All @@ -23,14 +23,14 @@ namespace Hl7.Fhir.Specification.Snapshot

partial class SnapshotGenerator
{
private T.Task ensureSnapshotBaseComponents(StructureDefinition structureDef, bool force = false) =>
private Tasks.Task ensureSnapshotBaseComponents(StructureDefinition structureDef, bool force = false) =>
ensureBaseComponents(structureDef.Snapshot.Element, structureDef.BaseDefinition, force);

/// <summary>(Re-)generate the <see cref="ElementDefinition.Base"/> components.</summary>
/// <param name="elements">A list of <see cref="ElementDefinition"/> instances.</param>
/// <param name="baseProfileUrl">The canonical url of the base profile, as defined by the <see cref="StructureDefinition.BaseDefinition"/> property.</param>
/// <param name="force">If <c>true</c>, then always (re-)generate the Base component, even if it exists.</param>
private async T.Task ensureBaseComponents(IList<ElementDefinition> elements, string baseProfileUrl, bool force = false)
private async Tasks.Task ensureBaseComponents(IList<ElementDefinition> elements, string baseProfileUrl, bool force = false)
{
var nav = new ElementDefinitionNavigator(elements);
if (nav.MoveToFirstChild() && !string.IsNullOrEmpty(baseProfileUrl))
Expand All @@ -56,7 +56,7 @@ private async T.Task ensureBaseComponents(IList<ElementDefinition> elements, str
}
}

private async T.Task ensureBaseComponents(ElementDefinitionNavigator nav, ElementDefinitionNavigator baseNav, bool force = false)
private async Tasks.Task ensureBaseComponents(ElementDefinitionNavigator nav, ElementDefinitionNavigator baseNav, bool force = false)
{
// Debug.Print($"[nameof(generateElementBase)}] Path = '{nav.Path}' Base = '{baseNav.Path}'");
var elem = nav.Current;
Expand Down Expand Up @@ -188,4 +188,4 @@ static ElementDefinition.BaseComponent createBaseComponent(FhirString maxElement
}

}
}
}
Loading