private DeleteBookResponse DeleteBookResponseMock(BookModel book)
        {
            DeleteBookResponse response = new DeleteBookResponse();
            response.Book = new BookVO() { Id = book.Id, Title = book.Title };

            return response;
        }
Beispiel #2
0
 public void AddItem(BookModel book, int quantity)
 {
     CartLine line = lineCollection.Where(b => b.Book.Id == book.Id).FirstOrDefault();
     if (line == null)
     {
         lineCollection.Add(new CartLine { Book = book, Quantity = quantity });
     }
     else
     {
         line.Quantity += quantity;
     }
 }
        public void Edit_CanSaveValidChanges()
        {
            // Arrange - create a book
            BookModel book = new BookModel { Id = 1, Title = "Book1" };

            // Act - try to save the book
            ActionResult result = _sut.Edit(book);

            // Assert - check that the service was called
            _onlineBookStoreServiceMock.Verify(m => m.SaveBook(It.Is<SaveBookRequest>(
                request => request.Book.Id == book.Id)));
            // Assert - check the method result type
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
        public void Delete_CanDeleteValidBooks()
        {
            // Arrange - create a book
            BookModel book = new BookModel { Id = 1, Title = "Book1" };
            _onlineBookStoreServiceMock
                       .Setup(x => x.DeleteBook(It.Is<DeleteBookRequest>(request => request.BookId == book.Id)))
                       .Returns(DeleteBookResponseMock(book));

            // Act - delete the book
            _sut.Delete(book.Id);

            // Assert - ensure that the service method was called
            _onlineBookStoreServiceMock.Verify(m => m.DeleteBook(It.Is<DeleteBookRequest>(
                request => request.BookId == book.Id)));
        }
Beispiel #5
0
 public void RemoveItem(BookModel book)
 {
     lineCollection.RemoveAll(b => b.Book.Id == book.Id);
 }
        public ActionResult Edit(BookModel book)
        {
            if (ModelState.IsValid)
            {
                _onlineBookStoreService.SaveBook(new SaveBookRequest() { Book = book.MapTo<BookVO>() });

                if (book.Id > 0)
                    TempData["message"] = string.Format("{0}[{1}] has been updated.", book.Title, book.Id);
                else
                    TempData["message"] = string.Format("{0} has been added.", book.Title);

                return RedirectToAction(eAction.Index);
            }
            else
            {
                ViewData["Categories"] = LoadCategories();
                ViewData["Authors"] = LoadAuthors();
                return View(book);
            }
        }