Skip to content

feat: add tests for sources - #77

Open
Laminate32 wants to merge 5 commits into
devfrom
test/65/write-tests-for-sources
Open

feat: add tests for sources#77
Laminate32 wants to merge 5 commits into
devfrom
test/65/write-tests-for-sources

Conversation

@Laminate32

@Laminate32 Laminate32 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

JIRA

Code reviewers

Second Level Review

Summary of issue

The Source module (specifically SourceLinkCategory) 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:

  • GetAllCategoriesHandlerTests
  • GetAllCategoryNamesHandlerTests
  • GetCategoriesByStreetcodeIdHandlerTests
  • GetCategoryByIdHandlerTests
  • GetCategoryContentByStreetcodeIdHandlerTests

Testing approach

  • Positive scenarios: Mocked IRepositoryWrapper to return valid entities. Verified that the handlers return a successful result (IsSuccess), checked for the correct returned data types using Assert.IsType and Assert.IsAssignableFrom, and verified the correct count of items (e.g., using Assert.Single).

  • Negative scenarios: Simulated missing data by mocking repositories to return null. Verified that the handlers return IsFailed, assert the exact expected error messages, and verified that ILoggerService.LogError is called exactly once with the correct message.

CHECK LIST

  • СI passed
  • Сode coverage >=95%
  • PR is reviewed manually again (to make sure you have 100% ready code)
  • All reviewers agreed to merge the PR
  • I've checked new feature as logged in and logged out user if needed
  • PR meets all conventions

Closes #65

@Laminate32 Laminate32 linked an issue Aug 18, 2026 that may be closed by this pull request

@emil720a1 emil720a1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

skorpionreser
skorpionreser previously approved these changes Aug 19, 2026

@skorpionreser skorpionreser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@DrFaust555 DrFaust555 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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".

  2. 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.

  3. 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).

  4. PR description: remove the stray "dev" line above ## JIRA, replace the
    placeholder JIRA link with the GitHub issue, add "Closes #65".

@Laminate32
Laminate32 requested a review from DrFaust555 August 24, 2026 16:53
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write tests for MediatR/Source

4 participants