Improve test coverage for SqlServer project#5335
Conversation
There was a problem hiding this comment.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
...s/Search/Expressions/Visitors/QueryGenerators/PrimaryKeyRangeParameterQueryGeneratorTests.cs
Fixed
Show fixed
Hide fixed
...itTests/Features/Search/Expressions/Visitors/QueryGenerators/ReferenceQueryGeneratorTests.cs
Fixed
Show fixed
Hide fixed
...es/Search/Expressions/Visitors/QueryGenerators/ReferenceTokenCompositeQueryGeneratorTests.cs
Fixed
Show fixed
Hide fixed
...atures/Search/Expressions/Visitors/QueryGenerators/ResourceIdParameterQueryGeneratorTests.cs
Fixed
Show fixed
Hide fixed
...arch/Expressions/Visitors/QueryGenerators/ResourceSurrogateIdParameterQueryGeneratorTests.cs
Fixed
Show fixed
Hide fixed
...itTests/Features/Search/Expressions/Visitors/QueryGenerators/TokenTextQueryGeneratorTests.cs
Fixed
Show fixed
Hide fixed
...atures/Search/Expressions/Visitors/QueryGenerators/TokenTokenCompositeQueryGeneratorTests.cs
Fixed
Show fixed
Hide fixed
...ver.UnitTests/Features/Search/Expressions/Visitors/QueryGenerators/UriQueryGeneratorTests.cs
Fixed
Show fixed
Hide fixed
...h.Fhir.SqlServer.UnitTests/Features/Storage/Registry/SearchParameterStatusCollectionTests.cs
Dismissed
Show dismissed
Hide dismissed
...th.Fhir.SqlServer.UnitTests/Features/Search/Expressions/DateTimeBoundedRangeRewriterTests.cs
Fixed
Show fixed
Hide fixed
...alth.Fhir.Shared.Tests.Integration/Features/Search/SqlServerSearchServiceIntegrationTests.cs
Outdated
Show resolved
Hide resolved
...alth.Fhir.Shared.Tests.Integration/Features/Search/SqlServerSearchServiceIntegrationTests.cs
Outdated
Show resolved
Hide resolved
...alth.Fhir.Shared.Tests.Integration/Features/Search/SqlServerSearchServiceIntegrationTests.cs
Outdated
Show resolved
Hide resolved
...alth.Fhir.Shared.Tests.Integration/Features/Search/SqlServerSearchServiceIntegrationTests.cs
Outdated
Show resolved
Hide resolved
...alth.Fhir.Shared.Tests.Integration/Features/Search/SqlServerSearchServiceIntegrationTests.cs
Outdated
Show resolved
Hide resolved
...alth.Fhir.Shared.Tests.Integration/Features/Search/SqlServerSearchServiceIntegrationTests.cs
Outdated
Show resolved
Hide resolved
...alth.Fhir.Shared.Tests.Integration/Features/Search/SqlServerSearchServiceIntegrationTests.cs
Fixed
Show fixed
Hide fixed
mikaelweave
left a comment
There was a problem hiding this comment.
Added a suggestion to strengthen the SQL assertion for reference token composite generator.
...itTests/Features/Search/Expressions/Visitors/QueryGenerators/ReferenceQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...itTests/Features/Search/Expressions/Visitors/QueryGenerators/ReferenceQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...es/Search/Expressions/Visitors/QueryGenerators/ReferenceTokenCompositeQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
mikaelweave
left a comment
There was a problem hiding this comment.
Added suggestions to strengthen SQL assertions for remaining query generator tests.
...es/Search/Expressions/Visitors/QueryGenerators/ReferenceTokenCompositeQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...itTests/Features/Search/Expressions/Visitors/QueryGenerators/ReferenceQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...es/Search/Expressions/Visitors/QueryGenerators/ReferenceTokenCompositeQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...es/Search/Expressions/Visitors/QueryGenerators/ReferenceTokenCompositeQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...es/Search/Expressions/Visitors/QueryGenerators/ReferenceTokenCompositeQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...itTests/Features/Search/Expressions/Visitors/QueryGenerators/TokenTextQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...itTests/Features/Search/Expressions/Visitors/QueryGenerators/TokenTextQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...atures/Search/Expressions/Visitors/QueryGenerators/TokenTokenCompositeQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...atures/Search/Expressions/Visitors/QueryGenerators/TokenTokenCompositeQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...atures/Search/Expressions/Visitors/QueryGenerators/TokenTokenCompositeQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
mikaelweave
left a comment
There was a problem hiding this comment.
Added comments for remaining generator/unit/integration test assertion improvements per pr_review_5335 analyses.
...Tests/Features/Search/Expressions/Visitors/QueryGenerators/CompartmentQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...Tests/Features/Search/Expressions/Visitors/QueryGenerators/CompartmentQueryGeneratorTests.cs
Show resolved
Hide resolved
...Tests/Features/Search/Expressions/Visitors/QueryGenerators/CompartmentQueryGeneratorTests.cs
Show resolved
Hide resolved
...Tests/Features/Search/Expressions/Visitors/QueryGenerators/CompartmentQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...Tests/Features/Search/Expressions/Visitors/QueryGenerators/CompartmentQueryGeneratorTests.cs
Show resolved
Hide resolved
....UnitTests/Features/Search/Expressions/Visitors/QueryGenerators/StringQueryGeneratorTests.cs
Show resolved
Hide resolved
...nitTests/Features/Search/Expressions/Visitors/QueryGenerators/QuantityQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...nitTests/Features/Search/Expressions/Visitors/QueryGenerators/QuantityQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...ver.UnitTests/Features/Search/Expressions/Visitors/QueryGenerators/UriQueryGeneratorTests.cs
Show resolved
Hide resolved
....UnitTests/Features/Search/Expressions/Visitors/QueryGenerators/StringQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
- Combine assertions in ReferenceQueryGeneratorTests to verify specific values (ReferenceResourceTypeId = {value})
- Update BaseUri null check to assert specific column name (BaseUri IS NULL)
- Strengthen ReferenceTokenCompositeQueryGeneratorTests assertions:
* Use regex patterns to validate component-indexed columns (ReferenceResourceId1, Code2)
* Verify specific NULL checks for component columns (BaseUri1 IS NULL, SystemId2 IS NULL)
- Add exact count assertion for GetSurrogateIdRanges test (Assert.Equal(5, ranges.Count()))
- Remove redundant range count check
All tests passing (36/36 tests)
|
Addressed review comments from @mikaelweave in commit b80537e: ✅ ReferenceQueryGeneratorTests.cs:
✅ ReferenceTokenCompositeQueryGeneratorTests.cs:
✅ SqlServerSearchServiceIntegrationTests.cs:
All tests passing (36/36 tests). |
- Remove unused patient variable in GetStatsFromCache_AfterSearch_ReturnsPopulatedCollection test - The variable was assigned but never read, causing a code scanning alert Addresses: #5335 (comment)
- ResourceIdParameterQueryGeneratorTests: Added regex assertions for ResourceId = and LIKE patterns - ResourceSurrogateIdParameterQueryGeneratorTests: Added regex assertions for ResourceSurrogateId with =, >, < operators - TokenQueryGeneratorTests: Strengthened SystemId, Code assertions with regex patterns - TokenTextQueryGeneratorTests: Strengthened Text column assertions with = and LIKE patterns - TokenTokenCompositeQueryGeneratorTests: Added Code1, Code2 column verifications - TokenNumberNumberQueryGeneratorTests: Added SingleValue2 null-guard and component assertions - TokenDateTimeCompositeQueryGeneratorTests: Added Code1, StartDateTime2 column verifications - CompartmentQueryGeneratorTests: Added regex assertions for CompartmentTypeId and ReferenceResourceId - DateTimeQueryGeneratorTests: Added regex assertions for StartDateTime, EndDateTime, IsLongerThanADay - NumberQueryGeneratorTests: Added regex assertions for SingleValue, LowValue, HighValue columns - StringQueryGeneratorTests: Strengthened Text column assertions for =, LIKE patterns - UriQueryGeneratorTests: Added regex assertion for Uri column - QuantityQueryGeneratorTests: Strengthened SingleValue, LowValue, HighValue, QuantityCodeId, SystemId assertions - PrimaryKeyRangeParameterQueryGeneratorTests: Added regex assertions for ResourceTypeId (literal) and ResourceSurrogateId (param) - DateTimeBoundedRangeRewriterTests: Added System.Linq using and refactored to use Select() - SqlServerSearchParameterStatusDataStoreTests: Replaced Assert.True(true) with Assert.Null(Record.Exception())
- CompartmentQueryGeneratorTests: Verify special characters are parameterized (not raw in SQL) - PrimaryKeyRangeParameterQueryGeneratorTests: Verify full predicate shape and IN clause contains expected ids - TokenTokenCompositeQueryGeneratorTests: Strengthen assertion to verify Code1 column with component suffix
mikaelweave
left a comment
There was a problem hiding this comment.
Added targeted recommendations for each reported finding (core/complex/integration) with concrete assertion alternatives tied to the implementation.
src/Microsoft.Health.Fhir.SqlServer.UnitTests/Features/ExceptionExtensionTests.cs
Show resolved
Hide resolved
...Tests/Features/Search/Expressions/Visitors/QueryGenerators/CompartmentQueryGeneratorTests.cs
Show resolved
Hide resolved
| var sql = context.StringBuilder.ToString(); | ||
|
|
||
| Assert.NotEmpty(sql); | ||
| Assert.True(context.Parameters.HasParametersToHash); |
There was a problem hiding this comment.
Finding: UTC conversion not validated. Recommendation: assert the parameter equals localDateTime.UtcDateTime (or UtcDateTime), and that SQL targets StartDateTime with the correct operator.
|
|
||
| var sql = context.StringBuilder.ToString(); | ||
|
|
||
| Assert.Matches($@"{VLatest.StringSearchParam.Text.Metadata.Name}\s+LIKE\s+@\w+", sql); |
There was a problem hiding this comment.
Finding: LIKE check is too generic. Recommendation: assert the parameter value is %value% for Contains (or value% for StartsWith), and include collation if applicable.
...r.UnitTests/Features/Search/Expressions/Visitors/QueryGenerators/TokenQueryGeneratorTests.cs
Show resolved
Hide resolved
...atures/Search/Expressions/Visitors/QueryGenerators/TokenTokenCompositeQueryGeneratorTests.cs
Outdated
Show resolved
Hide resolved
...th.Fhir.Shared.Tests.Integration/Persistence/SqlServerSearchParameterStatusDataStoreTests.cs
Show resolved
Hide resolved
Response to Unresolved Review CommentsI've analyzed all unresolved, non-outdated review comments and here's the status: ✅ Already AddressedSearchParameterStatusCollectionTests.cs (line 255) - "Useless upcast"
TokenTokenCompositeQueryGeneratorTests.cs (line 170) - Code1/Code2 assertions
PrimaryKeyRangeParameterQueryGeneratorTests.cs (line 196) - IN clause assertions
PrimaryKeyRangeParameterQueryGeneratorTests.cs (line 89) - Predicate shape
CompartmentQueryGeneratorTests.cs (line 76) - Predicate shape
SqlServerSearchParameterStatusDataStoreTests.cs (line 170) - Assert.True(true) bypass
ExceptionExtensionTests.cs (line 20) - Missing test patterns
📋 Requires Infrastructure Changes (Not Addressed)The following comments request parameter VALUE validation. This would require significant infrastructure refactoring because the
These would need a test infrastructure change to preserve parameter values, which is beyond the scope of this PR focused on test coverage improvements. Test ResultsAll modified tests pass: |
Description
Improve test coverage for SqlServer project.
Related issues
Addresses [174927].
Testing
Describe how this change was tested.
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)