Example #1
0
        public void Delete_GET_passes_correct_book_and_searchSortPageParams_to_view()
        {
            // Arrange
            string searchString           = "H3J";
            string sortCol                = "name";
            string nextOrder              = SearchSortPageViewModel.SORT_ORDER_ASC;
            string currentOrder           = SearchSortPageViewModel.SORT_ORDER_ASC;
            int    page                   = 1;
            int    pageSize               = 5;
            int    id                     = 1;
            SearchSortPageViewModel sspVM = new SearchSortPageViewModel(searchString, sortCol, currentOrder, nextOrder, page, pageSize);
            RecordViewModel         rVM   = new RecordViewModel(sspVM, id);


            // Act
            ViewResult      result   = controller.Delete(rVM) as ViewResult;
            DeleteViewModel deleteVM = (DeleteViewModel)result.ViewData.Model;

            // Assert
            Assert.IsNotNull(result);

            Assert.AreEqual(id, deleteVM.Book.ID);
            Assert.AreEqual("BBB", deleteVM.Book.Name);

            Assert.IsNotNull(deleteVM.SearchSortPageParams);
            Assert.AreEqual(searchString, deleteVM.SearchSortPageParams.SearchString);
            Assert.AreEqual(sortCol, deleteVM.SearchSortPageParams.SortCol);
            Assert.AreEqual(nextOrder, deleteVM.SearchSortPageParams.NextOrder);
            Assert.AreEqual(page, deleteVM.SearchSortPageParams.Page);
            Assert.AreEqual(pageSize, deleteVM.SearchSortPageParams.PageSize);
        }
Example #2
0
        public void Delete()
        {
            var cancellationToken = new CancellationToken(false);
            var result            = _booksController.Delete("BRL-0001").ExecuteAsync(cancellationToken).Result;

            Assert.IsTrue(result.StatusCode == HttpStatusCode.OK);
        }
Example #3
0
        public void DeleteNoId()
        {
            // act
            var result = (ViewResult)controller.Delete(null);

            // assert
            Assert.AreEqual("Error", result.ViewName);
        }
        public void DeleteViewLoad()
        {
            //act
            ViewResult result = controller.Delete(101) as ViewResult;

            //assert
            Assert.AreEqual("Delete", result.ViewName);
        }
Example #5
0
        public async Task Delete_WhenBookNotFound_ReturnsNotFoundResult()
        {
            // Act
            _bookServiceMock.Setup(x => x.DeleteAsync(_bookId)).ReturnsAsync(false);
            var response = await _booksController.Delete(_bookId);

            // Assert
            response.Should().BeOfType <NotFoundResult>();
        }
Example #6
0
        public void DeleteBookByIdOkResultTest()
        {
            var id = 5;

            var response = _controller.Delete(id).Result as OkObjectResult;

            Assert.IsNotNull(response);
            Assert.AreEqual(200, response.StatusCode);
        }
        public async Task TestDeleteBook_ReturnsSuccessfulAndNoContent()
        {
            //Arrange
            const int deletedId = 1;

            mockService.Setup(x => x.Book.DeleteAsync(deletedId)).ReturnsAsync(true);
            //Act
            var response = await bookController.Delete(deletedId);

            //Assert
            response.Should().BeOfType <OkResult>();
        }
        public async Task Delete_SuccessfulStatusCode_ReturnsOkStatusCode()
        {
            // Arrange
            _booksService.Delete(Arg.Any <string>()).Returns(new OperationResult <Book> {
                Status = Status.Success
            });

            // Act
            var result = await _booksController.Delete("9780132350884") as StatusCodeResult;

            // Assert
            Assert.AreEqual((int)HttpStatusCode.OK, result.StatusCode);
        }
        public async Task Delete_BookDoesNotExist_ReturnsNotFound()
        {
            //Arrange
            const int id = 1;

            _repositoryMock.GetById(Arg.Any <int>()).Returns((Book)null);

            //Act
            var httpActionResult = await _booksController.Delete(id);

            //Assert
            httpActionResult.Should().BeOfType <NotFoundResult>();
        }
        public void Delete()
        {
            var person = BuildBookVO();

            _booksController.Post(person);
            Assert.IsType <NoContentResult>(_booksController.Delete(person.Id.GetValueOrDefault()));
        }
