Esempio n. 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));
        }
Esempio n. 2
0
        public async Task Can_Paginate()
        {
            BookManageController ctrl   = new BookManageController(bookRepo);
            PagingInfo           result = (PagingInfo)(await ctrl.Index(2)).Model;

            Book[] books = result.Books.ToArray();

            Assert.IsTrue(result.TotalPages == 2);
            Assert.IsTrue(result.CurPage == 2, "2");
            Assert.IsTrue(books.Length == 2, "3");
            Assert.AreEqual("Avengers", books[0].Name);
            Assert.AreEqual("1000 Places to See", books[1].Name);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
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));
        }
Esempio n. 5
0
        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));
        }