public async Task Can_Edit_Book() { BookManageController ctrl = new BookManageController(bookRepo); Book book = new Book { Name = "C# programming" }; ActionResult result = await ctrl.Edit(book); mockContext.Verify(x => x.SetModified(It.IsAny <Book>()), Times.Once); mockContext.Verify(x => x.SaveChangesAsync(), Times.Once); Assert.IsNotInstanceOfType(result, typeof(ViewResult)); }
public async Task Cannot_Edit_Book_With_Invalid_Data() { BookManageController ctrl = new BookManageController(bookRepo); Book book = new Book { Name = "C# programming" }; ctrl.ModelState.AddModelError("error", "error message"); ActionResult result = await ctrl.Edit(book); mockContext.Verify(x => x.SetModified(It.IsAny <Book>()), Times.Never); mockContext.Verify(x => x.SaveChangesAsync(), Times.Never); Assert.IsInstanceOfType(result, typeof(ViewResult)); }