public void GetUserByUsernameShouldNotThrowExceptionIfUsernameIsInDB(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; bool result = true; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { uRepo.GetUserByUsernameAsync(username).Wait(); } else { uRepo.GetUserByUsername(username); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.True(result); }
public void GetUserByUsernameShouldReturnUserWithMatchingUsername(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; AppUser u; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { u = uRepo.GetUserByUsernameAsync(username).Result; } else { u = uRepo.GetUserByUsername(username); } } //Assert Assert.Equal(username, u.Username); }
public void GetUserByUsernameShouldThrowExceptionIfUsernameNotFound(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.GetUserByUsernameAsync(username).Wait(); } else { uRepo.GetUserByUsername(username); } } catch (NotSupportedException) { result = true; } catch (AggregateException) { result = true; } } //Assert Assert.True(result); }