Skip to content

Conversation

@rbans96
Copy link
Contributor

@rbans96 rbans96 commented Dec 4, 2025

Description

Add tests to improve R4.Core tests coverage

Related issues

Addresses 174931

Testing

Describe how this change was tested.

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)

@rbans96 rbans96 requested a review from a team as a code owner December 4, 2025 22:13
@rbans96 rbans96 added Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR labels Dec 4, 2025
@rbans96 rbans96 added this to the CY25Q3/2Wk07 milestone Dec 4, 2025
@rbans96 rbans96 added the Enhancement-Test Enhancement on tests. label Dec 4, 2025
{
// Arrange
const string operationName = "export";
var cancellationTokenSource = new CancellationTokenSource();

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable Warning

Disposable 'CancellationTokenSource' is created but not disposed.
Comment on lines +346 to +356
foreach (var type in new[] { "ValueSet", "CodeSystem", "StructureDefinition" })
{
if (type != resourceType)
{
_searchService.SearchAsync(
type,
Arg.Any<List<Tuple<string, string>>>(),
Arg.Any<CancellationToken>())
.Returns(new SearchResult(new List<SearchResultEntry>(), null, null, new List<Tuple<string, string>>()));
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where Note

This foreach loop
implicitly filters its target sequence
- consider filtering the sequence explicitly using '.Where(...)'.

Copilot Autofix

AI 5 days ago

To address the issue, the foreach loop in SetupSearchServiceWithResults should iterate only over elements where type != resourceType, utilizing LINQ's .Where(...) method for clarity and intent. The if (type != resourceType) guard inside the loop becomes superfluous and should be removed. There is no change to existing functionality—just a refactor to express filtering more idiomatically. Only the loop over the array on line 322–332 in SetupSearchServiceWithResults needs to be updated. Since System.Linq is already imported (line 8), no imports are required.


Suggested changeset 1
src/Microsoft.Health.Fhir.R4.Core.UnitTests/Features/Validation/ServerProvideProfileValidationTests.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/src/Microsoft.Health.Fhir.R4.Core.UnitTests/Features/Validation/ServerProvideProfileValidationTests.cs b/src/Microsoft.Health.Fhir.R4.Core.UnitTests/Features/Validation/ServerProvideProfileValidationTests.cs
--- a/src/Microsoft.Health.Fhir.R4.Core.UnitTests/Features/Validation/ServerProvideProfileValidationTests.cs
+++ b/src/Microsoft.Health.Fhir.R4.Core.UnitTests/Features/Validation/ServerProvideProfileValidationTests.cs
@@ -319,16 +319,13 @@
                 .Returns(searchResult);
 
             // Setup for other resource types to return empty
-            foreach (var type in new[] { "ValueSet", "CodeSystem", "StructureDefinition" })
+            foreach (var type in new[] { "ValueSet", "CodeSystem", "StructureDefinition" }.Where(type => type != resourceType))
             {
-                if (type != resourceType)
-                {
-                    _searchService.SearchAsync(
-                        type,
-                        Arg.Any<List<Tuple<string, string>>>(),
-                        Arg.Any<CancellationToken>())
-                        .Returns(new SearchResult(new List<SearchResultEntry>(), null, null, new List<Tuple<string, string>>()));
-                }
+                _searchService.SearchAsync(
+                    type,
+                    Arg.Any<List<Tuple<string, string>>>(),
+                    Arg.Any<CancellationToken>())
+                    .Returns(new SearchResult(new List<SearchResultEntry>(), null, null, new List<Tuple<string, string>>()));
             }
         }
 
EOF
@@ -319,16 +319,13 @@
.Returns(searchResult);

// Setup for other resource types to return empty
foreach (var type in new[] { "ValueSet", "CodeSystem", "StructureDefinition" })
foreach (var type in new[] { "ValueSet", "CodeSystem", "StructureDefinition" }.Where(type => type != resourceType))
{
if (type != resourceType)
{
_searchService.SearchAsync(
type,
Arg.Any<List<Tuple<string, string>>>(),
Arg.Any<CancellationToken>())
.Returns(new SearchResult(new List<SearchResultEntry>(), null, null, new List<Tuple<string, string>>()));
}
_searchService.SearchAsync(
type,
Arg.Any<List<Tuple<string, string>>>(),
Arg.Any<CancellationToken>())
.Returns(new SearchResult(new List<SearchResultEntry>(), null, null, new List<Tuple<string, string>>()));
}
}

Copilot is powered by AI and may make mistakes. Always verify output.
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants