Skip to content

test: add unit tests for spaced repetition - #49

Merged
Dejmenek merged 6 commits into
mainfrom
42-add-unit-tests-for-spaced-repetition
Sep 6, 2025
Merged

Dejmenek merged 6 commits into
mainfrom
42-add-unit-tests-for-spaced-repetition

Conversation

@Dejmenek

@Dejmenek Dejmenek commented Sep 6, 2025

Copy link
Copy Markdown
Owner

Summary

This pull request adds unit tests for various methods in the StudySessionsService and modifies the BaseCardDto class to include default property values.

Changes

  • StudySessionsServiceTests.cs: Added unit tests for GetNextBox, GetNextReviewDate, StartStudySessionAsync, RunStudySessionAsync, and GetAllStudySessionsAsync.
  • StudySessionsServiceTests.cs: Introduced reflection methods InvokeGetNextBox and InvokeGetNextReviewDate for testing private methods.
  • Flashcard.cs: Updated BaseCardDto to set default values for Box (defaulting to 1) and NextReviewDate (defaulting to DateTime.Now).

Added a new using directive for `System.Reflection` and introduced additional test cases for the `GetNextBox` method in the `StudySessionsServiceTests` class. The new test method `GetNextBox_ShouldReturnExpectedBox` utilizes the `[Theory]` and `[InlineData]` attributes to cover multiple input scenarios. A private static method `InvokeGetNextBox` was also added to enable reflection-based invocation of the non-public `GetNextBox` method in the `StudySessionsService` class.
Added a new test method `GetNextReviewDate_ShouldReturnExpectedDate` to the `StudySessionsServiceTests` class. This method utilizes the `[Theory]` and `[InlineData]` attributes to validate the behavior of the `InvokeGetNextReviewDate` method under various scenarios. It ensures that the next review date is calculated correctly based on the correctness of the answer. Additionally, two helper methods, `InvokeGetNextBox` and `InvokeGetNextReviewDate`, were introduced to enable the invocation of private static methods from the `StudySessionsService` class.
Added a new unit test method `StartStudySessionAsync_ShouldReturnFailure_WhenUpdateCardsProgressBulkAsyncFails` to the `StudySessionsServiceTests` class. This test verifies that when the `UpdateCardsProgressBulkAsync` method fails, the `StartStudySessionAsync` method returns a failure result. The test sets up a flashcard, mocks the user interaction service to provide an answer, and configures the cards repository to return a failure result. It then asserts that the result of the `StartStudySessionAsync` method indicates failure and matches the expected error.
Added a new unit test method `RunStudySessionAsync_ShouldReturnFailure_WhenStartStudySessionAsyncFails` to the `StudySessionsServiceTests` class. This test verifies that when the `RunStudySessionAsync` method is called with a list of flashcards and a stack ID, and the `UpdateCardsProgressBulkAsync` method fails, the result indicates a failure with the appropriate error message.
Added a new test method `GetAllStudySessionsAsync_ShouldReturnFailure_WhenHasStudySessionAsyncFails` to the `StudySessionsServiceTests` class. This test ensures that when the `_studySessionsRepository.HasStudySessionAsync` method fails, the `GetAllStudySessionsAsync` method of the `_studySessionsService` also returns a failure, validating that the error matches `StudySessionsErrors.HasStudySessionFailed`.
The `Box` and `NextReviewDate` properties in the `BaseCardDto` class have been updated. The `Box` property now defaults to `1`, and `NextReviewDate` defaults to the current date and time (`DateTime.Now`). This enhancement ensures that these properties are initialized with sensible defaults when an instance of `BaseCardDto` is created, improving the class's usability.
@Dejmenek Dejmenek linked an issue Sep 6, 2025 that may be closed by this pull request
@Dejmenek
Dejmenek merged commit 227b14e into main Sep 6, 2025
2 checks passed
@Dejmenek
Dejmenek deleted the 42-add-unit-tests-for-spaced-repetition branch September 6, 2025 14:23
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.

Add unit tests for spaced repetition

1 participant