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 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); }
public ActionResult AddBook(BookViewModel book) { List <PublicHouseViewModel> publicHouses = new List <PublicHouseViewModel>(); if (book == null) { return(HttpNotFound()); } //if (selectedPablicHouses != null) //{ // publicHouses.AddRange(_bookServise.GetPublicHouses().Where(x => selectedPablicHouses.Contains(x.Id)).ToList()); // book.PublicHouses.AddRange(publicHouses); //} _bookServise.Create(book); return(Json(book)); }