-
Notifications
You must be signed in to change notification settings - Fork 576
Adding E2E tests for InstantiatesCapabilityProvider. #5341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| 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
response
this
Show autofix suggestion
Hide autofix suggestion
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, aftervar response = await Client.ReadAsync<CapabilityStatement>("metadata");, insertAssert.NotNull(response);. - Replace
Assert.NotNull(response?.Resource);withAssert.NotNull(response.Resource);now thatresponseis checked.
No additional imports or helper methods are needed.
-
Copy modified lines R60-R61
| @@ -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>(); |
There was a problem hiding this comment.
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.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)