public void DeleteConfirmedViewLoad()
        {
            //act
            RedirectToRouteResult result = controller.DeleteConfirmed(102) as RedirectToRouteResult;

            //assert
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
예제 #2
0
        public void DeleteConfirmedNoId()
        {
            // act
            ViewResult result = (ViewResult)controller.DeleteConfirmed(null);

            // assert
            Assert.AreEqual("Error", result.ViewName);
        }
예제 #3
0
        public void DeleteConfirmed_returns_BadRequest_StatusCode_on_null_input_param()
        {
            // Arrange

            // Act
            //ViewResult result = controller.Details(null) as ViewResult;  // don't use - result is always null for some reason??!!
            var result = controller.DeleteConfirmed(null);

            // Assert
            Assert.IsInstanceOf <HttpStatusCodeResult>(result);
        }
예제 #4
0
        public void BooksControllerDeleteConfirmed()
        {
            var booksController = new BooksController(null);

            var result = booksController.DeleteConfirmed(1);

            Assert.IsNotNull(result);
        }
예제 #5
0
        public void DeleteConfirmed_throws_BadRequest_if_no_Id_passed()
        {
            var mockContext = new MockContext();
            var controller  = new BooksController(mockContext.Object);

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

            Assert.That(httpException.GetHttpCode(), Is.EqualTo((int)HttpStatusCode.BadRequest));
        }
예제 #6
0
        public void DeleteConfirmed_throws_NotFound_if_not_found()
        {
            var mockContext = new MockContext();
            var controller  = new BooksController(mockContext.Object);

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

            Assert.That(httpException.GetHttpCode(), Is.EqualTo((int)HttpStatusCode.NotFound));
        }
예제 #7
0
        public void DeleteConfirmed_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.DeleteConfirmed(4));

            Assert.That(httpException.GetHttpCode(), Is.EqualTo((int)HttpStatusCode.Forbidden));
        }
예제 #8
0
        public void DeleteUsesDAL()
        {
            //Arrange
            Fakes.FakeBookDAL DAL        = new Fakes.FakeBookDAL();
            BooksController   controller = new BooksController(DAL);

            //Act
            controller.DeleteConfirmed(5);

            //Assert
            Assert.AreEqual(5, DAL.bookDeleted);
        }
예제 #9
0
        public async Task DeleteConfirmed_removes_Book_and_redirects_to_Index_if_mine()
        {
            var userId        = "foxyboots9-guid";
            var mockDbContext = new MockContext();
            var controller    = new BooksController(mockDbContext.Object, () => userId);

            var result = await controller.DeleteConfirmed(21) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.RouteValues["action"], "Index");

            mockDbContext.MockBooks.Verify(m => m.Remove(It.IsAny <Book>()), Times.Once());
            mockDbContext.Verify(m => m.SaveChangesAsync(), Times.AtLeastOnce());
        }
예제 #10
0
        public async Task DeleteOnPost_WhenEntityExists_ReturnsRedirectToIndex()
        {
            //Arrange
            TestDbSeeder.Initialize(_db);
            TestDbSeeder.SeedBooks(_db);

            //Act
            var bookId = 1;
            var result = await _controller.DeleteConfirmed(bookId);

            //Assert
            var book = await _db.Books.FirstOrDefaultAsync(b => b.Id == bookId);

            Assert.Null(book);
            var books = await _db.Books.ToListAsync();

            Assert.NotNull(books);
            Assert.Equal(TestDbSeeder.Books.Length - 1, books.Count);

            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal(nameof(BooksController.Index), redirectToActionResult.ActionName);
        }
예제 #11
0
        public async Task ConfirmedDelete_ShouldRedirectToIndexPage()
        {
            var book = new Book()
            {
                Title = "TEST1"
            };

            _bookService.Setup(mock => mock.GetBookByIdAsync(1)).ReturnsAsync(book);

            var result = await _booksController.DeleteConfirmed(1);

            var redirectResult = result as RedirectToActionResult;

            result.Should().BeOfType <RedirectToActionResult>();
            redirectResult.ActionName.Should().Be("Index");
        }
예제 #12
0
        public void TestDeleteConfirmedMethod()
        {
            Books book = new Books {
                BookId = 1, BookTitle = "Harry Porter", Price = 10
            };

            //Mock IRepository of books
            Mock <IRepository <Books> > mockBooksController = new Mock <IRepository <Books> >();

            mockBooksController.Setup(b => b.Delete(It.IsAny <int>()));

            //Pass in the IRepository books
            BooksController booksController = new BooksController(mockBooksController.Object);
            var             result          = booksController.DeleteConfirmed(1) as RedirectToRouteResult;

            Assert.AreEqual(result.RouteValues["action"], "Index");
        }
        public void Books_DeleteConfirmed()
        {
            // Arrange
            Source source = GetTestSource();
            var    books  = GetTestBookSet(source);
            var    db     = new Mock <IPersonalInformationManagerContext>();

            db.Setup(e => e.Books).Returns(books);
            db.Setup(e => e.Books.Find(It.IsAny <int>())).Returns(GetTestBook(source));
            db.Setup(e => e.SaveChanges()).Returns(1);
            BooksController controller = new BooksController(db.Object);

            // Act
            var result = (RedirectToRouteResult)controller.DeleteConfirmed(1);

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }