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

            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,
                Car            = car,
                Conversation   = new Conversation()
            },
                new Ride
            {
                Date           = DateTime.UtcNow.AddDays(-1),
                AvailableSeats = 1,
                Car            = car,
                Conversation   = new Conversation()
            }
                );

            await context.SaveChangesAsync();

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

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

            // Assert
            Assert.Equal(expectedCount, actualCount);
        }
Esempio n. 2
0
        public async Task GetAllAsync_WithNoRides_ReturnsEmptyCollection()
        {
            // Arrange
            const int expectedCount = 0;

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

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

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

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