Example #11
0
        public async Task ThenA200OKResultIsReturned()
        {
            var controller = new BooksController(Substitute.For <IBooksRepository>());
            var result     = await controller.Delete(2) as OkResult;

            result.StatusCode.Should().Be(200);
        }
        public async Task Delete_BookIdDoesntExist_ReturnsNotFoundView()
        {
            var book1 = new Book()
            {
                name  = "Higuraszki",
                genre = "Horrorek",
                year  = 2015
            };
            var book2 = new Book()
            {
                name  = "Wrobiona w magiÄ™",
                genre = "Fantasy",
                year  = 2018
            };

            var service = new Mock <IBookRepository>();

            service.Setup(x => x.GetBook(1)).ReturnsAsync(book1);
            service.Setup(x => x.GetBook(2)).ReturnsAsync(book2);
            var controller = new BooksController(service.Object);

            var result = await controller.Delete(2137);

            var viewResult = (ViewResult)result;

            Assert.AreEqual("NotFound", viewResult.ViewName);
        }
        public async Task Delete_BookIdExists_ReturnsSameBook()
        {
            var book1 = new Book()
            {
                name  = "Higuraszki",
                genre = "Horrorek",
                year  = 2015
            };
            var book2 = new Book()
            {
                name  = "Wrobiona w magiÄ™",
                genre = "Fantasy",
                year  = 2018
            };

            var service = new Mock <IBookRepository>();

            service.Setup(x => x.GetBook(1)).ReturnsAsync(book1);
            service.Setup(x => x.GetBook(2)).ReturnsAsync(book2);
            var controller = new BooksController(service.Object);

            var result = await controller.Delete(1);

            var viewResult = (ViewResult)result;
            var model      = (viewResult).Model as Book;

            Assert.AreEqual(book1, model);
        }
        public void DeleteABook_ShouldReturnOkObjectResult()
        {
            var bookId = "1";

            var result = _controller.Delete(bookId);

            result.Should().BeOfType <OkObjectResult>();
        }
Example #15
0
        public async Task remove_book()
        {
            var controller = new BooksController(repo);

            var response = await controller.Delete("0") as ObjectResult;

            Assert.AreEqual(200, response.StatusCode);
        }
Example #16
0
        public void Delete_ReturnsOkResult()
        {
            // Act
            var okResult = _controller.Delete(2);

            // Assert
            Assert.IsType <OkObjectResult>(okResult);
        }
Example #17
0
        public void BooksControllerDelete()
        {
            var booksController = new BooksController(null);

            var result = booksController.Delete(null);

            Assert.IsNotNull(result);
        }
Example #18
0
        public void Delete_throws_NotFound_if_not_found()
        {
            var mockContext = new MockContext();
            var controller  = new BooksController(mockContext.Object);

            var httpException = Assert.ThrowsAsync <HttpException>(async() => await controller.Delete(-1));

            Assert.That(httpException.GetHttpCode(), Is.EqualTo((int)HttpStatusCode.NotFound));
        }
Example #19
0
        public void Delete_throws_BadRequest_if_no_Id_passed()
        {
            var mockContext = new MockContext();
            var controller  = new BooksController(mockContext.Object);

            var httpException = Assert.ThrowsAsync <HttpException>(async() => await controller.Delete((int?)null));

            Assert.That(httpException.GetHttpCode(), Is.EqualTo((int)HttpStatusCode.BadRequest));
        }
Example #20
0
        public void ShouldDeleteBook()
        {
            const int id = 1;

            mockRepository.Setup(m => m.Delete(id));
            JsonResult result = (JsonResult)controller.Delete(id);

            Assert.AreEqual(id, result.Data);
            mockRepository.Verify(m => m.Delete(id));
        }
Example #21
0
        public void Delete_throws_Forbidden_if_not_mine()
        {
            var userId        = "foxyboots9-guid";
            var mockDbContext = new MockContext();
            var controller    = new BooksController(mockDbContext.Object, () => userId);

            var httpException = Assert.ThrowsAsync <HttpException>(async() => await controller.Delete(4));

            Assert.That(httpException.GetHttpCode(), Is.EqualTo((int)HttpStatusCode.Forbidden));
        }
