MINOR FOUNDATION: Repository ForeignKey Tests#332
Merged
Conversation
…ursAndLogItAsync -> FAIL * Closes: #310
…ursAndLogItAsync -> FAIL
…ursAndLogItAsync -> PASS
…rsAndLogItAsync -> PASS
There was a problem hiding this comment.
Pull Request Overview
This PR adds handling for foreign key constraint conflicts in the repository service by introducing a new exception type and covering the new logic with unit tests.
- Added a catch block for
ForeignKeyConstraintConflictExceptioninRepositoryService.Exceptions.cs - Introduced
InvalidRepositoryReferenceExceptionin the models - Added unit tests for Add and Modify flows to verify foreign key error handling
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| GitFyle.Core.Api/Services/Foundations/Repositories/RepositoryService.Exceptions.cs | Added catch block to wrap FK constraint errors into validation exceptions |
| GitFyle.Core.Api/Models/Foundations/Repositories/Exceptions/InvalidRepositoryReferenceException.cs | New exception class for invalid repository references |
| GitFyle.Core.Api.Tests.Unit/Services/Foundations/Repositories/RepositoryServiceTests.Exceptions.Modify.cs | Test for Modify flow handling of foreign key conflicts |
| GitFyle.Core.Api.Tests.Unit/Services/Foundations/Repositories/RepositoryServiceTests.Exceptions.Add.cs | Test for Add flow handling of foreign key conflicts |
Comments suppressed due to low confidence (3)
GitFyle.Core.Api.Tests.Unit/Services/Foundations/Repositories/RepositoryServiceTests.Exceptions.Add.cs:202
- To more accurately simulate a database foreign key violation, consider throwing
ForeignKeyConstraintConflictExceptionfromstorageBroker.InsertRepositoryAsyncinstead ofdateTimeBroker.GetCurrentDateTimeOffsetAsync. This ensures the exception flows through the repository insert logic.
this.dateTimeBrokerMock.Setup(broker =>
GitFyle.Core.Api.Tests.Unit/Services/Foundations/Repositories/RepositoryServiceTests.Exceptions.Modify.cs:216
- To better reflect where a foreign key error would occur, throw
ForeignKeyConstraintConflictExceptionfromstorageBroker.UpdateRepositoryAsyncrather than fromdateTimeBroker.GetCurrentDateTimeOffsetAsync. This aligns the test with the actual failure point.
this.dateTimeBrokerMock.Setup(broker =>
GitFyle.Core.Api/Models/Foundations/Repositories/Exceptions/InvalidRepositoryReferenceException.cs:11
- [nitpick] Add XML documentation comments for
InvalidRepositoryReferenceExceptionto explain when this exception is thrown and its intended use.
public class InvalidRepositoryReferenceException : Xeption
aosunlana
approved these changes
Jun 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.