public void GetAllBooks_ShouldReturnAllBooks() { var controller = new BooksController(GetContext()); var result = (OkNegotiatedContentResult <List <Book> >)controller.GetAllBooks(); Assert.IsNotNull(result); Assert.AreEqual(5, result.Content.Count); }
public void GetAllBooksTest() { BooksController controller = new BooksController(); var result = controller.GetAllBooks() as List <Book>; Assert.AreEqual(2, result.Count); }
public void GetTest_ReturnsListOfBooks() { // Act var result = _booksController.GetAllBooks().Result; // Assert Assert.Equal(2, result.Count()); }
public void GetAllBooks_Called_OkResultWithEnumerable() { var serviceStub = Substitute.For <IBookService>(); var booksController = new BooksController(serviceStub); var result = booksController.GetAllBooks(); Assert.IsInstanceOf <OkNegotiatedContentResult <IEnumerable <BookDto> > >(result); }
public void GetAllBooks_Called_CallsService() { var serviceMock = Substitute.For <IBookService>(); var booksController = new BooksController(serviceMock); booksController.GetAllBooks(); serviceMock.Received().GetAll(); }
public void DeleteBookTest() { BooksController controller = new BooksController(); controller.DeleteBook("9418951247361"); var result = controller.GetAllBooks() as List <Book>; Assert.AreEqual(1, result.Count); }
public async Task GetAllBooks_ExpectOkResult() { _booksService.Setup(bs => bs.GetAllBooks()).ReturnsAsync(new List <Book> { book1, book2 }); var result = await _booksController.GetAllBooks(); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); }
public void GetAllBooks_ServiceThrows_Throws() { var serviceStub = Substitute.For <IBookService>(); serviceStub.When(service => service.GetAll()) .Do(callback => { throw new Exception(); }); var booksController = new BooksController(serviceStub); Assert.Throws <HttpResponseException>(() => booksController.GetAllBooks()); }
public void AddBookToListTest() { BooksController controller = new BooksController(); Book book1 = new Book("Harry Potter and The Philosopher's stone", "J.K. Rowling", 373, "1232123212321"); controller.AddNewBook(book1); var resultAll = controller.GetAllBooks() as List <Book>; var resultOne = controller.GetSpecificBook("1232123212321"); Assert.AreEqual(3, resultAll.Count); Assert.AreEqual("J.K. Rowling", resultOne.Author); }
public void Run(SoftUniLibraryContext context) { IBooksController booksController = new BooksController(context); IAuthorsController authorsController = new AuthorsController(context); while (true) { Console.WriteLine("Please select an action:"); Console.WriteLine(" \"AllBooks\" - Show all books."); Console.WriteLine(" \"BookDetails\" - Show book details."); Console.WriteLine(" \"AuthorDetails\" - Show author details."); Console.WriteLine(" \"Exit\" - Exit the app."); string action = Console.ReadLine(); switch (action) { case "AllBooks": Console.WriteLine(booksController.GetAllBooks()); break; case "BookDetails": Console.WriteLine(booksController.GetBookDetails()); break; case "AuthorDetails": Console.WriteLine(authorsController.GetAuthorDetails()); break; case "Exit": ExitTheApp(); break; default: Console.WriteLine("Invalid Action!"); break; } Console.WriteLine(); Console.WriteLine("--------------------------------------------------------------------------"); Console.WriteLine(); } }
public void GetAllBooks_ActionExecutes_ReturnsBooksList() { var result = booksController.GetAllBooks(); Assert.IsType <ActionResult <List <Book> > >(result); }