TripParticipantRepositoryTests.cs
1,824 bytes
| 1 | using App.DAL.EF.Repositories; |
|---|---|
| 2 | using App.Domain; |
| 3 | using FluentAssertions; |
| 4 | |
| 5 | namespace App.Tests.DAL; |
| 6 | |
| 7 | public class TripParticipantRepositoryTests : RepositoryTestBase |
| 8 | { |
| 9 | [Fact] |
| 10 | public async Task IsParticipantAsync_WhenUserIsActiveParticipant_ReturnsTrue() |
| 11 | { |
| 12 | // Arrange — SeedTripAsync creates an active organizer participant |
| 13 | var (_, user, trip) = await SeedTripAsync(); |
| 14 | var repo = new TripParticipantRepository(Context); |
| 15 | |
| 16 | // Act |
| 17 | var result = await repo.IsParticipantAsync(trip.Id, user.Id); |
| 18 | |
| 19 | // Assert |
| 20 | result.Should().BeTrue(); |
| 21 | } |
| 22 | |
| 23 | [Fact] |
| 24 | public async Task IsParticipantAsync_WhenUserHasLeft_ReturnsFalse() |
| 25 | { |
| 26 | // Arrange — flip the seeded participant to inactive (i.e. left the trip) |
| 27 | var (_, user, trip) = await SeedTripAsync(); |
| 28 | var participant = Context.TripParticipants.First(); |
| 29 | participant.IsActive = false; |
| 30 | await Context.SaveChangesAsync(); |
| 31 | var repo = new TripParticipantRepository(Context); |
| 32 | |
| 33 | // Act |
| 34 | var result = await repo.IsParticipantAsync(trip.Id, user.Id); |
| 35 | |
| 36 | // Assert — IsActive=false should exclude them from "is participant" |
| 37 | result.Should().BeFalse(); |
| 38 | } |
| 39 | |
| 40 | [Fact] |
| 41 | public async Task IsOrganizerAsync_WhenUserIsRegularParticipant_ReturnsFalse() |
| 42 | { |
| 43 | // Arrange — demote the seeded organizer to plain participant |
| 44 | var (_, user, trip) = await SeedTripAsync(); |
| 45 | var participant = Context.TripParticipants.First(); |
| 46 | participant.Role = EParticipantRole.Participant; |
| 47 | await Context.SaveChangesAsync(); |
| 48 | var repo = new TripParticipantRepository(Context); |
| 49 | |
| 50 | // Act |
| 51 | var result = await repo.IsOrganizerAsync(trip.Id, user.Id); |
| 52 | |
| 53 | // Assert |
| 54 | result.Should().BeFalse(); |
| 55 | } |
| 56 | } |
| 57 | |