feat: add tests for sources - #77
Conversation
emil720a1
left a comment
There was a problem hiding this comment.
The tests pass locally and the PR scope is clean. One improvement: the repository predicates are currently matched with It.IsAny, so the tests would still pass if a handler used the wrong id, streetcodeId, or categoryId. Please consider validating the compiled predicates. Also, GetAllAsync() returns an empty collection rather than null, so an empty-result test would represent the real repository behavior better.
DrFaust555
left a comment
There was a problem hiding this comment.
-
GetAllCategoriesHandlerTests.cs, lines 42-52: the test is named
WhenRepositoryReturnsEmptyCollection, but the second Setup overrides the
first one, so the handler still receives null. The empty-list setup is
dead code. Split into two tests: an empty list must give IsSuccess with
an empty Value; null must give IsFailed with "Categories is null". -
Same file, line 40 area: the fix commit removed
_blobServiceMock.Verify(b => b.FindFileInStorageAsBase64("test.jpg"),
Times.Once) from the positive test. Restore it and assert
result.Value.First().Image.Base64 == "base64string". Do the same in
GetCategoriesByStreetcodeIdHandlerTests.cs and
GetCategoryByIdHandlerTests.cs, where the blob service is set up but
never checked. -
Fix the 169 Sonar issues in the five test files: add the file header
(SA1633), move usings inside the namespace block (SA1200), prefix member
calls with this (SA1101), rename fields without the underscore (SA1309),
use new () with a space or the explicit type (SA1000), trailing commas in
multi-line initializers (SA1413). Replace Assert.IsAssignableFrom with
Assert.IsType(value, exactMatch: false) (xUnit2032). -
PR description: remove the stray "dev" line above ## JIRA, replace the
placeholder JIRA link with the GitHub issue, add "Closes #65".
|



JIRA
Code reviewers
Second Level Review
Summary of issue
The
Sourcemodule (specificallySourceLinkCategory) lacked unit tests for its MediatR handlers, leaving both positive and negative scenarios uncovered.Summary of change
Added comprehensive unit test classes for the following MediatR handlers:
GetAllCategoriesHandlerTestsGetAllCategoryNamesHandlerTestsGetCategoriesByStreetcodeIdHandlerTestsGetCategoryByIdHandlerTestsGetCategoryContentByStreetcodeIdHandlerTestsTesting approach
Positive scenarios: Mocked
IRepositoryWrapperto return valid entities. Verified that the handlers return a successful result (IsSuccess), checked for the correct returned data types usingAssert.IsTypeandAssert.IsAssignableFrom, and verified the correct count of items (e.g., usingAssert.Single).Negative scenarios: Simulated missing data by mocking repositories to return
null. Verified that the handlers returnIsFailed, assert the exact expected error messages, and verified thatILoggerService.LogErroris called exactly once with the correct message.CHECK LIST
Closes #65