示例#1
0
        public async Task DeletePostAction_DeleteModelFromService()
        {
            // Arrange

            // Act
            var result = await validController.DeleteConfirmed(entity.Id);

            // Assert
            mock.Verify(a => a.DeleteAsync(entity.Id));
        }
示例#2
0
        public async Task DeleteConfirmed_Redirects()
        {
            // Arrange
            var mockRepo   = new Mock <IInvoicesRepository>();
            var controller = new ItemsController(mockRepo.Object);

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

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

            Assert.Equal("Index", redirect.ActionName);
        }
        public void testDb_Delete_RemovesToDb()
        {
            //Arrange
            ItemsController controller = new ItemsController(db);
            Item            testItem   = new Item
            {
                ItemId      = 5,
                Name        = "Sarah Pearson gummi flavor",
                Description = "pumpkin suprise",
                Cost        = 100000,
            };

            //Act
            controller.Create(testItem);
            controller.DeleteConfirmed(testItem.ItemId);
            var collection = (controller.Index() as ViewResult).ViewData.Model as List <Item>;

            //Assert
            CollectionAssert.DoesNotContain(collection, testItem);
        }
        public async Task Post_Delete_And_Redirect_Result()
        {
            //Arrange
            var  mock = new Mock <IItemsRepository>();
            Item item = new Item {
                ID = 1, UserID = "john123", Title = "New Title"
            };

            mock.Setup(x => x.GetItem(It.IsAny <int>())).ReturnsAsync(item);
            mock.Setup(repo => repo.DeleteItem(It.IsAny <Item>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            var controller = new ItemsController(mock.Object);

            //Act
            var result = await controller.DeleteConfirmed(item.ID);

            //Assert
            var RedirectToRouteResult = Assert.IsType <RedirectToRouteResult>(result);

            Assert.Equal("Index", RedirectToRouteResult.RouteValues["action"]);
            mock.Verify();
        }