示例#1
0
        public async Task DeleteConfirmedPostReturnsRedirectToTheCorrectActionWithTheCorrectRouteValues()
        {
            // Arrange
            SkillController controller;

            MockMediatorSkillDeleteQuery(out controller);

            var viewModel = new SkillDeleteViewModel {
                SkillBelongsToSameOrgAsOrgAdmin = true
            };

            var routeValueDictionary = new RouteValueDictionary {
                ["area"] = "Admin"
            };

            var mockContext = MockControllerContextWithUser(SiteAdmin());

            controller.ControllerContext = mockContext.Object;

            // Act
            var result = await controller.DeleteConfirmed(viewModel) as RedirectToActionResult;

            // Assert
            Assert.Equal(nameof(SkillController.Index), result.ActionName);
            Assert.Equal(routeValueDictionary, result.RouteValues);
        }
        private static Mock<IMediator> MockMediatorSkillDeleteQuery(out SkillController controller, SkillDeleteViewModel model = null)
        {
            if (model == null) model = new SkillDeleteViewModel {  HierarchicalName = "Name" };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<SkillDeleteQuery>())).ReturnsAsync(model).Verifiable();
            controller = new SkillController(mockMediator.Object);
            return mockMediator;
        }
示例#3
0
        public async Task <IActionResult> DeleteConfirmed(SkillDeleteViewModel viewModel)
        {
            if (!viewModel.SkillBelongsToSameOrgAsOrgAdmin)
            {
                return(new UnauthorizedResult());
            }

            await _mediator.SendAsync(new SkillDeleteCommand { Id = viewModel.SkillId });

            return(RedirectToAction(nameof(Index), new { area = "Admin" }));
        }
        public async Task DeleteConfirmedPostReturnsUnauthorizedResult_WhenSkillBelongsToSameOrgAsOrgAdminIsFalse()
        {
            // Arrange
            var viewModel = new SkillDeleteViewModel { SkillBelongsToSameOrgAsOrgAdmin = false };
            SkillController controller;
            MockMediatorSkillDeleteQueryNullModel(out controller);

            // Act
            var result = await controller.DeleteConfirmed(viewModel) as UnauthorizedResult;

            // Assert
            Assert.IsType<UnauthorizedResult>(result);
        }
        public async Task DeleteConfirmedPostSendsSkillDeleteCommandWithCorrectSkillId()
        {
            // Arrange
            const int skillId = 1;
            SkillController controller;
            var mockMediator = MockMediatorSkillDeleteQuery(out controller);

            var viewModel = new SkillDeleteViewModel { SkillBelongsToSameOrgAsOrgAdmin = true, SkillId = skillId };

            var mockContext = MockControllerContextWithUser(SiteAdmin());
            controller.ControllerContext = mockContext.Object;

            // Act            
            await controller.DeleteConfirmed(viewModel);

            // Assert
            mockMediator.Verify(mock => mock.SendAsync(It.Is<SkillDeleteCommand>(y => y.Id == skillId)), Times.Once);
        }