public void GetRestaurantsInQueryShouldNotThrowExceptionIfIdIsInDB(int Id, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledQueryDB") .Options; bool result = true; QueryRepo qRepo; //Act using (var context = new Project2DBContext(options)) { qRepo = new QueryRepo(context); if (useAsync) { qRepo.GetRestaurantsInQueryAsync(Id).Wait(); } else { qRepo.GetRestaurantsInQuery(Id); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.True(result); }
public void GetRestaurantsInQueryShouldThrowExceptionIfIdNotFound(int Id, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledQueryDB") .Options; bool result = false; QueryRepo qRepo; //Act using (var context = new Project2DBContext(options)) { qRepo = new QueryRepo(context); try { if (useAsync) { qRepo.GetRestaurantsInQueryAsync(Id).Wait(); } else { qRepo.GetRestaurantsInQuery(Id); } } catch (NotSupportedException) { result = true; } catch (AggregateException) { result = true; } } //Assert Assert.True(result); }