TripRepositoryTests.cs
1,221 bytes
| 1 | using App.DAL.EF.Repositories; |
|---|---|
| 2 | using FluentAssertions; |
| 3 | |
| 4 | namespace App.Tests.DAL; |
| 5 | |
| 6 | public class TripRepositoryTests : RepositoryTestBase |
| 7 | { |
| 8 | [Fact] |
| 9 | public async Task GetByIdAsync_WhenTripExists_ReturnsTripWithCurrencyAndCreator() |
| 10 | { |
| 11 | // Arrange |
| 12 | var (_, user, trip) = await SeedTripAsync(); |
| 13 | var repo = new TripRepository(Context); |
| 14 | |
| 15 | // Act |
| 16 | var result = await repo.GetByIdAsync(trip.Id); |
| 17 | |
| 18 | // Assert |
| 19 | result.Should().NotBeNull(); |
| 20 | result!.Name.Should().Be("Paris"); |
| 21 | result.DefaultCurrency.Should().NotBeNull(); |
| 22 | result.DefaultCurrency!.Code.Should().Be("EUR"); |
| 23 | result.CreatedBy.Should().NotBeNull(); |
| 24 | result.CreatedBy!.Id.Should().Be(user.Id); |
| 25 | } |
| 26 | |
| 27 | [Fact] |
| 28 | public async Task GetUserTripsAsync_WhenUserIsActiveParticipant_ReturnsTrip() |
| 29 | { |
| 30 | // Arrange — SeedTripAsync adds the user as an active organizer participant |
| 31 | var (_, user, trip) = await SeedTripAsync(); |
| 32 | var repo = new TripRepository(Context); |
| 33 | |
| 34 | // Act |
| 35 | var result = await repo.GetUserTripsAsync(user.Id); |
| 36 | |
| 37 | // Assert |
| 38 | result.Should().ContainSingle() |
| 39 | .Which.Id.Should().Be(trip.Id); |
| 40 | } |
| 41 | } |
| 42 | |