public void GetFavoritesForUserShouldReturnCorrectNumberOfRestaurantsWhenUsernameFound(string username, int expected, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; AppUserRepo uRepo; List <Restaurant> results; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { results = uRepo.GetFavoritesForUserAsync(username).Result.ToList(); } else { results = uRepo.GetFavoritesForUser(username).ToList(); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.Equal(expected, results.Count); }
public void GetFavoritesForUserShouldThrowExceptionIfIsUsernameNotFound(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; bool result = false; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); try { if (useAsync) { uRepo.GetFavoritesForUserAsync(username).Wait(); } else { uRepo.GetFavoritesForUser(username); } } catch (NotSupportedException) { result = true; } catch (AggregateException) { result = true; } } //If exception is throw, test will exit before reaching Assert //Assert Assert.True(result); }