public void GetQueriesForUserShouldReturnCorrectNumberOfRestaurantsWhenUsernameFound(string username, int expected, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; AppUserRepo uRepo; List <Query> results; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { results = uRepo.GetQueriesForUserAsync(username).Result.ToList(); } else { results = uRepo.GetQueriesForUser(username).ToList(); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.Equal(expected, results.Count); }
public void GetQueriesForUserShouldThrowExceptionIfIsUsernameNotFound(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.GetQueriesForUserAsync(username).Wait(); } else { uRepo.GetQueriesForUser(username); } } catch (NotSupportedException) { result = true; } catch (AggregateException) { result = true; } } //If exception is throw, test will exit before reaching Assert //Assert Assert.True(result); }