public async Task Cannot_Add_book_With_No_Pic() { BookManageController ctrl = new BookManageController(bookRepo); Book book = new Book { Name = "C# programming" }; ActionResult result = await ctrl.Create(book, null); mockSet.Verify(x => x.Add(It.IsAny <Book>()), Times.Never); mockContext.Verify(x => x.SaveChangesAsync(), Times.Never); Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public async Task Cannot_Add_Book_With_Invalid_Data() { BookManageController ctrl = new BookManageController(bookRepo); Book book = new Book { Name = "C# programming" }; ctrl.ModelState.AddModelError("error", "error message"); Mock <HttpPostedFileBase> mockFile = new Mock <HttpPostedFileBase>(); ActionResult result = await ctrl.Create(book, mockFile.Object); mockSet.Verify(x => x.Add(It.IsAny <Book>()), Times.Never); mockContext.Verify(x => x.SaveChangesAsync(), Times.Never); Assert.IsInstanceOfType(result, typeof(ViewResult)); }