diff --git a/RestaurantReservation.Test/GenericControllerFunctionalTests.cs b/RestaurantReservation.Test/GenericControllerFunctionalTests.cs new file mode 100644 index 0000000..631e8e0 --- /dev/null +++ b/RestaurantReservation.Test/GenericControllerFunctionalTests.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +using RestaurantReservation.Presentation.Interfaces; +using RestaurantReservation.Test.Data; +using RestaurantReservation.Test.Fixtures; +using FluentAssertions; + +namespace RestaurantReservation.Test; + +public class ProgramFunctionalTests : IClassFixture +{ + private readonly IGenericController _genericController; + + public ProgramFunctionalTests(FullTestSetupFixture fullTestSetupFixture) + { + _genericController = fullTestSetupFixture.ServiceProvider.GetRequiredService(); + } + + [Fact] + public async Task ListManagers_ShouldReturnCorrectData() + { + var managers = await _genericController.ListManagers().ToListAsync(); + managers.Count.Should().Be(1); + managers[0].Should().BeEquivalentTo(ModelsData.Employees().ToList()[0]); + } + + [Fact] + public async Task GetReservationsByCustomer_ShouldReturnCorrectData() + { + var reservations = await _genericController.GetReservationsByCustomer(1).ToListAsync(); + reservations.Count.Should().Be(1); + reservations[0].Should().BeEquivalentTo(ModelsData.Reservations().ToList()[0]); + } + + [Fact] + public async Task ListOrdersAndMenuItems_ShouldReturnCorrectData() + { + var pairs = await _genericController.ListOrdersAndMenuItems(1).ToListAsync(); + pairs.Count.Should().Be(1); + + var (order, menuItems) = pairs[0]; + order.Should().BeEquivalentTo(ModelsData.Orders().ToList()[0]); + + var menuItemList = await menuItems.ToListAsync(); + menuItemList.Count.Should().Be(1); + menuItemList[0].Should().BeEquivalentTo(ModelsData.MenuItems().ToList()[0]); + } + + [Fact] + public async Task ListOrderedMenuItems_ShouldReturnCorrectData() + { + var menuItems = await _genericController.ListOrderedMenuItems(1).ToListAsync(); + menuItems.Count.Should().Be(1); + menuItems[0].Should().BeEquivalentTo(ModelsData.MenuItems().ToList()[0]); + } + + [Fact] + public async Task CalculateAverageOrderAmount_ShouldReturnCorrectData() + { + var average = await _genericController.CalculateAverageOrderAmount(1); + average.Should().BeApproximately(45.9, 1e-6); + } +} \ No newline at end of file diff --git a/RestaurantReservation.Test/RestaurantReservation.Test.csproj b/RestaurantReservation.Test/RestaurantReservation.Test.csproj index cc1e79c..d3a6752 100644 --- a/RestaurantReservation.Test/RestaurantReservation.Test.csproj +++ b/RestaurantReservation.Test/RestaurantReservation.Test.csproj @@ -18,6 +18,7 @@ + diff --git a/RestaurantReservation/Presentation/Controllers/GenericController.cs b/RestaurantReservation/Presentation/Controllers/GenericController.cs index 6583e50..1079c6c 100644 --- a/RestaurantReservation/Presentation/Controllers/GenericController.cs +++ b/RestaurantReservation/Presentation/Controllers/GenericController.cs @@ -47,12 +47,13 @@ public async IAsyncEnumerable GetReservationsByCustomer(int custome await foreach (var order in orders.AsAsyncEnumerable()) { - var menuItems = context.OrderItems + var menuItems = await context.OrderItems .Where(oi => oi.OrderId == order.OrderId) .Select(od => od.MenuItem) - .AsAsyncEnumerable(); + .Distinct() + .ToListAsync(); - yield return (order, menuItems); + yield return (order, menuItems.ToAsyncEnumerable()); } }