Esempio n. 1
0
        public async Task GetAllUpcomingWithFreeSeatsAsync_WithRides_WorksCorrectly()
        {
            // Arrange
            const int expectedCount = 1;

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var car = new Car
            {
                Model = new CarModel
                {
                    Model        = "Test Model",
                    Manufacturer = new CarManufacturer()
                },
                Owner = new PoolItUser
                {
                    UserName = "******"
                }
            };

            await context.Cars.AddAsync(car);

            await context.Rides.AddRangeAsync(
                new Ride
            {
                Date           = DateTime.UtcNow.AddDays(1),
                AvailableSeats = 1,
                Participants   = new[]
                {
                    new UserRide
                    {
                        User = new PoolItUser
                        {
                            UserName = "******"
                        }
                    }
                },
                Car          = car,
                Conversation = new Conversation()
            },
                new Ride
            {
                Date           = DateTime.UtcNow.AddDays(-1),
                AvailableSeats = 1,
                Participants   = new[]
                {
                    new UserRide
                    {
                        User = new PoolItUser
                        {
                            UserName = "******"
                        }
                    }
                },
                Car          = car,
                Conversation = new Conversation()
            },
                new Ride
            {
                Date           = DateTime.UtcNow.AddDays(1),
                AvailableSeats = 1,
                Participants   = new[]
                {
                    new UserRide
                    {
                        User = new PoolItUser
                        {
                            UserName = "******"
                        }
                    },
                    new UserRide
                    {
                        User = new PoolItUser
                        {
                            UserName = "******"
                        }
                    }
                },
                Car          = car,
                Conversation = new Conversation()
            }
                );

            await context.SaveChangesAsync();

            var ridesService = new RidesService(new EfRepository <Ride>(context), null, null, null);

            // Act
            var actualCount = (await ridesService.GetAllUpcomingWithFreeSeatsAsync()).Count();

            // Assert
            Assert.Equal(expectedCount, actualCount);
        }