Repository navigation
test: add unit tests for spaced repetition - #49
Merged
Merged
Conversation
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.
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.
Summary
This pull request adds unit tests for various methods in the
StudySessionsServiceand modifies theBaseCardDtoclass to include default property values.Changes
StudySessionsServiceTests.cs: Added unit tests forGetNextBox,GetNextReviewDate,StartStudySessionAsync,RunStudySessionAsync, andGetAllStudySessionsAsync.StudySessionsServiceTests.cs: Introduced reflection methodsInvokeGetNextBoxandInvokeGetNextReviewDatefor testing private methods.Flashcard.cs: UpdatedBaseCardDtoto set default values forBox(defaulting to1) andNextReviewDate(defaulting toDateTime.Now).