public void GetQueryByIDShouldNotThrowExceptionIfIdIsInDB(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.GetQueryByIDAsync(Id).Wait(); } else { qRepo.GetQueryByID(Id); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.True(result); }
public void GetQueryByIDShouldReturnQueryWithMatchingId(int Id, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledQueryDB") .Options; Query q; QueryRepo qRepo; //Act using (var context = new Project2DBContext(options)) { qRepo = new QueryRepo(context); if (useAsync) { q = qRepo.GetQueryByIDAsync(Id).Result; } else { q = qRepo.GetQueryByID(Id); } } //Assert Assert.Equal(Id, q.Id); }
public void GetQueryByIDShouldThrowExceptionIfIdNotFound(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.GetQueryByIDAsync(Id).Wait(); } else { qRepo.GetQueryByID(Id); } } catch (NotSupportedException) { result = true; } catch (AggregateException) { result = true; } } //Assert Assert.True(result); }