コード例 #1
0
        public async void TestGoalDeleteConfirmedSiteAdminRedirectToAction()
        {
            const int campaignId = 123;
            const int goalId     = 567;
            // Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <GoalDeleteQuery>()))
            .ReturnsAsync(new GoalDeleteViewModel
            {
                Id = goalId,
                OwningOrganizationId = OrgAdminOrgId,
                CampaignId           = campaignId
            })
            .Verifiable();

            var goalController = new GoalController(mockMediator.Object);

            var mockContext = MockControllerContextWithUser(SiteAdmin());

            goalController.ControllerContext = mockContext.Object;

            // Act
            var result = await goalController.DeleteConfirmed(goalId) as RedirectToActionResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal("Details", result.ActionName);
            Assert.Equal("Campaign", result.ControllerName);
            Assert.Equal(AreaNames.Admin, result.RouteValues["area"]);
            Assert.Equal(campaignId, result.RouteValues["id"]);
            mockMediator.Verify(mock => mock.SendAsync(It.IsAny <GoalDeleteCommand>()), Times.Once);
        }
コード例 #2
0
        public async Task Test_Delete_Deletes_Goal()
        {
            controller.ControllerContext = new MockControllerContext().ControllerContext.Object;

            await controller.DeleteConfirmed(1);

            context.MockGoals.Verify(x => x.Remove(It.Is <Goal>(t => t.GoalId == 1)));
        }
コード例 #3
0
        public async void TestGoalDeleteConfirmedForOrgAdminForNonexistantGoalReturn401()
        {
            // Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <GoalDeleteQuery>()))
            .ReturnsAsync(null)
            .Verifiable();

            var goalController = new GoalController(mockMediator.Object);

            var mockContext = MockControllerContextWithUser(OrgAdmin(OrgAdminOrgId));

            goalController.ControllerContext = mockContext.Object;

            // Act
            var result = await goalController.DeleteConfirmed(987);

            // Assert
            Assert.IsType <UnauthorizedResult>(result);
        }
コード例 #4
0
        public async void TestGoalDeleteConfirmedForWrongOrgAdminReturns401()
        {
            // Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <GoalDeleteQuery>()))
            .ReturnsAsync(new GoalDeleteViewModel {
                OwningOrganizationId = OrgAdminOrgId
            })
            .Verifiable();
            var goalController = new GoalController(mockMediator.Object);

            var mockContext = MockControllerContextWithUser(OrgAdmin(654));

            goalController.ControllerContext = mockContext.Object;

            // Act
            var result = await goalController.DeleteConfirmed(567);

            // Assert
            Assert.IsType <UnauthorizedResult>(result);
        }