public BooksControllerTest() { // Lets create some sample books book1 = new Book { ID = 1, Book1 = "test1", AuthorName = "test1", ISBN = "NA" }; book2 = new Book { ID = 2, Book1 = "test2", AuthorName = "test2", ISBN = "NA" }; book3 = new Book { ID = 3, Book1 = "test3", AuthorName = "test3", ISBN = "NA" }; book4 = new Book { ID = 4, Book1 = "test4", AuthorName = "test4", ISBN = "NA" }; book5 = new Book { ID = 5, Book1 = "test5", AuthorName = "test5", ISBN = "NA" }; books = new List<Book> { book1, book2, book3, book4 }; // Lets create our dummy repository booksRepo = new DummyBooksRepository(books); // Let us now create the Unit of work with our dummy repository uow = new UnitOfWork(booksRepo); // Now lets create the BooksController object to test and pass our unit of work controller = new HomeController(uow); }
public void UpdateBook(Book book) { int id = book.ID; Book bookToUpdate = m_books.SingleOrDefault(b => b.ID == id); DeleteBook(bookToUpdate); m_books.Add(book); }
public ActionResult Create(Book book) { if (ModelState.IsValid) { unitOfWork.BookRepository.AddBook(book); unitOfWork.BookRepository.Save(); return RedirectToAction("Index"); } return View(); }
public void Create() { // Lets create a valid book objct to add into Book newBook = new Book { ID = 7, Book1 = "new", AuthorName = "new", ISBN = "NA" }; // Lets call the action method now controller.Create(newBook); // get the list of books List<Book> books = booksRepo.GetAllBooks(); CollectionAssert.Contains(books, newBook); }
public void UpdateBook(Book book) { db.Entry(book).State = System.Data.Entity.EntityState.Modified; }
public void DeleteBook(Book book) { db.Books.Remove(book); }
public void AddBook(Book book) { db.Books.Add(book); }
public void AddBook(Book book) { m_books.Add(book); }