Example #22
0
        public void Remove()
        {
            var books       = _controller.Get().Value;
            var removedBook = books.First();

            _controller.Delete(books.First().ID);
            var result = _controller.Get().Value;

            Assert.DoesNotContain(removedBook, result);
        }
        public async Task Delete_should_return_NoContent_result()
        {
            // Arrange

            // Act
            var result = await _controller.Delete(Guid.Empty);

            // Assert
            Assert.IsType <NoContentResult>(result);
            A.CallTo(() => _mediator.Send(A <DeleteBookCommand> .Ignored, A <CancellationToken> .Ignored)).MustHaveHappenedOnceExactly();
        }
Example #24
0
        public void ShouldDeleteBookAndShowListOfBooks()
        {
            var mockedRepo = new Mock<IRepository>();
            mockedRepo.Setup(repo => repo.Delete<Book>(1));
            var booksController = new BooksController(mockedRepo.Object);

            var viewResult = booksController.Delete(1);
            mockedRepo.Verify(repo => repo.Delete<Book>(1));
            Assert.AreEqual("Book successfully deleted", booksController.TempData["flash"]);
            Assert.AreEqual("List", viewResult.RouteValues["action"]);
        }
        public void ShouldDeleteBookAndShowListOfBooks()
        {
            var mockedRepo = new Mock <Repository>();

            mockedRepo.Setup(repo => repo.Delete <Book>(1));
            var booksController = new BooksController(mockedRepo.Object);

            var viewResult = booksController.Delete(1);

            mockedRepo.Verify(repo => repo.Delete <Book>(1));
            Assert.AreEqual("Book successfully deleted", booksController.TempData["flashSuccess"]);
            Assert.AreEqual("List", viewResult.RouteValues["action"]);
        }
        public async Task Delete_ReturnsNotFound()
        {
            Mock <IBooksRepository> mockRepo = new Mock <IBooksRepository>();

            mockRepo.Setup(repo => repo.DeleteAsync("i1")).ReturnsAsync(false);
            BooksController controller = new BooksController(mockRepo.Object);
            IActionResult   response   = await controller.Delete("i1");

            Assert.IsType <NotFoundObjectResult>(response);
            ObjectResult objectResponse = response as ObjectResult;

            Assert.Equal(404, objectResponse.StatusCode);
        }
Example #27
0
        public async Task Delete_Book_BadRequest400()
        {
            // Arrange.
            var ctx        = new CatalogDbContext(_dbOptions);
            var controller = new BooksController(ctx);
            var id         = 0;

            // Act.
            var result = await controller.Delete(id);

            // Assert.
            Assert.IsType <BadRequestResult>(result);
        }
Example #28
0
        public async Task Delete_Book_NotFound404()
        {
            // Arrange.
            var ctx        = new CatalogDbContext(_dbOptions);
            var controller = new BooksController(ctx);
            var id         = 200;

            // Act.
            var result = await controller.Delete(id);

            // Assert.
            Assert.IsType <NotFoundResult>(result);
        }
        public void Delete_Should_Call_Delete_Method()
        {
            // Arrange
            _mockRepo.Setup(repo => repo.Delete("1"));

            // Act
            var methodResult = _mockController.Delete("1");

            // Assert
            var testResult = methodResult as OkResult;

            Assert.Equal(200, testResult.StatusCode);
        }
Example #30
0
        public void DeleteBook_ShouldReturnOk()
        {
            //Arrange
            var mock = new Mock <IBookService>();

            mock.Setup(x => x.DeleteBook(It.IsAny <int>())).Returns(true);
            var booksController = new BooksController(mock.Object);

            IHttpActionResult result = booksController.Delete(1);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
Example #31
0
        public async Task Delete_Book_Success204()
        {
            // Arrange.
            var ctx        = new CatalogDbContext(_dbOptions);
            var controller = new BooksController(ctx);
            var id         = 2;

            // Act.
            var result = await controller.Delete(id);

            // Assert.
            Assert.IsType <NoContentResult>(result);
            Assert.Null(ctx.Books.SingleOrDefault(a => a.Id == id));
        }