diff --git a/src/Hl7.Fhir.Base/CompatibilitySuppressions.xml b/src/Hl7.Fhir.Base/CompatibilitySuppressions.xml index b503bd0188..9319cf6767 100644 --- a/src/Hl7.Fhir.Base/CompatibilitySuppressions.xml +++ b/src/Hl7.Fhir.Base/CompatibilitySuppressions.xml @@ -1,5 +1,5 @@  - + CP0001 diff --git a/src/Hl7.Fhir.Base/Hl7.Fhir.Base.csproj b/src/Hl7.Fhir.Base/Hl7.Fhir.Base.csproj index 44011e9614..4f986793ad 100644 --- a/src/Hl7.Fhir.Base/Hl7.Fhir.Base.csproj +++ b/src/Hl7.Fhir.Base/Hl7.Fhir.Base.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Hl7.Fhir.Base/Specification/Snapshot/SnapshotGeneratorExtensions.cs b/src/Hl7.Fhir.Base/Specification/Snapshot/SnapshotGeneratorExtensions.cs index 3cd2cb0abb..159e5b3788 100644 --- a/src/Hl7.Fhir.Base/Specification/Snapshot/SnapshotGeneratorExtensions.cs +++ b/src/Hl7.Fhir.Base/Specification/Snapshot/SnapshotGeneratorExtensions.cs @@ -76,8 +76,12 @@ public static void RemoveAllConstrainedByDiffExtensions(this IEnumerable e } } - - internal static void RemoveAllNonInheritableExtensions(this Element element) + /// + /// This extension removes all non-inheritable extensions from the specified element definition and all it's child objects. + /// Non-inheritable extensions are extensions that should not be inherited by derived profiles. + /// + /// + public static void RemoveAllNonInheritableExtensions(this Element element) { if (element == null) { throw Error.ArgumentNull(nameof(element)); } element.RemoveNonInheritableExtensions(); diff --git a/src/Hl7.Fhir.Conformance/CompatibilitySuppressions.xml b/src/Hl7.Fhir.Conformance/CompatibilitySuppressions.xml new file mode 100644 index 0000000000..52c10ef318 --- /dev/null +++ b/src/Hl7.Fhir.Conformance/CompatibilitySuppressions.xml @@ -0,0 +1,46 @@ + + + + + CP0001 + T:Hl7.Fhir.Specification.Snapshot.RegenerationSettings + lib/net8.0/Hl7.Fhir.Conformance.dll + lib/net8.0/Hl7.Fhir.Conformance.dll + true + + + CP0001 + T:Hl7.Fhir.Specification.Snapshot.RegenerationSettings + lib/netstandard2.0/Hl7.Fhir.Conformance.dll + lib/netstandard2.0/Hl7.Fhir.Conformance.dll + true + + + CP0002 + M:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorSettings.get_RegenerationBehaviour + lib/net8.0/Hl7.Fhir.Conformance.dll + lib/net8.0/Hl7.Fhir.Conformance.dll + true + + + CP0002 + M:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorSettings.set_RegenerationBehaviour(Hl7.Fhir.Specification.Snapshot.RegenerationSettings) + lib/net8.0/Hl7.Fhir.Conformance.dll + lib/net8.0/Hl7.Fhir.Conformance.dll + true + + + CP0002 + M:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorSettings.get_RegenerationBehaviour + lib/netstandard2.0/Hl7.Fhir.Conformance.dll + lib/netstandard2.0/Hl7.Fhir.Conformance.dll + true + + + CP0002 + M:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorSettings.set_RegenerationBehaviour(Hl7.Fhir.Specification.Snapshot.RegenerationSettings) + lib/netstandard2.0/Hl7.Fhir.Conformance.dll + lib/netstandard2.0/Hl7.Fhir.Conformance.dll + true + + \ No newline at end of file diff --git a/src/Hl7.Fhir.Conformance/Specification/Snapshot/SnapshotGenerator.cs b/src/Hl7.Fhir.Conformance/Specification/Snapshot/SnapshotGenerator.cs index 87d34e30b7..abeeccafa8 100644 --- a/src/Hl7.Fhir.Conformance/Specification/Snapshot/SnapshotGenerator.cs +++ b/src/Hl7.Fhir.Conformance/Specification/Snapshot/SnapshotGenerator.cs @@ -2224,17 +2224,9 @@ private async Tasks.Task ensureSnapshot(StructureDefinition sd, string pro try { - var shouldGenerate = _settings.RegenerationBehaviour switch - { - RegenerationSettings.TRY_USE_EXISTING => !sd.HasSnapshot, - RegenerationSettings.REGENERATE_ONCE => !sd.HasSnapshot || !sd.Snapshot.IsCreatedBySnapshotGenerator(), -#pragma warning disable CS0618 // Type or member is obsolete - RegenerationSettings.FORCE_REGENERATE => true, // possible infinite recursion -#pragma warning restore CS0618 // Type or member is obsolete - _ => throw new InvalidOperationException($"Invalid RegenerationSettings value {_settings.RegenerationBehaviour}") - }; - - if (_settings.GenerateSnapshotForExternalProfiles && shouldGenerate) + if (_settings.GenerateSnapshotForExternalProfiles + && (!sd.HasSnapshot || (_settings.ForceRegenerateSnapshots && !sd.Snapshot.IsCreatedBySnapshotGenerator())) + ) { // Automatically expand external profiles on demand // Debug.Print($"[{nameof(SnapshotGenerator)}.{nameof(ensureSnapshot)}] Recursively generate snapshot for type profile with url: '{sd.Url}' ..."); @@ -2316,18 +2308,9 @@ private async Tasks.Task getSnapshotRootElement(StructureDefi var cachedRoot = sd.GetSnapshotRootElementAnnotation(); if (cachedRoot != null) { return cachedRoot; } #endif - var hasValidRoot = _settings.RegenerationBehaviour switch - { - RegenerationSettings.TRY_USE_EXISTING => sd.HasSnapshot, - RegenerationSettings.REGENERATE_ONCE => sd.HasSnapshot && sd.Snapshot.IsCreatedBySnapshotGenerator(), -#pragma warning disable CS0618 // Type or member is obsolete - RegenerationSettings.FORCE_REGENERATE => false, -#pragma warning restore CS0618 // Type or member is obsolete - _ => throw new InvalidOperationException($"Invalid RegenerationSettings value {_settings.RegenerationBehaviour}") - }; - + // 2. Return root element definition from existing (pre-generated) snapshot, if it exists - if (hasValidRoot) + if (sd.HasSnapshot && (sd.Snapshot.IsCreatedBySnapshotGenerator() || !_settings.ForceRegenerateSnapshots)) { // Debug.Print($"[{nameof(SnapshotGenerator)}.{nameof(getSnapshotRootElement)}] {nameof(profileUri)} = '{profileUri}' - use existing root element definition from snapshot: #{sd.Snapshot.Element[0].GetHashCode()}"); // No need to save root ElemDef annotation, as the snapshot has already been fully expanded diff --git a/src/Hl7.Fhir.STU3/CompatibilitySuppressions.xml b/src/Hl7.Fhir.STU3/CompatibilitySuppressions.xml new file mode 100644 index 0000000000..5ea4f028ec --- /dev/null +++ b/src/Hl7.Fhir.STU3/CompatibilitySuppressions.xml @@ -0,0 +1,46 @@ + + + + + CP0001 + T:Hl7.Fhir.Specification.Snapshot.RegenerationSettings + lib/net8.0/Hl7.Fhir.STU3.dll + lib/net8.0/Hl7.Fhir.STU3.dll + true + + + CP0001 + T:Hl7.Fhir.Specification.Snapshot.RegenerationSettings + lib/netstandard2.0/Hl7.Fhir.STU3.dll + lib/netstandard2.0/Hl7.Fhir.STU3.dll + true + + + CP0002 + M:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorSettings.get_RegenerationBehaviour + lib/net8.0/Hl7.Fhir.STU3.dll + lib/net8.0/Hl7.Fhir.STU3.dll + true + + + CP0002 + M:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorSettings.set_RegenerationBehaviour(Hl7.Fhir.Specification.Snapshot.RegenerationSettings) + lib/net8.0/Hl7.Fhir.STU3.dll + lib/net8.0/Hl7.Fhir.STU3.dll + true + + + CP0002 + M:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorSettings.get_RegenerationBehaviour + lib/netstandard2.0/Hl7.Fhir.STU3.dll + lib/netstandard2.0/Hl7.Fhir.STU3.dll + true + + + CP0002 + M:Hl7.Fhir.Specification.Snapshot.SnapshotGeneratorSettings.set_RegenerationBehaviour(Hl7.Fhir.Specification.Snapshot.RegenerationSettings) + lib/netstandard2.0/Hl7.Fhir.STU3.dll + lib/netstandard2.0/Hl7.Fhir.STU3.dll + true + + \ No newline at end of file diff --git a/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGenerator.cs b/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGenerator.cs index 8b2616a871..7b6029aeb4 100644 --- a/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGenerator.cs +++ b/src/Hl7.Fhir.STU3/Specification/Snapshot/SnapshotGenerator.cs @@ -1941,17 +1941,9 @@ private async Tasks.Task ensureSnapshot(StructureDefinition sd, string pro try { - var shouldGenerate = _settings.RegenerationBehaviour switch - { - RegenerationSettings.TRY_USE_EXISTING => !sd.HasSnapshot, - RegenerationSettings.REGENERATE_ONCE => !sd.HasSnapshot || !sd.Snapshot.IsCreatedBySnapshotGenerator(), -#pragma warning disable CS0618 // Type or member is obsolete - RegenerationSettings.FORCE_REGENERATE => true, -#pragma warning restore CS0618 // Type or member is obsolete - _ => throw new InvalidOperationException($"Invalid RegenerationSettings value {_settings.RegenerationBehaviour}") - }; - - if (_settings.GenerateSnapshotForExternalProfiles && shouldGenerate) + if (_settings.GenerateSnapshotForExternalProfiles + && (!sd.HasSnapshot || (_settings.ForceRegenerateSnapshots && !sd.Snapshot.IsCreatedBySnapshotGenerator())) + ) { // Automatically expand external profiles on demand // Debug.Print($"[{nameof(SnapshotGenerator)}.{nameof(ensureSnapshot)}] Recursively generate snapshot for type profile with url: '{sd.Url}' ..."); @@ -2033,18 +2025,9 @@ private async Tasks.Task getSnapshotRootElement(StructureDefi var cachedRoot = sd.GetSnapshotRootElementAnnotation(); if (cachedRoot != null) { return cachedRoot; } #endif - var hasValidRoot = _settings.RegenerationBehaviour switch - { - RegenerationSettings.TRY_USE_EXISTING => sd.HasSnapshot, - RegenerationSettings.REGENERATE_ONCE => sd.HasSnapshot && sd.Snapshot.IsCreatedBySnapshotGenerator(), -#pragma warning disable CS0618 // Type or member is obsolete - RegenerationSettings.FORCE_REGENERATE => false, -#pragma warning restore CS0618 // Type or member is obsolete - _ => throw new InvalidOperationException($"Invalid RegenerationSettings value {_settings.RegenerationBehaviour}") - }; - + // 2. Return root element definition from existing (pre-generated) snapshot, if it exists - if (hasValidRoot) + if (sd.HasSnapshot && (sd.Snapshot.IsCreatedBySnapshotGenerator() || !_settings.ForceRegenerateSnapshots)) { // Debug.Print($"[{nameof(SnapshotGenerator)}.{nameof(getSnapshotRootElement)}] {nameof(profileUri)} = '{profileUri}' - use existing root element definition from snapshot: #{sd.Snapshot.Element[0].GetHashCode()}"); // No need to save root ElemDef annotation, as the snapshot has already been fully expanded diff --git a/src/Hl7.Fhir.Shims.Base/Specification/Snapshot/SnapshotGeneratorSettings.cs b/src/Hl7.Fhir.Shims.Base/Specification/Snapshot/SnapshotGeneratorSettings.cs index 09ca863da8..15aa3570b5 100644 --- a/src/Hl7.Fhir.Shims.Base/Specification/Snapshot/SnapshotGeneratorSettings.cs +++ b/src/Hl7.Fhir.Shims.Base/Specification/Snapshot/SnapshotGeneratorSettings.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2017, Firely (info@fire.ly) and contributors * See the file CONTRIBUTORS for details. * @@ -7,7 +7,6 @@ */ using Hl7.Fhir.Utility; -using System; namespace Hl7.Fhir.Specification.Snapshot { @@ -35,7 +34,7 @@ public void CopyTo(SnapshotGeneratorSettings other) { if (other == null) { throw Error.ArgumentNull(nameof(other)); } other.GenerateSnapshotForExternalProfiles = GenerateSnapshotForExternalProfiles; - other.RegenerationBehaviour = RegenerationBehaviour; + other.ForceRegenerateSnapshots = ForceRegenerateSnapshots; other.GenerateExtensionsOnConstraints = GenerateExtensionsOnConstraints; other.GenerateAnnotationsOnConstraints = GenerateAnnotationsOnConstraints; other.GenerateElementIds = GenerateElementIds; @@ -56,18 +55,7 @@ public void CopyTo(SnapshotGeneratorSettings other) /// Re-generated snapshots are annotated to prevent duplicate re-generation (assuming the provided resource resolver uses caching). /// If disabled (default), then the snapshot generator relies on existing snapshot components, if they exist. /// - [Obsolete( - "This setting does not work as intended. We will maintain the old behaviour for now, and we will consider removing it in a future major release. Use the new RegenerationBehaviour setting instead. See also https://github.com/FirelyTeam/firely-net-sdk/pull/2803")] - public bool ForceRegenerateSnapshots - { - get { return this.RegenerationBehaviour == RegenerationSettings.REGENERATE_ONCE; } - set { this.RegenerationBehaviour = value ? RegenerationSettings.REGENERATE_ONCE : RegenerationSettings.TRY_USE_EXISTING; } - } // ForceExpandAll - - /// - /// Setting for the regeneration behaviour of the snapshot generator. see . - /// - public RegenerationSettings RegenerationBehaviour { get; set; } + public bool ForceRegenerateSnapshots { get; set; } = false; // ForceExpandAll /// /// Enable this setting to add a custom extension @@ -96,24 +84,4 @@ public bool ForceRegenerateSnapshots // See GForge #9791 // public bool MergeTypeProfiles { get; set; } } - - /// - /// Settings for defining the behaviour of the snapshot generator with respect to regenerating snapshots. - /// - public enum RegenerationSettings - { - /// - /// Try to use an existing snapshot, if available. - /// - TRY_USE_EXISTING, - /// - /// Regenerate the snapshot once, to ensure it is up-to-date. - /// - REGENERATE_ONCE, - /// - /// Regenerate the snapshot every time. This is useful for debugging and testing purposes. - /// - [Obsolete("Watch out when using this setting! it could lead to infinite recursion and is mainly meant for debugging and testing purposes. If you previously had ForceRegenerateSnapshots set to true, consider using REGENERATE_ONCE instead.")] - FORCE_REGENERATE, - } } diff --git a/src/Hl7.Fhir.Shims.Base/Specification/Source/SnapshotSource.cs b/src/Hl7.Fhir.Shims.Base/Specification/Source/SnapshotSource.cs index 01b5a880c0..7d8d30ac83 100644 --- a/src/Hl7.Fhir.Shims.Base/Specification/Source/SnapshotSource.cs +++ b/src/Hl7.Fhir.Shims.Base/Specification/Source/SnapshotSource.cs @@ -54,9 +54,7 @@ public SnapshotSource(ISyncOrAsyncResourceResolver source, bool regenerate) private static SnapshotGeneratorSettings createSettings(bool regenerate) { var settings = SnapshotGeneratorSettings.CreateDefault(); -#pragma warning disable CS0618 // Type or member is obsolete settings.ForceRegenerateSnapshots = regenerate; -#pragma warning restore CS0618 // Type or member is obsolete return settings; } @@ -72,11 +70,11 @@ public SnapshotSource(ISyncOrAsyncResourceResolver source) #region IResourceResolver - private IAsyncResourceResolver Resolver => Generator.AsyncResolver; + private IAsyncResourceResolver _resolver => Generator.AsyncResolver; /// Find a resource based on its relative or absolute uri. /// The source ensures that resolved instances have a snapshot component. - public async Tasks.Task ResolveByUriAsync(string uri) => await ensureSnapshot(await Resolver.ResolveByUriAsync(uri).ConfigureAwait(false)).ConfigureAwait(false); + public async Tasks.Task ResolveByUriAsync(string uri) => await ensureSnapshot(await _resolver.ResolveByUriAsync(uri).ConfigureAwait(false)).ConfigureAwait(false); /// [Obsolete("SnapshotSource now works best with asynchronous resolvers. Use ResolveByUriAsync() instead.")] @@ -84,7 +82,7 @@ public SnapshotSource(ISyncOrAsyncResourceResolver source) /// Find a (conformance) resource based on its canonical uri. /// The source ensures that resolved instances have a snapshot component. - public async Tasks.Task ResolveByCanonicalUriAsync(string uri) => await ensureSnapshot(await Resolver.ResolveByCanonicalUriAsync(uri).ConfigureAwait(false)).ConfigureAwait(false); + public async Tasks.Task ResolveByCanonicalUriAsync(string uri) => await ensureSnapshot(await _resolver.ResolveByCanonicalUriAsync(uri).ConfigureAwait(false)).ConfigureAwait(false); /// [Obsolete("SnapshotSource now works best with asynchronous resolvers. Use ResolveByCanonicalUriAsync() instead.")] @@ -98,17 +96,7 @@ private async Tasks.Task ensureSnapshot(Resource res) { if (res is StructureDefinition sd) { - var shouldGenerate = Generator.Settings.RegenerationBehaviour switch - { - RegenerationSettings.TRY_USE_EXISTING => !sd.HasSnapshot, - RegenerationSettings.REGENERATE_ONCE => !sd.HasSnapshot || !sd.Snapshot.IsCreatedBySnapshotGenerator(), -#pragma warning disable CS0618 // Type or member is obsolete - RegenerationSettings.FORCE_REGENERATE => true, -#pragma warning restore CS0618 // Type or member is obsolete - _ => throw Error.NotSupported($"Unknown regeneration behaviour: {Generator.Settings.RegenerationBehaviour}") - }; - - if (shouldGenerate) + if (!sd.HasSnapshot || Generator.Settings.ForceRegenerateSnapshots || !sd.Snapshot.IsCreatedBySnapshotGenerator()) { await Generator.UpdateAsync(sd).ConfigureAwait(false); } @@ -119,6 +107,6 @@ private async Tasks.Task ensureSnapshot(Resource res) // Allow derived classes to override // http://blogs.msdn.com/b/jaredpar/archive/2011/03/18/debuggerdisplay-attribute-best-practices.aspx [DebuggerBrowsable(DebuggerBrowsableState.Never)] - internal protected virtual string DebuggerDisplay => $"{GetType().Name} for {Resolver.DebuggerDisplayString()}"; + internal protected virtual string DebuggerDisplay => $"{GetType().Name} for {_resolver.DebuggerDisplayString()}"; } } \ No newline at end of file diff --git a/src/Hl7.Fhir.Specification.R4.Tests/Hl7.Fhir.Specification.R4.Tests.csproj b/src/Hl7.Fhir.Specification.R4.Tests/Hl7.Fhir.Specification.R4.Tests.csproj index 74e7e05fb8..021e194225 100644 --- a/src/Hl7.Fhir.Specification.R4.Tests/Hl7.Fhir.Specification.R4.Tests.csproj +++ b/src/Hl7.Fhir.Specification.R4.Tests/Hl7.Fhir.Specification.R4.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/Hl7.Fhir.Specification.R4B.Tests/Hl7.Fhir.Specification.R4B.Tests.csproj b/src/Hl7.Fhir.Specification.R4B.Tests/Hl7.Fhir.Specification.R4B.Tests.csproj index bf6ee48a12..2f04245b98 100644 --- a/src/Hl7.Fhir.Specification.R4B.Tests/Hl7.Fhir.Specification.R4B.Tests.csproj +++ b/src/Hl7.Fhir.Specification.R4B.Tests/Hl7.Fhir.Specification.R4B.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/Hl7.Fhir.Specification.R5.Tests/Hl7.Fhir.Specification.R5.Tests.csproj b/src/Hl7.Fhir.Specification.R5.Tests/Hl7.Fhir.Specification.R5.Tests.csproj index 0347d1234c..0d7d8c18ba 100644 --- a/src/Hl7.Fhir.Specification.R5.Tests/Hl7.Fhir.Specification.R5.Tests.csproj +++ b/src/Hl7.Fhir.Specification.R5.Tests/Hl7.Fhir.Specification.R5.Tests.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/Hl7.Fhir.Specification.STU3.Tests/Snapshot/SnapshotGeneratorTest.cs b/src/Hl7.Fhir.Specification.STU3.Tests/Snapshot/SnapshotGeneratorTest.cs index 13814b8cfd..e85807f1a6 100644 --- a/src/Hl7.Fhir.Specification.STU3.Tests/Snapshot/SnapshotGeneratorTest.cs +++ b/src/Hl7.Fhir.Specification.STU3.Tests/Snapshot/SnapshotGeneratorTest.cs @@ -49,7 +49,7 @@ public class SnapshotGeneratorTest2 { // Throw on unresolved profile references; must include in TestData folder GenerateSnapshotForExternalProfiles = true, - RegenerationBehaviour = RegenerationSettings.REGENERATE_ONCE, + ForceRegenerateSnapshots = true, GenerateExtensionsOnConstraints = false, GenerateAnnotationsOnConstraints = false, GenerateElementIds = true // STU3 @@ -7979,6 +7979,7 @@ public async Tasks.Task TestConstraintSource() var element = snapshot.Should().Contain(e => e.Path == "Observation.subject").Subject; var constraint = element.Constraint.Where(c => c.Key == "ref-1").FirstOrDefault(); constraint.Source.Should().Be("http://hl7.org/fhir/StructureDefinition/Reference"); + } diff --git a/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorManifestTests.cs b/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorManifestTests.cs index e9764a5f14..fdc0260ebf 100644 --- a/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorManifestTests.cs +++ b/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorManifestTests.cs @@ -83,7 +83,7 @@ public class SnapshotGeneratorManifestTests static readonly SnapshotGeneratorSettings _snapGenSettings = new SnapshotGeneratorSettings() { - RegenerationBehaviour = RegenerationSettings.REGENERATE_ONCE, + ForceRegenerateSnapshots = true, GenerateSnapshotForExternalProfiles = true }; @@ -799,8 +799,6 @@ public SnapshotEvaluationContext( Id = id ?? throw new ArgumentNullException(nameof(id)); Assert.AreEqual(id, generated.Id); this.Tracer = this.Trace; - - this.WithResourceOverrides(Generated); } void Trace(string msg, IEnumerable elems) diff --git a/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorTest.cs b/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorTest.cs index dab716a337..593f196779 100644 --- a/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorTest.cs +++ b/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotGeneratorTest.cs @@ -58,7 +58,7 @@ public partial class SnapshotGeneratorTest2 { // Throw on unresolved profile references; must include in TestData folder GenerateSnapshotForExternalProfiles = true, - RegenerationBehaviour = RegenerationSettings.REGENERATE_ONCE, + ForceRegenerateSnapshots = true, GenerateExtensionsOnConstraints = false, GenerateAnnotationsOnConstraints = false, GenerateElementIds = true // STU3 diff --git a/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotSourceTest.cs b/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotSourceTest.cs index 0079317192..1d5646344f 100644 --- a/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotSourceTest.cs +++ b/src/Hl7.Fhir.Specification.Shared.Tests/Snapshot/SnapshotSourceTest.cs @@ -14,11 +14,11 @@ public class SnapshotSourceTest [TestMethod] public async Tasks.Task TestElementSnapshot() { - var zipSource = ZipSource.CreateValidationSource(); - var cachedSource = new CachedResolver(zipSource); - var snapSource = new SnapshotSource(cachedSource, new SnapshotGeneratorSettings{RegenerationBehaviour = RegenerationSettings.REGENERATE_ONCE}); // Request core Element snapshot; verify recursion handling + var orgSource = ZipSource.CreateValidationSource(); + var cachedSource = new CachedResolver(orgSource); + // Assumption: source provides Element structure var sdCached = await cachedSource.FindStructureDefinitionForCoreTypeAsync(FHIRAllTypes.Element); Assert.IsNotNull(sdCached); @@ -28,9 +28,11 @@ public async Tasks.Task TestElementSnapshot() // Generate snapshot by calling SnapshotSource // Important! Specify flag to force re-generation (don't trust existing core snapshots...) + var snapSource = new SnapshotSource(cachedSource, true); + var sd = await snapSource.FindStructureDefinitionForCoreTypeAsync(FHIRAllTypes.Element); Assert.IsNotNull(sd); - Assert.AreEqual(sdCached, sd); // Expecting same (cached) object reference, with updated Snapshot component + Assert.AreEqual(sdCached, sd); // Expecting same (cached) object reference, with updated Snapshot component Assert.IsTrue(sd.HasSnapshot); Assert.IsTrue(sd.Snapshot.IsCreatedBySnapshotGenerator()); @@ -73,8 +75,7 @@ void assert_ele1(ElementDefinition eld) // STU3: Element.id has type code "string" // R4: Element.id has no type code, only special "compiler magic" extensions // => Element.id no longer inherits constraints from "Element", e.g. "ele-1" - if (elem.Type?.FirstOrDefault()?.Code is string typeName && - !typeName.StartsWith("http://hl7.org/fhirpath/System.")) + if (elem.Type?.FirstOrDefault()?.Code is string typeName && !typeName.StartsWith("http://hl7.org/fhirpath/System.")) { assert_ele1(elem); } @@ -84,54 +85,24 @@ void assert_ele1(ElementDefinition eld) [TestMethod] public void CannotCreateSnapshotGeneratorFromSnapshotSource() { - var zipSource = ZipSource.CreateValidationSource(); - var cachedSource = new CachedResolver(zipSource); - var snapSource = new SnapshotSource(cachedSource, regenerate:true); + var orgSource = ZipSource.CreateValidationSource(); + var cachedSource = new CachedResolver(orgSource); + var src = new SnapshotSource(cachedSource); // Verify that SnapshotGenerator ctor rejects SnapshotSource arguments - Assert.ThrowsException(() => new SnapshotGenerator(snapSource)); + Assert.ThrowsException(() => new SnapshotGenerator(src)); } [TestMethod] public void CannotCreateNestedSnapshotSource() { - var zipSource = ZipSource.CreateValidationSource(); - var cachedSource = new CachedResolver(zipSource); - var snapSource = new SnapshotSource(cachedSource, regenerate:true); + var orgSource = ZipSource.CreateValidationSource(); + var cachedSource = new CachedResolver(orgSource); + var src = new SnapshotSource(cachedSource); // Verify that SnapshotSource ctor rejects SnapshotSource arguments - Assert.ThrowsException(() => new SnapshotSource(snapSource)); + Assert.ThrowsException(() => new SnapshotSource(src)); } - [TestMethod] - public async Tasks.Task Generate_ForceRegenerate_DoesNotReuse_SnapshotCreatedByOthers() - { - var zipSource = ZipSource.CreateValidationSource(); - var cachedSource = new CachedResolver(zipSource); - var snapSource = new SnapshotSource(cachedSource, regenerate:true); - - var original = await cachedSource.FindStructureDefinitionForCoreTypeAsync(FHIRAllTypes.Element); - Assert.IsTrue(original.HasSnapshot); - var originalSnapshot = original.Snapshot; - var regenerated = - await snapSource.FindStructureDefinitionForCoreTypeAsync(FHIRAllTypes.Element); - Assert.IsTrue(regenerated.HasSnapshot); - Assert.AreNotSame(originalSnapshot, regenerated.Snapshot); - } - - [TestMethod] - public async Tasks.Task Generate_ForceRegenerate_Reuses_SelfCreatedSnapshot() - { - var zipSource = ZipSource.CreateValidationSource(); - var cachedSource = new CachedResolver(zipSource); - var snapSource = new SnapshotSource(cachedSource, new SnapshotGeneratorSettings{RegenerationBehaviour = RegenerationSettings.REGENERATE_ONCE}); - - var first = - await snapSource.FindStructureDefinitionForCoreTypeAsync(FHIRAllTypes.Element); - var firstSnapshot = first.Snapshot; - var second = - await snapSource.FindStructureDefinitionForCoreTypeAsync(FHIRAllTypes.Element); - Assert.AreSame(firstSnapshot, second.Snapshot); - } } } \ No newline at end of file diff --git a/src/Hl7.Fhir.Support.Tests/Hl7.Fhir.Support.Tests.csproj b/src/Hl7.Fhir.Support.Tests/Hl7.Fhir.Support.Tests.csproj index 205141ab72..e2092c30dd 100644 --- a/src/Hl7.Fhir.Support.Tests/Hl7.Fhir.Support.Tests.csproj +++ b/src/Hl7.Fhir.Support.Tests/Hl7.Fhir.Support.Tests.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/Hl7.FhirPath.R4.Tests/Hl7.FhirPath.R4.Tests.csproj b/src/Hl7.FhirPath.R4.Tests/Hl7.FhirPath.R4.Tests.csproj index d71bc39716..6994304a3f 100644 --- a/src/Hl7.FhirPath.R4.Tests/Hl7.FhirPath.R4.Tests.csproj +++ b/src/Hl7.FhirPath.R4.Tests/Hl7.FhirPath.R4.Tests.csproj @@ -21,7 +21,7 @@ - + \ No newline at end of file diff --git a/src/Hl7.FhirPath.Tests/HL7.FhirPath.Tests.csproj b/src/Hl7.FhirPath.Tests/HL7.FhirPath.Tests.csproj index 779dde0d38..91d190f317 100644 --- a/src/Hl7.FhirPath.Tests/HL7.FhirPath.Tests.csproj +++ b/src/Hl7.FhirPath.Tests/HL7.FhirPath.Tests.csproj @@ -9,7 +9,7 @@ - +