Skip to content

Commit

Permalink
Updates to unit tests for smoother runs in CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
GinoCanessa committed Sep 12, 2024
1 parent 32ca719 commit 1be7a30
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 302 deletions.
6 changes: 3 additions & 3 deletions src/Microsoft.Health.Fhir.CodeGen.Tests/CrossVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static string FindRelativeDir(string path)
return DirectoryContentsAttribute.FindRelativeDir(string.Empty, path, true);
}

[Theory(DisplayName = "TestLoadingFml")]
[Theory(DisplayName = "TestLoadingFml", Skip = "Tests require external repo - run manually if desired")]
[Trait("Category", "FML")]
[Trait("RequiresExternalRepo", "true")]
[Trait("ExternalRepo", "HL7/fhir-cross-version")]
Expand Down Expand Up @@ -126,7 +126,7 @@ internal IAsyncResourceResolver OnlyVersion(CrossVersionResolver resolver, strin
return null!;
}

[Theory(DisplayName = "ValidateCrossVersionMaps")]
[Theory(DisplayName = "ValidateCrossVersionMaps", Skip = "Tests are used to test FML, not this project - run manually if desired")]
[Trait("Category", "FML")]
[Trait("RequiresExternalRepo", "true")]
[Trait("ExternalRepo", "HL7/fhir-cross-version")]
Expand Down Expand Up @@ -349,7 +349,7 @@ IEnumerable<FhirStructureMap> resolveMaps(string url)
Assert.True(errorCount == 0 && warningCount == 0, $"FML Errors: {errorCount}, Warnings: {warningCount}");
}

[Theory(DisplayName = "CheckFmlMissingProps")]
[Theory(DisplayName = "CheckFmlMissingProps", Skip = "Tests are used to test FML, not this project - run manually if desired")]
[Trait("Category", "FML")]
[Trait("RequiresExternalRepo", "true")]
[Trait("ExternalRepo", "HL7/fhir-cross-version")]
Expand Down
145 changes: 52 additions & 93 deletions src/Microsoft.Health.Fhir.CodeGen.Tests/FhirPackageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,50 @@
namespace Microsoft.Health.Fhir.CodeGen.Tests;

/// <summary>A FHIR package test fixture.</summary>
public class FhirPackageTestFixture
public class FhirPackageTestBase : IDisposable
{
public readonly string? CachePath = null;
public const string? CachePath = null;

private bool _disposedValue = false;

/// <summary>
/// Initializes a new instance of the <see cref="FhirPackageTestBase"/> class.
/// </summary>
public FhirPackageTestBase()
{
}

protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}

// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
_disposedValue = true;
}
}

/// <summary>
/// Initializes a new instance of the <see cref="FhirPackageTestFixture"/> class.
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged
/// resources.
/// </summary>
public FhirPackageTestFixture()
void IDisposable.Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}

