コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }