public void Update_Test() { var bookService = new BookServise(_connectionString); bookService.Create(new ViewEntities.Models.BookViewModel { Name = "-Test Update Book-", Author = "Test Author", YearOfPublishing = "1997" }); var allBooks = bookService.Get().ToList(); var oldBook = allBooks.FirstOrDefault(x => x.Name == "-Test Update Book-"); oldBook.Author = "New Author"; oldBook.Name = "-Test Update Book 2-"; oldBook.YearOfPublishing = "1234"; bookService.Update(oldBook); var result = bookService.Get(oldBook.Id); Assert.IsTrue(result.Author == "New Author"); Assert.IsTrue(result.Name == "-Test Update Book 2-"); Assert.IsTrue(result.YearOfPublishing == "1234"); bookService.Remove(oldBook.Id); }
public ActionResult Delete(int id) { BookViewModel b = _bookServise.Get(id); if (b == null) { return(HttpNotFound("Delete failed")); } _bookServise.Remove(id); return(RedirectToAction("Books")); }
public void Create_Test() { var bookService = new BookServise(_connectionString); bookService.Create(new ViewEntities.Models.BookViewModel { Name = "-Test Create Book-", Author = "Test Author", YearOfPublishing = "1997" }); var allBooks = bookService.Get().ToList(); var result = allBooks.FirstOrDefault(x => x.Name == "-Test Create Book-"); Assert.IsTrue(result != null); bookService.Remove(result.Id); }