public void Book_Book_ById_Return_OkObjectResult() { int bookId = 25; var response = bookController.DeleteBook(bookId); Assert.IsType <OkObjectResult>(response); }
public void Book_DeleteBook_Should_Return_Bad_Request() { var id = 0; var response = _bookController.DeleteBook(id); Assert.IsInstanceOf <BadRequestResult>(response); }
public void DeleteBook_BookWithValidId_ReturnStatusWithTrue() { _bookController.CreateBook(_beautyAndTheBeast); _bookController.CreateBook(_gameOfThrones); _bookController.CreateBook(_swordOfTruth); var response = _bookController.DeleteBook(_swordOfTruth.Id); var responseData = (ResponseData)response.Data; Assert.That(responseData.Status, Is.True); Assert.That(responseData.Message, Does.Contain("Successfully deleted")); }
public async Task DeleteBookSuccess() { //Arrange var book = new Book { Id = 1, Title = "Testowy Title" }; var fileServiceMock = new Mock <IBookService>(); fileServiceMock.Setup(m => m.DeleteBookAsync(It.IsAny <string>(), It.IsAny <int>())) .Returns(Task.FromResult(book)); var storageMock = new Mock <IStorageService>(); var fileController = new BookController(_mapper, fileServiceMock.Object, _logger, storageMock.Object); //Act IActionResult actionResult = await fileController.DeleteBook("ID1", 1); //Assert actionResult.ShouldNotBeNull(); OkObjectResult result = actionResult as OkObjectResult; result.ShouldNotBeNull(); result.StatusCode.ShouldEqual(200); BookDeleteDto resultValue = result.Value as BookDeleteDto; ; resultValue.ShouldNotBeNull(); resultValue.Id.ShouldEqual(1); }
public void Books_DeleteItem() { var test = GetTestBooks(); var controller = new BookController(test); var result = controller.DeleteBook(3) as List <Book>; Assert.IsNotNull(result); Assert.AreEqual(result.Id, 3); }
public async Task DeleteBookCheckReturnOk_Test() { _bookService.Setup(service => service.DeleteBookAsync(BookId)).Returns(async() => { await Task.CompletedTask; }); var actionResult = await _bookController.DeleteBook(BookId); var contentResult = actionResult as IStatusCodeActionResult; Assert.AreEqual(StatusCodes.Status200OK, contentResult.StatusCode); }
public void DeleteBook_NonExistingBook_ReturnsNotFound() { mockService.Setup(s => s.DeleteBook(It.IsAny <int>())) .Returns(BookTestData.DeleteBookServiceResponseNullData()); BookController bookController = new BookController(mockService.Object); var result = bookController.DeleteBook(1); Assert.That(result, Is.InstanceOf <NotFoundObjectResult>()); }
public void DeleteBook_NonExistingBook_ReturnsNotFound() { dbContext.Database.EnsureDeleted(); dbContext.Database.EnsureCreated(); BookService bookService = new BookService(mapper, dbContext); BookController bookController = new BookController(bookService); var result = bookController.DeleteBook(1); Assert.That(result, Is.InstanceOf <NotFoundObjectResult>()); }
public void DeleteBook_InvalidModeStade_BadRequest() { //Arrange var bookId = 0; var controller = new BookController(_bookServiceMock.Object); //Act var action = controller.DeleteBook(bookId); //Assert Assert.IsTrue(action is BadRequestErrorMessageResult); }
public void TestDeleteBooksByController() { //Arrange BookController controller = new BookController(); String bookId = "1"; //Act JsonResult result = controller.DeleteBook(bookId); //Assert Assert.AreEqual("False", result.Data.ToString()); }
public void Can_Delete_Valid_Book() { //Arrange //создаем cookie var cookies = new HttpCookieCollection(); //Создаем HttpContext и присваиваем cookies для Request и Response var mockHttpContext = Substitute.For <HttpContextBase>(); mockHttpContext.Request.Cookies.Returns(cookies); mockHttpContext.Response.Cookies.Returns(cookies); // создаем Mock-контейнер Mock <IBookContainer> mock = new Mock <IBookContainer>(); mock.Setup(m => m.Books).Returns(new List <Book> { new Book { BookId = 1, Title = "T1", PublishYear = 1959 }, new Book { BookId = 2, Title = "T2", PublishYear = 1971 }, new Book { BookId = 3, Title = "T3", PublishYear = 1985 }, new Book { BookId = 4, Title = "T4", PublishYear = 1976 }, new Book { BookId = 5, Title = "T5", PublishYear = 1951 } }.AsQueryable()); //Создаем экземпляр контроллера и присваиваем HttpContext BookController controller = new BookController(mock.Object); controller.ControllerContext = new ControllerContext { Controller = controller, HttpContext = mockHttpContext }; //Act - Берем из mock книгу с bookId = 1 Book book = mock.Object.Books.FirstOrDefault(b => b.BookId == 1); //Act - Удаляем книгу controller.DeleteBook(book.BookId); //Проверяем, что для book 1 раз вызывался метод DeleteBook mock.Verify(books => books.DeleteBook(book.BookId), Times.Once()); }
public void DeleteBook_ShouldReturnOK() { var context = new TestBookstoreAppContext(); var item = GetDemoBook(); context.Books.Add(item); var controller = new BookController(context); var result = controller.DeleteBook(3) as OkNegotiatedContentResult <Book>; Assert.IsNotNull(result); Assert.AreEqual(item.Id, result.Content.Id); }
public async Task DeleteBook_WhenValidIdIsPassed_ReturnsOkResult() { //Arrange var moq = new Mock <IBookService>(); moq.Setup(r => r.RemoveBook(1)); //Act var controller = new BookController(moq.Object); var result = await controller.DeleteBook(1); //Assert Assert.IsType <OkResult>(result); }
public void DeleteBook_ExistingBook_ReturnsOk() { dbContext.Database.EnsureDeleted(); dbContext.Database.EnsureCreated(); AddBookDto newBook = GetAddBookDto(); BookService bookService = new BookService(mapper, dbContext); BookController bookController = new BookController(bookService); bookController.AddBook(newBook); var result = bookController.DeleteBook(1); Assert.That(result, Is.InstanceOf <OkObjectResult>()); }
public void DeleteBook_ExistingBook_ReturnsOk() { mockService.Setup(s => s.AddBook(It.IsAny <AddBookDto>())) .Returns(BookTestData.AddBookServiceResponse()); mockService.Setup(s => s.DeleteBook(It.IsAny <int>())) .Returns(BookTestData.DeleteBookServiceResponse()); BookController bookController = new BookController(mockService.Object); AddBookDto newBook = BookTestData.AddBookDto(); bookController.AddBook(newBook); var result = bookController.DeleteBook(1); Assert.That(result, Is.InstanceOf <OkObjectResult>()); }
public void InValid_DeleteBook() { Mock <IDatabase> mock = new Mock <IDatabase>(); mock.Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(1); BookController bookcontroller = new BookController(mock.Object); Book book = new Book(); book.SetBookID(-1); book.SetName("Times"); book.SetAuthor("David Stanley"); book.SetStatus("Available"); book.SetPrice(25); book.SetRackno(12); book.SetCount(0); var result = bookcontroller.DeleteBook("12") as RedirectToRouteResult; Assert.IsNotNull(result); }