コード例 #1
0
        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);
        }
コード例 #2
0
 public void UpdateBook(Book book)
 {
     int id = book.ID;
     Book bookToUpdate = m_books.SingleOrDefault(b => b.ID == id);
     DeleteBook(bookToUpdate);
     m_books.Add(book);
 }
コード例 #3
0
        public ActionResult Create(Book book)
        {
            if (ModelState.IsValid)
            {
                unitOfWork.BookRepository.AddBook(book);
                unitOfWork.BookRepository.Save();
                return RedirectToAction("Index");
            }

            return View();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public void UpdateBook(Book book)
 {
     db.Entry(book).State = System.Data.Entity.EntityState.Modified;
 }
コード例 #6
0
 public void DeleteBook(Book book)
 {
     db.Books.Remove(book);
 }
コード例 #7
0
 public void AddBook(Book book)
 {
     db.Books.Add(book);
 }
コード例 #8
0
 public void AddBook(Book book)
 {
     m_books.Add(book);
 }