-
Notifications
You must be signed in to change notification settings - Fork 539
Adds Create E2E test for all R4 Resource types #5019
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
52968c7
to
40d613f
Compare
40d613f
to
f65c3a6
Compare
src/Microsoft.Health.Fhir.Shared.Tests.Fakes/FhirFakesFactory.cs
Dismissed
Show dismissed
Hide dismissed
src/Microsoft.Health.Fhir.Shared.Tests.Fakes/FhirFakesFactory.cs
Dismissed
Show dismissed
Hide dismissed
src/Microsoft.Health.Fhir.Shared.Tests.Fakes/FhirFakesFactory.cs
Dismissed
Show dismissed
Hide dismissed
catch (Exception e) | ||
{ | ||
Trace.WriteLine("Unable to set property " + prop.Name + " on " + obj.GetType().Name + ": " + e.Message); | ||
} |
Check notice
Code scanning / CodeQL
Generic catch clause Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 25 days ago
To fix the issue, replace the generic catch (Exception e)
block with specific exception handling. The most likely exceptions that could occur in this context are:
ArgumentException
or its derived types (e.g.,ArgumentNullException
,ArgumentOutOfRangeException
) if the property value is invalid.TargetInvocationException
if the property setter throws an exception.InvalidOperationException
if the property cannot be set due to some runtime condition.
The fix involves:
- Catching these specific exceptions individually.
- Logging the exception details for debugging purposes.
- Allowing other exceptions to propagate by not catching them.
-
Copy modified line R366 -
Copy modified lines R368-R376
@@ -365,5 +365,13 @@ | ||
} | ||
catch (Exception e) | ||
catch (ArgumentException e) | ||
{ | ||
Trace.WriteLine("Unable to set property " + prop.Name + " on " + obj.GetType().Name + ": " + e.Message); | ||
Trace.WriteLine("Argument exception while setting property " + prop.Name + " on " + obj.GetType().Name + ": " + e.Message); | ||
} | ||
catch (TargetInvocationException e) | ||
{ | ||
Trace.WriteLine("Invocation exception while setting property " + prop.Name + " on " + obj.GetType().Name + ": " + e.Message); | ||
} | ||
catch (InvalidOperationException e) | ||
{ | ||
Trace.WriteLine("Invalid operation while setting property " + prop.Name + " on " + obj.GetType().Name + ": " + e.Message); | ||
} |
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.
Pull Request Overview
This PR adds a new shared test fakes project for generating and linking FHIR resources, integrates it into the solution, and updates existing E2E create tests to use the new utilities and output logging.
- Introduce
Microsoft.Health.Fhir.Shared.Tests.Fakes
project containingFhirFakesFactory
andFhirResourceExtensions
- Update Shared and R4 CreateTests to use
FhirFakesFactory
and supportITestOutputHelper
logging - Add
Bogus
package for fake data generation
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/CreateTests.cs | Made CreateTests partial and injected ITestOutputHelper for logging |
test/Microsoft.Health.Fhir.R4.Tests.E2E/Rest/CreateTests.cs | Added R4-specific CreateTests using FhirFakesFactory |
test/Microsoft.Health.Fhir.R4.Tests.E2E/Microsoft.Health.Fhir.R4.Tests.E2E.csproj | Added Bogus package reference and imported shared fakes items |
src/Microsoft.Health.Fhir.Shared.Tests.Fakes/ | New shared test fakes project, including factory and extension methods |
Directory.Packages.props | Added central version for Bogus package |
Comments suppressed due to low confidence (2)
src/Microsoft.Health.Fhir.Shared.Tests.Fakes/FhirResourceExtensions.cs:25
- The new utility method has no corresponding unit tests. Consider adding tests to verify that LinkToPatient correctly sets patient references on various resource types.
public static T LinkToPatient<T>(this T resource, Patient patient)
test/Microsoft.Health.Fhir.R4.Tests.E2E/Rest/CreateTests.cs:37
- ITestOutputHelper is used but not injected or defined in this class. Add a private ITestOutputHelper field and modify the constructor to accept and assign the output helper to enable logging.
_outputHelper.WriteLine(resourceJson);
Description
This pull request introduces a new shared project,
Microsoft.Health.Fhir.Shared.Tests.Fakes
, which provides utilities and extensions for testing FHIR resources. It also integrates the new project into the solution and updates existing tests to use these utilities.Updates to tests:
test/Microsoft.Health.Fhir.R4.Tests.E2E/Rest/CreateTests.cs
: Added tests using the newFhirFakesFactory
to create FHIR resources and bundles for testing.test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/CreateTests.cs
: Updated theCreateTests
class to use the new utilities and added support for output logging.Dependency updates:
Directory.Packages.props
: AddedBogus
package version35.6.3
to support data generation for testing.test/Microsoft.Health.Fhir.R4.Tests.E2E/Microsoft.Health.Fhir.R4.Tests.E2E.csproj
: AddedBogus
as a package reference for generating fake data.Related issues
This is an alternative approach for AB#143833
Testing
Describe how this change was tested.
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)