/// <summary>
/// Represents a test fixture for FHIR package tests.
/// </summary>
public class FhirPackageTestsR5 : IClassFixture<FhirPackageTestFixture>
public class FhirPackageTestsR5 : FhirPackageTestBase
{
private int _countCodeSystemsByUrl = TestCommon.EntriesR4.Length == 1 ? 448 : 485; // 448 in core, 485 in +extensions
private int _countValueSetsByUrl = TestCommon.EntriesR4.Length == 1 ? 827 : 887;
Expand All @@ -45,22 +73,9 @@ public class FhirPackageTestsR5 : IClassFixture<FhirPackageTestFixture>
private int _countImplementationGuidesByUrl = TestCommon.EntriesR4.Length == 1 ? 2 : 3; // 2 in core, 3 in +extensions
private int _countCompartmentsByUrl = 6;

/// <summary>
/// The test output helper.
/// </summary>
private readonly ITestOutputHelper _testOutputHelper;

private readonly FhirPackageTestFixture _fixture;

/// <summary>
/// Initializes a new instance of the <see cref="FhirPackageTestsR5"/> class.
/// </summary>
/// <param name="fixture">The fixture.</param>
/// <param name="testOutputHelper">The test output helper.</param>
public FhirPackageTestsR5(FhirPackageTestFixture fixture, ITestOutputHelper testOutputHelper)
/// <summary>Initializes a new instance of the <see cref="FhirPackageTestsR5"/> class.</summary>
public FhirPackageTestsR5() : base()
{
_testOutputHelper = testOutputHelper;
_fixture = fixture;
}

/// <summary>
Expand All @@ -76,8 +91,7 @@ public FhirPackageTestsR5(FhirPackageTestFixture fixture, ITestOutputHelper test
[Trait("DefaultCache", "true")]
internal async Task ParseCorePackage(LoaderOptions.JsonDeserializationModel jsonModel)
{
PackageLoader loader = new(new() { FhirCacheDirectory = _fixture.CachePath }, new() { JsonModel = jsonModel });

PackageLoader loader = new(new() { FhirCacheDirectory = CachePath }, new() { JsonModel = jsonModel });
DefinitionCollection? loaded = await loader.LoadPackages(TestCommon.EntriesR5);

loaded.Should().NotBeNull();
Expand All @@ -103,7 +117,7 @@ internal async Task ParseCorePackage(LoaderOptions.JsonDeserializationModel json
}
}

public class FhirPackageTestsR4B : IClassFixture<FhirPackageTestFixture>
public class FhirPackageTestsR4B : FhirPackageTestBase
{
private int _countCodeSystemsByUrl = TestCommon.EntriesR4.Length == 1 ? 540 : 565;
private int _countValueSetsByUrl = TestCommon.EntriesR4.Length == 1 ? 745 : 805;
Expand All @@ -119,22 +133,9 @@ public class FhirPackageTestsR4B : IClassFixture<FhirPackageTestFixture>
private int _countImplementationGuidesByUrl = TestCommon.EntriesR4.Length == 1 ? 1 : 2;
private int _countCompartmentsByUrl = 6;

/// <summary>
/// The test output helper.
/// </summary>
private readonly ITestOutputHelper _testOutputHelper;

private readonly FhirPackageTestFixture _fixture;

/// <summary>
/// Initializes a new instance of the <see cref="FhirPackageTestsR5"/> class.
/// </summary>
/// <param name="fixture">The fixture.</param>
/// <param name="testOutputHelper">The test output helper.</param>
public FhirPackageTestsR4B(FhirPackageTestFixture fixture, ITestOutputHelper testOutputHelper)
/// <summary>Initializes a new instance of the <see cref="FhirPackageTestsR4B"/> class.</summary>
public FhirPackageTestsR4B() : base()
{
_testOutputHelper = testOutputHelper;
_fixture = fixture;
}

/// <summary>
Expand All @@ -148,8 +149,7 @@ public FhirPackageTestsR4B(FhirPackageTestFixture fixture, ITestOutputHelper tes
[Trait("DefaultCache", "true")]
internal async Task ParseCorePackage()
{
PackageLoader loader = new(new() { FhirCacheDirectory = _fixture.CachePath }, new() { JsonModel = LoaderOptions.JsonDeserializationModel.Default });

PackageLoader loader = new(new() { FhirCacheDirectory = CachePath }, new() { JsonModel = LoaderOptions.JsonDeserializationModel.Default });
DefinitionCollection? loaded = await loader.LoadPackages(TestCommon.EntriesR4B);

loaded.Should().NotBeNull();
Expand All @@ -175,7 +175,7 @@ internal async Task ParseCorePackage()
}
}

public class FhirPackageTestsR4 : IClassFixture<FhirPackageTestFixture>
public class FhirPackageTestsR4 : FhirPackageTestBase
{
private int _countCodeSystemsByUrl = TestCommon.EntriesR4.Length == 1 ? 1062 : 1090;
private int _countValueSetsByUrl = TestCommon.EntriesR4.Length == 1 ? 1317 : 1377;
Expand All @@ -191,22 +191,9 @@ public class FhirPackageTestsR4 : IClassFixture<FhirPackageTestFixture>
private int _countImplementationGuidesByUrl = TestCommon.EntriesR4.Length == 1 ? 0 : 1;
private int _countCompartmentsByUrl = 6;

/// <summary>
/// The test output helper.
/// </summary>
private readonly ITestOutputHelper _testOutputHelper;

private readonly FhirPackageTestFixture _fixture;

/// <summary>
/// Initializes a new instance of the <see cref="FhirPackageTestsR4"/> class.
/// </summary>
/// <param name="fixture">The fixture.</param>
/// <param name="testOutputHelper">The test output helper.</param>
public FhirPackageTestsR4(FhirPackageTestFixture fixture, ITestOutputHelper testOutputHelper)
/// <summary>Initializes a new instance of the <see cref="FhirPackageTestsR4"/> class.</summary>
public FhirPackageTestsR4() : base()
{
_testOutputHelper = testOutputHelper;
_fixture = fixture;
}

/// <summary>
Expand All @@ -220,8 +207,7 @@ public FhirPackageTestsR4(FhirPackageTestFixture fixture, ITestOutputHelper test
[Trait("DefaultCache", "true")]
internal async Task ParseCorePackage()
{
PackageLoader loader = new(new() { FhirCacheDirectory = _fixture.CachePath }, new() { JsonModel = LoaderOptions.JsonDeserializationModel.Default });

PackageLoader loader = new(new() { FhirCacheDirectory = CachePath }, new() { JsonModel = LoaderOptions.JsonDeserializationModel.Default });
DefinitionCollection? loaded = await loader.LoadPackages(TestCommon.EntriesR4);

loaded.Should().NotBeNull();
Expand All @@ -247,7 +233,7 @@ internal async Task ParseCorePackage()
}
}

public class FhirPackageTestsR3 : IClassFixture<FhirPackageTestFixture>
public class FhirPackageTestsR3 : FhirPackageTestBase
{
private const int _countCodeSystemsByUrl = 941;
private const int _countValueSetsByUrl = 1154;
Expand All @@ -263,22 +249,9 @@ public class FhirPackageTestsR3 : IClassFixture<FhirPackageTestFixture>
private const int _countImplementationGuidesByUrl = 2;
private const int _countCompartmentsByUrl = 6;

/// <summary>
/// The test output helper.
/// </summary>
private readonly ITestOutputHelper _testOutputHelper;

private readonly FhirPackageTestFixture _fixture;

/// <summary>
/// Initializes a new instance of the <see cref="FhirPackageTestsR3"/> class.
/// </summary>
/// <param name="fixture">The fixture.</param>
/// <param name="testOutputHelper">The test output helper.</param>
public FhirPackageTestsR3(FhirPackageTestFixture fixture, ITestOutputHelper testOutputHelper)
/// <summary>Initializes a new instance of the <see cref="FhirPackageTestsR3"/> class.</summary>
public FhirPackageTestsR3() : base()
{
_testOutputHelper = testOutputHelper;
_fixture = fixture;
}

/// <summary>
Expand All @@ -292,8 +265,7 @@ public FhirPackageTestsR3(FhirPackageTestFixture fixture, ITestOutputHelper test
[Trait("DefaultCache", "true")]
internal async Task ParseCorePackage()
{
PackageLoader loader = new(new() { FhirCacheDirectory = _fixture.CachePath }, new() { JsonModel = LoaderOptions.JsonDeserializationModel.Default });

PackageLoader loader = new(new() { FhirCacheDirectory = CachePath }, new() { JsonModel = LoaderOptions.JsonDeserializationModel.Default });
DefinitionCollection? loaded = await loader.LoadPackages(TestCommon.EntriesR3);

loaded.Should().NotBeNull();
Expand All @@ -319,7 +291,7 @@ internal async Task ParseCorePackage()
}
}

public class FhirPackageTestsR2 : IClassFixture<FhirPackageTestFixture>
public class FhirPackageTestsR2 : FhirPackageTestBase
{
private const int _countCodeSystemsByUrl = 822; // note - there are zero in the definitions, the 822 are contained in VS resources
private const int _countValueSetsByUrl = 1016;
Expand All @@ -335,22 +307,9 @@ public class FhirPackageTestsR2 : IClassFixture<FhirPackageTestFixture>
private const int _countImplementationGuidesByUrl = 0;
private const int _countCompartmentsByUrl = 0;

/// <summary>
/// The test output helper.
/// </summary>
private readonly ITestOutputHelper _testOutputHelper;

private readonly FhirPackageTestFixture _fixture;

/// <summary>
/// Initializes a new instance of the <see cref="FhirPackageTestsR2"/> class.
/// </summary>
/// <param name="fixture">The fixture.</param>
/// <param name="testOutputHelper">The test output helper.</param>
public FhirPackageTestsR2(FhirPackageTestFixture fixture, ITestOutputHelper testOutputHelper)
/// <summary>Initializes a new instance of the <see cref="FhirPackageTestsR2"/> class.</summary>
public FhirPackageTestsR2() : base()
{
_testOutputHelper = testOutputHelper;
_fixture = fixture;
}

/// <summary>
Expand All @@ -364,7 +323,7 @@ public FhirPackageTestsR2(FhirPackageTestFixture fixture, ITestOutputHelper test
[Trait("DefaultCache", "true")]
internal async Task ParseCorePackage()
{
PackageLoader loader = new(new() { FhirCacheDirectory = _fixture.CachePath }, new() { JsonModel = LoaderOptions.JsonDeserializationModel.Default });
PackageLoader loader = new(new() { FhirCacheDirectory = CachePath }, new() { JsonModel = LoaderOptions.JsonDeserializationModel.Default });

DefinitionCollection? loaded = await loader.LoadPackages(TestCommon.EntriesR2);

Expand Down
Loading

0 comments on commit 1be7a30

Please sign in to comment.