public async void AddAnswerAsyncShouldAdd() { // arrange var options = new DbContextOptionsBuilder <PH_DbContext>() .UseInMemoryDatabase("AddAnswerAsyncShouldAdd") .Options; using var actContext = new PH_DbContext(options); var repo = new ForumRepo(actContext); User newUser = new User() { FirstName = "Rando", LastName = "Random", Email = "*****@*****.**", Phone = "1231231234", //PointAvailable = 100 }; Answer newAnswer = new Answer() { Author = newUser }; // act await repo.AddAnswerAsync(newAnswer); //actContext.SaveChanges(); // assert using var assertContext = new PH_DbContext(options); var member = assertContext.Answers.Select(m => newAnswer); Assert.NotNull(member); }
public async void AddAnswerAsyncShouldThrowExcpetion() { // arrange var options = new DbContextOptionsBuilder <PH_DbContext>() .UseInMemoryDatabase("AddAnswerAsyncShouldThrowExcpetion") .Options; using var actContext = new PH_DbContext(options); var repo = new ForumRepo(actContext); var newAnswer = new Answer(); try { await repo.AddAnswerAsync(newAnswer); } catch (InvalidOperationException ex) { Assert.Equal("There is no user logged in.", ex.Message); } }