ExpenseRepositoryTests.cs
966 bytes
| 1 | using App.DAL.EF.Repositories; |
|---|---|
| 2 | using App.Domain; |
| 3 | using FluentAssertions; |
| 4 | |
| 5 | namespace App.Tests.DAL; |
| 6 | |
| 7 | public class ExpenseRepositoryTests : RepositoryTestBase |
| 8 | { |
| 9 | [Fact] |
| 10 | public async Task GetByTripIdAsync_ReturnsExpensesForThatTripOnly() |
| 11 | { |
| 12 | // Arrange |
| 13 | var (currency, user, trip) = await SeedTripAsync(); |
| 14 | var expense = new Expense |
| 15 | { |
| 16 | TripId = trip.Id, |
| 17 | PaidByUserId = user.Id, |
| 18 | CurrencyId = currency.Id, |
| 19 | Amount = 42.50m, |
| 20 | Description = "Dinner", |
| 21 | ExpenseDate = DateTime.UtcNow, |
| 22 | SplitMethod = ESplitMethod.EqualAll |
| 23 | }; |
| 24 | Context.Expenses.Add(expense); |
| 25 | await Context.SaveChangesAsync(); |
| 26 | |
| 27 | var repo = new ExpenseRepository(Context); |
| 28 | |
| 29 | // Act |
| 30 | var result = await repo.GetByTripIdAsync(trip.Id); |
| 31 | |
| 32 | // Assert |
| 33 | result.Should().ContainSingle() |
| 34 | .Which.Amount.Should().Be(42.50m); |
| 35 | } |
| 36 | } |
| 37 | |