public void GetRestaurantByIDShouldNotThrowExceptionIfIdIsInDB(string Id, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledRestaurantDB") .Options; bool result = true; RestaurantRepo rRepo; //Act using (var context = new Project2DBContext(options)) { rRepo = new RestaurantRepo(context); if (useAsync) { rRepo.GetRestaurantByIDAsync(Id).Wait(); } else { rRepo.GetRestaurantByID(Id); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.True(result); }
public void GetRestaurantByIDShouldReturnRestaurantWithMatchingId(string Id, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledRestaurantDB") .Options; Restaurant r; RestaurantRepo rRepo; //Act using (var context = new Project2DBContext(options)) { rRepo = new RestaurantRepo(context); if (useAsync) { r = rRepo.GetRestaurantByIDAsync(Id).Result; } else { r = rRepo.GetRestaurantByID(Id); } } //Assert Assert.Equal(Id, r.Id); }
public void GetRestaurantByIDShouldThrowExceptionIfIdNotFound(string Id, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledRestaurantDB") .Options; bool result = false; RestaurantRepo rRepo; //Act using (var context = new Project2DBContext(options)) { rRepo = new RestaurantRepo(context); try { if (useAsync) { rRepo.GetRestaurantByIDAsync(Id).Wait(); } else { rRepo.GetRestaurantByID(Id); } } catch (NotSupportedException) { result = true; } catch (AggregateException) { result = true; } } //Assert Assert.True(result); }