Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/JA-112 BrowseServiceTests #102

Merged
merged 19 commits into from
May 29, 2024
Merged

Conversation

Zjyslav
Copy link
Collaborator

@Zjyslav Zjyslav commented May 21, 2024

I created tests for BrowseService.
There's a lot of code here. I tried to do as much of Arrange in helper methods as I could without making it more confusing.

Please check my setup code closely, because it's something that we'll have to do for all services probably.

I struggled a bit with setting up the in memory EF Core db (method SetupInMemoryDbContext), but it works quite nicely. Notice that I use Guid.NewGuid() in the databaseName parameter. It's to give it a unique name each time the tests run (it's realy realy unlikely we'd get 2 Guids that are the same). We need it, because when the tests run in parallel, if 2 or more contexts are initialized with the same dbName they share the same db and tests are not isolated. Before I figured it out, I could not understand why my tests failed when I ran them all, but were successful when I tried to debug them.

Look also at my methods that set up repository mocks (e.g. SetupMockGetAllAds).

Test - GetBrowseAdsPage_WhenRequestIsInvalid_ShouldReturnUnsuccessfulResponse
Tests:
- GetBrowseAdsPage_WhenPageNumberIsLargerThanAvailable_ShouldReturnLastPage
- GetBrowseAdsPage_WhenRequestIsValid_ShouldReturnCorrectNumberOfAds
- GetBrowseAdsPage_WhenRequestIsValid_ShouldReturnCorrectTotalPages
- GetBrowseAdsPage_WhenRequestIsValid_ShouldReturnCorrectAds
Tests:
- GetAdDetails_WhenAdDoesntExist_ShouldReturnNull
- GetAdDetails_WhenUserIsOwner_ShouldReturnCorrectUserRelationship
- GetAdDetails_WhenUserIsAcceptedStudent_ShouldReturnCorrectUserRelationship
- GetAdDetails_WhenUserIsPendingStudent_ShouldReturnCorrectUserRelationship
- GetAdDetails_WhenUserIsHasNoRelationshipToAd_ShouldReturnCorrectUserRelationship
- GetAdDetails_WhenAdExists_ShouldReturnCorrectAdDetails

Also added 1 helper method - SetupMockGetAdById
- GetUsersSchedule_WhenUserHasNoAds_ShouldReturnEmptyTutorsSchedule
- GetUsersSchedule_WhenUserHasNoScheduleItemRequests_ShouldReturnEmptyStudentsSchedule
- GetUsersSchedule_WhenUserHasAdsWithScheduleItems_ShouldReturnCorrectTutorsSchedule
- GetUsersSchedule_WhenUserHasScheduleItemRequests_ShouldReturnCorrectStudentsSchedule
- GetUsersSchedule_WhenNoStudentIsAccepted_ShouldReturnNullAcceptedStudentsName
- GetUsersSchedule_WhenAStudentIsAccepted_ShouldReturnStudentsName
- GetUsersSchedule_WhenRequestIsAccepted_ShouldReturnCorrectStatus
- GetUsersSchedule_WhenRequestIsPending_ShouldReturnCorrectStatus

Also added and modified some helper methods.
@Zjyslav Zjyslav merged commit f9951a7 into develop May 29, 2024
1 check passed
@Zjyslav Zjyslav deleted the feature/ja-112-browse-service-tests branch May 29, 2024 23:09
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.

None yet

2 participants