Skip to content

Conversation

@v-isyamauchi-gh
Copy link
Contributor

Description

Adding E2E tests for InstantiatesCapabilityProvider.

Related issues

Addresses [issue #95785].

User Story 95785: Instantiate field and export endpoint is added under Capability statement

Testing

Tested by running them locally.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

@v-isyamauchi-gh v-isyamauchi-gh added this to the CY25Q3/2Wk07 milestone Jan 21, 2026
@v-isyamauchi-gh v-isyamauchi-gh requested a review from a team as a code owner January 21, 2026 16:37
@v-isyamauchi-gh v-isyamauchi-gh added Enhancement-Test Enhancement on tests. Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Open source This change is only relevant to the OSS code or release. No-PaaS-breaking-change No-ADR ADR not needed labels Jan 21, 2026

var response = await Client.ReadAsync<CapabilityStatement>("metadata");
Assert.NotNull(response?.Resource);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning test

Variable
response
may be null at this access as suggested by
this
null check.

Copilot Autofix

AI 1 day ago

In general, to fix this problem we must ensure that response is known to be non-null before any dereference. This can be done either by adding an explicit null check (with an assertion, since this is test code) or by restructuring code so that dereferences occur only when response is non-null.

The best fix with minimal behavior change is to add an explicit Assert.NotNull(response); immediately after the ReadAsync call and then remove the unnecessary null-conditional operator on response when asserting about the Resource. This both documents the expectation that response is never null in this test scenario and satisfies the static analysis tool by establishing a clear non-null guarantee on all paths that reach response.StatusCode. Concretely:

  • In GivenMetadataRequest_WhenUSCore6ProfileIsUploaded_TheInstantiatesFieldShouldBePopulated, after var response = await Client.ReadAsync<CapabilityStatement>("metadata");, insert Assert.NotNull(response);.
  • Replace Assert.NotNull(response?.Resource); with Assert.NotNull(response.Resource); now that response is checked.
    No additional imports or helper methods are needed.
Suggested changeset 1
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Conformance/InstantiatesCapabilityProviderTests.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Conformance/InstantiatesCapabilityProviderTests.cs b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Conformance/InstantiatesCapabilityProviderTests.cs
--- a/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Conformance/InstantiatesCapabilityProviderTests.cs
+++ b/test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Conformance/InstantiatesCapabilityProviderTests.cs
@@ -57,7 +57,8 @@
                 }
 
                 var response = await Client.ReadAsync<CapabilityStatement>("metadata");
-                Assert.NotNull(response?.Resource);
+                Assert.NotNull(response);
+                Assert.NotNull(response.Resource);
                 Assert.Equal(HttpStatusCode.OK, response.StatusCode);
 
                 var instantiates = response.Resource.Instantiates?.ToList() ?? new List<string>();
EOF
@@ -57,7 +57,8 @@
}

var response = await Client.ReadAsync<CapabilityStatement>("metadata");
Assert.NotNull(response?.Resource);
Assert.NotNull(response);
Assert.NotNull(response.Resource);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

var instantiates = response.Resource.Instantiates?.ToList() ?? new List<string>();
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't fix. A null check is done at Ln:60, and both 'response' and 'Resource' shouldn't be null.

@v-isyamauchi-gh
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Enhancement-Test Enhancement on tests. No-ADR ADR not needed No-PaaS-breaking-change Open source This change is only relevant to the OSS code or release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants