Skip to content

Commit

Permalink
Fix: migrated Compartment tests to Shouldly.
Browse files Browse the repository at this point in the history
  • Loading branch information
GinoCanessa committed Jan 27, 2025
1 parent eaebf17 commit 296409e
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/fhir-candle.Tests/CompartmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
extern alias coreR4;

using System.Net;
using candleR4::FhirCandle.Models;
using candleR4::FhirCandle.Storage;
using Hl7.Fhir.Model;
using fhir.candle.Tests.Extensions;
using FhirCandle.Utils;
using FluentAssertions;
using Hl7.Fhir.Introspection;
using Hl7.Fhir.Specification;
using Xunit.Abstractions;
using FhirRequestContext = FhirCandle.Models.FhirRequestContext;
using FhirResponseContext = FhirCandle.Models.FhirResponseContext;
using Resource = Hl7.Fhir.Model.Resource;
using TenantConfiguration = FhirCandle.Models.TenantConfiguration;
using Shouldly;

namespace fhir.candle.Tests;

Expand Down Expand Up @@ -49,7 +46,7 @@ public void TestCompartmentTypeSearch(string json)
// load compartment
var jsonParser = new coreR4::Hl7.Fhir.Serialization.FhirJsonParser();
var compartmentDefinition = jsonParser.Parse(json) as coreR4::Hl7.Fhir.Model.CompartmentDefinition;
compartmentDefinition.Should().NotBeNull();
compartmentDefinition.ShouldNotBeNull();

string path = Path.GetRelativePath(Directory.GetCurrentDirectory(), "data/r4");
DirectoryInfo? loadDirectory = null;
Expand Down Expand Up @@ -77,27 +74,27 @@ public void TestCompartmentTypeSearch(string json)

// all observations
var searchAllBundle = SearchResource(versionedFhirStore, "Observation");
searchAllBundle.Should().NotBeNull();
searchAllBundle.Entry.Should().NotBeNullOrEmpty();
searchAllBundle.Entry.Count.Should().BeGreaterThan(0);
searchAllBundle.ShouldNotBeNull();
searchAllBundle.Entry.ShouldNotBeNullOrEmpty();
searchAllBundle.Entry.Count.ShouldBeGreaterThan(0);
var searchAllBundleCount = searchAllBundle.Entry.Count;

// all observations for patient example
var searchBundle = SearchResource(versionedFhirStore, "Observation?subject=example");
searchBundle.Should().NotBeNull();
searchBundle.Entry.Should().NotBeNullOrEmpty();
searchBundle.Entry.Count.Should().BeGreaterThan(0);
searchBundle.ShouldNotBeNull();
searchBundle.Entry.ShouldNotBeNullOrEmpty();
searchBundle.Entry.Count.ShouldBeGreaterThan(0);
var searchBundleCount = searchBundle.Entry.Count;

// all observations for patient example using compartment
var compartmentBundle = SearchResource(versionedFhirStore, "Patient/example/Observation");
compartmentBundle.Should().NotBeNull();
compartmentBundle.Entry.Should().NotBeNullOrEmpty();
compartmentBundle.Entry.Count.Should().BeGreaterThan(0);
compartmentBundle.ShouldNotBeNull();
compartmentBundle.Entry.ShouldNotBeNullOrEmpty();
compartmentBundle.Entry.Count.ShouldBeGreaterThan(0);
var compartmentBundleCount = compartmentBundle.Entry.Count;

// check if direct and compartment search returns equal numbers
compartmentBundleCount.Should().Be(searchBundleCount);
compartmentBundleCount.ShouldBe(searchBundleCount);
}

private Bundle SearchResource(VersionedFhirStore versionedFhirStore, String search )
Expand All @@ -118,13 +115,13 @@ private Bundle SearchResource(VersionedFhirStore versionedFhirStore, String sear
ctx,
out FhirResponseContext response);

success.Should().BeTrue();
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.SerializedResource.Should().NotBeNullOrEmpty();
success.ShouldBeTrue();
response.StatusCode.ShouldBe(HttpStatusCode.OK);
response.SerializedResource.ShouldNotBeNullOrEmpty();

response.Resource.Should().NotBeNull();
response.Resource.ShouldNotBeNull();
var result = response.Resource;
result.GetType().ToString().Should().Be("Hl7.Fhir.Model.Bundle");
result.GetType().ToString().ShouldBe("Hl7.Fhir.Model.Bundle");

var bundle = result as Bundle;
return bundle;
Expand Down

0 comments on commit 296409e

Please sign in to comment.