public void Can_Filter_Books() { // Arrange Mock <IBookRepository> mock = new Mock <IBookRepository>(); mock.Setup(b => b.Books).Returns(new Book[] { new Book { ISBN = "1", Title = "Book1", Category = "CS" }, new Book { ISBN = "2", Title = "Book2", Category = "KS" }, new Book { ISBN = "3", Title = "Book3", Category = "IS" }, new Book { ISBN = "4", Title = "Book4", Category = "MS" }, new Book { ISBN = "5", Title = "Book5", Category = "NM" } }); Bookcontroller controller = new Bookcontroller(mock.Object); // Method we want to test inside this class controller.pageSize = 3; //Act Book[] result = ((BookListViewModel)controller .BookView("IS", 1).Model).Books.ToArray(); //Assert Assert.AreEqual(result.Length, 1); Assert.IsTrue(result[0].Title == "Book3" && result[0].Category == "IS"); }
public void Can_Send_Pagination_View_Model() { // Arrange Mock <IBookRepository> mock = new Mock <IBookRepository>(); mock.Setup(b => b.Books).Returns( new Book[] { new Book { ISBN = "12", Title = "SQL" }, new Book { ISBN = "13", Title = "SQL" }, new Book { ISBN = "14", Title = "SQL" }, new Book { ISBN = "15", Title = "SQL" }, new Book { ISBN = "16", Title = "SQL" } }); Bookcontroller controller = new Bookcontroller(mock.Object); controller.pageSize = 3; // Act BookListViewModel result = (BookListViewModel)controller.BookView(null, 2).Model; // Assert PagingInfo pageinfo = result.PagingInfo; Assert.AreEqual(pageinfo.CurrentPage, 2); Assert.AreEqual(pageinfo.ItemsPerPage, 3); Assert.AreEqual(pageinfo.TotalItems, 5); Assert.AreEqual(pageinfo.TotalPage, 2); }
public void Can_Paginate() { // test to verify that app has two pages and there are just three products in each page // Arrange Mock <IBookRepository> mock = new Mock <IBookRepository>(); mock.Setup(b => b.Books).Returns(new Book[] { new Book { ISBN = "1", Title = "Book1" }, new Book { ISBN = "2", Title = "Book2" }, new Book { ISBN = "3", Title = "Book3" }, new Book { ISBN = "4", Title = "Book4" }, new Book { ISBN = "5", Title = "Book5" } }); Bookcontroller controller = new Bookcontroller(mock.Object); // Method we want to test inside this class controller.pageSize = 3; //Act BookListViewModel result = (BookListViewModel)controller.BookView(null, 1).Model; //Assert Book[] bookArray = result.Books.ToArray(); Assert.IsTrue(bookArray.Length == 3); Assert.AreEqual(bookArray[0].Title, "Book1"); Assert.AreEqual(bookArray[1].Title, "Book2"); Assert.AreEqual(bookArray[2].Title, "Book3"); }