public void DBContainsUsernameShouldReturnFalseIfIfDBIsEmpty(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyDB3") .Options; bool result; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { result = uRepo.DBContainsUsernameAsync(username).Result; } else { result = uRepo.DBContainsUsername(username); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.False(result); }
public void DBContainsUsernameShouldReturnFalseIfUsernameNotInDB(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; bool result; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { result = uRepo.DBContainsUsernameAsync(username).Result; } else { result = uRepo.DBContainsUsername(username); } } //Assert Assert.False(result); }
public void DBContainsUsernameShouldNotThrowExceptionIfDBIsEmpty(bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyDB2") .Options; bool result = true; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { uRepo.DBContainsUsernameAsync("LiterallyAnything").Wait(); } else { uRepo.DBContainsUsername("LiterallyAnything"); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.True(result); }