public async Task ShouldDeleteBookById() { var authorList = new List <BookAuthorEntity>(); var genreList = new List <BookGenreEntity>(); authorList.Add(new BookAuthorEntity { AuthorId = (await PostAuthor()).Id }); genreList.Add(new BookGenreEntity { GenreId = (await PostGenre()).Id }); var book = CreateBook(authorList, genreList); var postResponse = (ObjectResult)await _bookController.Post(book); book = (BookEntity)postResponse.Value; var deleteResponse = (ObjectResult)await _bookController.Delete(book.Id); var isDeleted = (bool)deleteResponse.Value; var getResponse = await _bookController.Get(book.Id); Assert.AreEqual(200, postResponse.StatusCode); Assert.AreEqual(200, deleteResponse.StatusCode); Assert.IsTrue(isDeleted); Assert.IsInstanceOfType(getResponse, typeof(NotFoundResult)); //Consultar obj deletado não deve retorn\r }
public void Delete_NoFound() { _bookRepository.Setup(x => x.Get(1)) .Returns <BookEntity>(null); var response = _bookController.Delete(1); Assert.IsNotNull(response); Assert.IsInstanceOf <NotFoundResult>(response); }
public void Remove_NotExistingGuidPassed_ReturnsNotFoundResponse() { // Arrange var notExistingGuid = 99999; // Act var badResponse = _controller.Delete(notExistingGuid).Result; // Assert Assert.IsType <NotFoundResult>(badResponse); }
public void Ok_WhenCalled_Delete() { var list = Ok_WhenCalled_Get_With_PageControl(); var model = list.FirstOrDefault(); var result = _bookController.Delete(model.Id); Assert.True(result is OkResult); DeleteAllRegisters(); }
public void DeleteBookTest(string id) { var controller = new BookController(this.GetContextWithData()); controller.Delete(id); Assert.That("null", Is.EqualTo(controller.Get(id))); }
public void controller_should_delete() { var referenceNumber = "1234"; _controller.Delete(referenceNumber); _service.Verify(q => q.CancelReservation(referenceNumber)); }
public void Test9() { var service = new BookController(null, _logger); var result = service.Delete("A1"); Assert.AreEqual(500, result.StatusCode); Assert.AreEqual("Problem with database while deleting", result.Value); }
public void Delete_Test() { IBookRepo BookData = new BookRepo(db); BookController obj = new BookController(BookData); var data = obj.Delete(2); var okResult = data as OkObjectResult; Assert.AreEqual(200, okResult.StatusCode); }
public void Throw_When_Passed_Id_Is_Empty() { // Arrange Mock <IBookServices> bookServicesMock = new Mock <IBookServices>(); BookController sut = new BookController(bookServicesMock.Object); Guid invalidId = Guid.Empty; // Act & Assert Assert.Throws <ArgumentNullException>(() => sut.Delete(invalidId)); }
private void BtDelete_Click(object sender, RoutedEventArgs e) { Book seletedBook = dataGrid.SelectedItems[0] as Book; int selectedId = !string.IsNullOrEmpty(TbBookId.Text) ? TransformStringIntoInt(TbBookId.Text) : seletedBook.BookID; Book deletedBook = booksController.Delete(selectedId); MessageBox.Show("The book with " + deletedBook.ToString() + "has been deleted succesfully"); LoadBooks(); }
public void DeleteValidBooking() { // inserindo um registro válido para após apagar BookController bc = new BookController(); string dummyPost = "{bookReference: \"abc12\", car:{category: 0, model: 1, year: 2015}, driver:{age: 28, firstName: \"John\", lastName: \"Doe\"}, dropoffDate: \"2016-02-20T00:00:00-02:00\", hasAgeExtraFee: false, pickupDate: \"2016-02-07T00:00:00-02:00\"}"; bc.Post(dummyPost); Assert.True(bc.Delete("abc12").StatusCode == HttpStatusCode.OK); }
public void DeleteIsNull() { // Arrange BookController controller = new BookController(); // Act ViewResult result = controller.Delete(id: null) as ViewResult; // Assert Assert.IsNull(result); }
[Fact] async Task delete_existing_book() { // Arrange var repository = BookContextMocker.GetInMemoryBookRepository(nameof(get_book_with_existing_id)); var controller = new BookController(repository); int expectedValue = 3; // Act await controller.Delete(1); await controller.Delete(3); var response = await controller.GetAll() as ObjectResult; var books = response.Value as List <Book>; // Assert Assert.Equal(200, response.StatusCode); Assert.Equal(expectedValue, books.Count); }
public void TestDeleteNotFound() { // Arrange BookController controller = new BookController(); // Act ViewResult result = controller.Delete(-15) as ViewResult; // Assert Assert.IsNull(result); }
public async void Task_Delete_Book_Return_OkResult() { //Arrange var controller = new BookController(context); var id = 10; //Act var data = await controller.Delete(id); //Assert Assert.IsType <OkObjectResult>(data); }
public void Task_DeleteBook_Return_View() { //Arrange var controller = new BookController(context); var id = 1; //Act var data = controller.Delete(id); //Assert Assert.IsType <ViewResult>(data); }
public void DeleteReturnsOkResult() { int testId = 1; var mock = new Mock <IBookRepository>(); var controller = new BookController(mock.Object); OkResult response = (OkResult)controller.Delete(testId); Assert.IsNotNull(response); Assert.AreEqual(200, response.StatusCode); }
public void BookController_Delete_IncorrectId() { var mock = new Mock <IBookRepository>(); mock.Setup(m => m.Delete(It.IsAny <int>())).Returns(false); var bookController = new BookController(mock.Object); var result = bookController.Delete(999); Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }
public void TestDeleteViewData() { // Arrange BookController controller = new BookController(); // Act ViewResult result = controller.Delete(1) as ViewResult; BookTbl product = (BookTbl)result.ViewData.Model; // Assert Assert.AreEqual(1, product.Id); }
private void btnDelete_Click(object sender, EventArgs e) { if (bookBindingSource.Current == null) { return; } if (MessageBox.Show("Are you sure you want to delete this record?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _controller.Delete(bookBindingSource.Current as Book); bookBindingSource.RemoveCurrent(); } }
public async void Task_Delete_Return_NotFound() { //Arrange var controller = new BookController(context); var id = 10; //Act var data = await controller.Delete(id); //Assert Assert.IsType <NotFoundResult>(data); }
public async void Task_Delete_Book_Return_BadRequest() { //Arrange var controller = new BookController(context); int?id = null; //Act var data = await controller.Delete(id); //Assert Assert.IsType <BadRequestResult>(data); }
public async Task delete_book_with_not_existing_id_should_return_status_code_404() { //Arrange var repository = BookContextMocker.GetInMemoryBookRepository (nameof(delete_book_with_not_existing_id_should_return_status_code_404)); var mapperMock = new Mock <IMapper>(); var controller = new BookController(repository, mapperMock.Object); //Act var response = await controller.Delete(999); //Assert response.Should().BeOfType <NotFoundObjectResult>(); }
public void DeleteTest() { //Arrange SetUp(); Book book = new Book(); mock.Setup(x => x.Add(book)); controller.Add(book); //Act var result = controller.Delete(book.Id); //Assert Assert.IsInstanceOf <OkResult>(result); }
public void GivenHttpDeleteVerb_WhenRequestParameterIsInvalidIsbn_ThenShouldReturnStatusNotFound() { // Arrange string isbn = null; var service = new Mock <IBookService>(); service.Setup(s => s.Delete(isbn)); var controller = new BookController(service.Object); // Act var result = controller.Delete(isbn); // Assert service.Verify(s => s.Delete(It.IsAny <string>()), Times.Never); result.Should().BeOfType <NotFoundResult>(); }
public void Test10() { List <Book> books = new List <Book>() { new Book() { Name = "A1", Author = "Au1", Year = 2000 }, new Book() { Name = "B2", Author = "Au2", Year = 1444 }, new Book() { Name = "B3", Author = "Au3", Year = 2000 } }; List <Book> booksNew = new List <Book>() { new Book() { Name = "A1", Author = "Au1", Year = 2000 }, new Book() { Name = "B2", Author = "Au2", Year = 1444 }, new Book() { Name = "B3", Author = "Au3", Year = 2000 } }; database = GetDatabase(books); var service = new BookController(database, _logger); var result = service.Delete("Not a book"); Assert.AreEqual(200, result.StatusCode); Assert.AreEqual("Alreadey deleted or not yet added", result.Value); Assert.AreEqual(booksNew.Count, books.Count); for (int i = 0; i < booksNew.Count; i++) { Assert.AreEqual(true, BookEqual(booksNew[i], books[i])); } }
public async Task delete_existing_book() { // Arrange var repository = BookContextMocker.GetInMemoryBookRepository(nameof(delete_existing_book)); var controller = new BookController(repository); // Act var response = await controller.Delete(3); var getBooks = await controller.GetAll() as ObjectResult; var books = getBooks.Value as List <Book>; // Assert Assert.IsType <OkResult>(response); Assert.Equal(2, books.Count); }
public async Task Delete_ReturnsDeleted_If_successful() { //Arrange var bookServiceMock = new Mock <IBookService>(); var sut = new BookController(bookServiceMock.Object); bookServiceMock.Setup(c => c.DeleteBook(It.IsAny <long>())) .Returns(Task.CompletedTask); //Act var result = await sut.Delete(1); Assert.NotNull(result); var response = Assert.IsAssignableFrom <OkObjectResult>(result); Assert.Equal(response.Value, $"Deleted successfully"); }
public void GivenHttpDeleteVerb_WhenRequestParameterIsValidIsbn_ThenShouldReturnStatusNoContent() { // Arrange var isbn = BookStub.CreateNew().Isbn; var service = new Mock <IBookService>(); service.Setup(s => s.IsValidIsbn(isbn)).Returns(true); service.Setup(s => s.Delete(isbn)); var controller = new BookController(service.Object); // Act var result = controller.Delete(isbn) as ResponseMessageResult; // Assert service.Verify(s => s.Delete(It.IsAny <string>()), Times.Exactly(1)); result.Should().BeOfType <ResponseMessageResult>(); result.Response.StatusCode.ShouldBeEquivalentTo(204); }
public async Task delete_nonexisting_book() { // Arrange var repository = BookContextMocker.GetInMemoryBookRepository(nameof(delete_nonexisting_book)); var controller = new BookController(repository); var expectedMessage = "The book to delete record couldn't be found."; // Act var response = await controller.Delete(999) as ObjectResult; var getBooks = await controller.GetAll() as ObjectResult; var books = getBooks.Value as List <Book>; // Assert Assert.Equal(StatusCodes.Status404NotFound, response.StatusCode); Assert.Equal(expectedMessage, response.Value); Assert.Equal(3, books.Count); }