public async Task GetAllUpcomingForUserAsync_WithNonExistentUser_ReturnsNull() { // Arrange const string testUser = "******"; var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options); var ridesService = new RidesService(new EfRepository <Ride>(context), new EfRepository <PoolItUser>(context), null, null); // Act var result = await ridesService.GetAllUpcomingForUserAsync(testUser); // Assert Assert.Null(result); }
public async Task GetAllUpcomingForUserAsync_WithRides_WorksCorrectly() { // Arrange var expectedResult = new[] { "Ride1", "Ride2" }; const string testUser = "******"; var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options); var user = new PoolItUser { UserName = testUser }; await context.Users.AddAsync(user); 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 { Title = "Ride1", Date = DateTime.UtcNow.AddDays(1), Participants = new[] { new UserRide { User = user } }, Car = car, Conversation = new Conversation() }, new Ride { Title = "Ride2", Date = DateTime.UtcNow.AddDays(2), Participants = new[] { new UserRide { User = user } }, Car = car, Conversation = new Conversation() }, new Ride { Title = "OtherRide1", Date = DateTime.UtcNow.AddDays(-1), Participants = new[] { new UserRide { User = user } }, Car = car, Conversation = new Conversation() }, new Ride { Title = "OtherRide2", Date = DateTime.UtcNow.AddDays(1), Participants = new[] { new UserRide { User = new PoolItUser { UserName = "******" } } }, Car = car, Conversation = new Conversation() } ); await context.SaveChangesAsync(); var ridesService = new RidesService(new EfRepository <Ride>(context), new EfRepository <PoolItUser>(context), null, null); // Act var actualResult = (await ridesService.GetAllUpcomingForUserAsync(testUser)).Select(r => r.Title); // Assert Assert.Equal(expectedResult, actualResult); }