Esempio n. 1
0
        public async Task AssignRedirectsToRoute()
        {
            const int organizationId   = 1;
            const int taskId           = 1;
            var       taskModelSummary = new TaskSummaryModel {
                ActivityId = 1
            };

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <TaskQueryAsync>())).ReturnsAsync(taskModelSummary);
            mediator.Setup(x => x.Send(It.Is <ActivityByActivityIdQuery>(y => y.ActivityId == taskModelSummary.ActivityId))).Returns(new Activity {
                Campaign = new Campaign {
                    ManagingOrganizationId = organizationId
                }
            });

            var sut = new TaskController(mediator.Object);

            MakeUserOrganizationAdminUser(sut, organizationId.ToString());

            var result = await sut.Assign(taskId, null) as RedirectToRouteResult;

            Assert.Equal(result.RouteValues["controller"], "Task");
            Assert.Equal(result.RouteValues["Area"], "Admin");
            Assert.Equal(result.RouteValues["action"], nameof(TaskController.Details));
            Assert.Equal(result.RouteValues["id"], taskId);
        }
Esempio n. 2
0
        public async Task AssignSendsAssignTaskCommandAsync()
        {
            const int organizationId   = 1;
            const int taskId           = 1;
            var       taskModelSummary = new TaskSummaryModel {
                ActivityId = 1
            };
            var userIds = new List <string> {
                "1", "2"
            };

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <TaskQueryAsync>())).ReturnsAsync(taskModelSummary);
            mediator.Setup(x => x.Send(It.Is <ActivityByActivityIdQuery>(y => y.ActivityId == taskModelSummary.ActivityId))).Returns(new Activity {
                Campaign = new Campaign {
                    ManagingOrganizationId = organizationId
                }
            });

            var sut = new TaskController(mediator.Object);

            MakeUserOrganizationAdminUser(sut, organizationId.ToString());
            await sut.Assign(taskId, userIds);

            mediator.Verify(x => x.SendAsync(It.Is <AssignTaskCommandAsync>(y => y.TaskId == taskId && y.UserIds == userIds)), Times.Once);
        }
Esempio n. 3
0
        public async Task AssignReturnsUnauthorizedResultWhenUserIsNotOrgAdmin()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <OrganizationIdByTaskIdQuery>())).ReturnsAsync(It.IsAny <int>());

            var sut = new TaskController(mediator.Object, null);

            sut.SetDefaultHttpContext();
            var result = await sut.Assign(1, null);

            Assert.IsType <UnauthorizedResult>(result);
        }
Esempio n. 4
0
        public async Task AssignReturnsForbidResultWhenUserIsNotAuthorized()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <OrganizationIdByVolunteerTaskIdQuery>())).ReturnsAsync(It.IsAny <int>());
            mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableTaskQuery>())).ReturnsAsync(new FakeAuthorizableTask(false, false, false, false));

            var sut = new TaskController(mediator.Object, null);

            sut.SetDefaultHttpContext();
            var result = await sut.Assign(1, null);

            Assert.IsType <ForbidResult>(result);
        }
Esempio n. 5
0
        public async Task AssignSendsOrganizationIdByTaskIdQueryWithCorrectTaskId()
        {
            const int taskId = 1;

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <OrganizationIdByTaskIdQuery>())).ReturnsAsync(It.IsAny <int>());

            var sut = new TaskController(mediator.Object, null);

            sut.SetDefaultHttpContext();
            await sut.Assign(taskId, null);

            mediator.Verify(x => x.SendAsync(It.Is <OrganizationIdByTaskIdQuery>(y => y.TaskId == taskId)), Times.Once);
        }
Esempio n. 6
0
        public async Task AssignSendsOrganizationIdByTaskIdQueryWithCorrectTaskId()
        {
            const int volunteerTaskId = 1;

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <OrganizationIdByVolunteerTaskIdQuery>())).ReturnsAsync(It.IsAny <int>());
            mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableTaskQuery>())).ReturnsAsync(new FakeAuthorizableTask(false, true, false, false));

            var sut = new TaskController(mediator.Object, null);

            sut.SetDefaultHttpContext();
            await sut.Assign(volunteerTaskId, null);

            mediator.Verify(x => x.SendAsync(It.Is <OrganizationIdByVolunteerTaskIdQuery>(y => y.VolunteerTaskId == volunteerTaskId)), Times.Once);
        }
Esempio n. 7
0
        public async Task AssignSendsAssignTaskCommand()
        {
            const int volunteerTaskId = 1;
            var       userIds         = new List <string> {
                "1", "2"
            };

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <OrganizationIdByVolunteerTaskIdQuery>())).ReturnsAsync(It.IsAny <int>());
            mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableTaskQuery>())).ReturnsAsync(new FakeAuthorizableTask(false, true, false, false));

            var sut = new TaskController(mediator.Object, null);
            await sut.Assign(volunteerTaskId, userIds);

            mediator.Verify(x => x.SendAsync(It.Is <AssignVolunteerTaskCommand>(y => y.VolunteerTaskId == volunteerTaskId && y.UserIds == userIds)), Times.Once);
        }
Esempio n. 8
0
        public async Task AssignRedirectsToCorrectRoute()
        {
            const int volunteerTaskId = 1;

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <OrganizationIdByVolunteerTaskIdQuery>())).ReturnsAsync(It.IsAny <int>());
            mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableTaskQuery>())).ReturnsAsync(new FakeAuthorizableTask(false, true, false, false));

            var sut = new TaskController(mediator.Object, null);

            var result = await sut.Assign(volunteerTaskId, null) as RedirectToRouteResult;

            Assert.Equal(result.RouteValues["controller"], "Task");
            Assert.Equal(result.RouteValues["Area"], "Admin");
            Assert.Equal(result.RouteValues["action"], nameof(TaskController.Details));
            Assert.Equal(result.RouteValues["id"], volunteerTaskId);
        }
Esempio n. 9
0
        public async Task AssignSendsAssignTaskCommand()
        {
            const int organizationId = 1;
            const int taskId         = 1;
            var       userIds        = new List <string> {
                "1", "2"
            };

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <OrganizationIdByTaskIdQuery>())).ReturnsAsync(organizationId);

            var sut = new TaskController(mediator.Object, null);

            sut.MakeUserAnOrgAdmin(organizationId.ToString());
            await sut.Assign(taskId, userIds);

            mediator.Verify(x => x.SendAsync(It.Is <AssignTaskCommand>(y => y.TaskId == taskId && y.UserIds == userIds)), Times.Once);
        }
Esempio n. 10
0
        public async Task AssignRedirectsToCorrectRoute()
        {
            const int organizationId = 1;
            const int taskId         = 1;

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <OrganizationIdByTaskIdQuery>())).ReturnsAsync(organizationId);

            var sut = new TaskController(mediator.Object, null);

            sut.MakeUserAnOrgAdmin(organizationId.ToString());

            var result = await sut.Assign(taskId, null) as RedirectToRouteResult;

            Assert.Equal(result.RouteValues["controller"], "Task");
            Assert.Equal(result.RouteValues["Area"], "Admin");
            Assert.Equal(result.RouteValues["action"], nameof(TaskController.Details));
            Assert.Equal(result.RouteValues["id"], taskId);
        }
Esempio n. 11
0
        public async Task AssignReturnsHttpUnauthorizedResultWhenUserIsNotOrgAdmin()
        {
            var taskModelSummary = new TaskSummaryModel {
                ActivityId = 1
            };

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <TaskQueryAsync>())).ReturnsAsync(taskModelSummary);
            mediator.Setup(x => x.Send(It.IsAny <ActivityByActivityIdQuery>())).Returns(new Activity {
                Campaign = new Campaign {
                    ManagingOrganizationId = 1
                }
            });

            var sut = new TaskController(mediator.Object);

            sut.SetDefaultHttpContext();
            var result = await sut.Assign(1, null);

            Assert.IsType <HttpUnauthorizedResult>(result);
        }
Esempio n. 12
0
        public async Task AssignSendsTaskQueryAsyncWithCorrectTaskId()
        {
            const int taskId           = 1;
            var       taskModelSummary = new TaskSummaryModel {
                ActivityId = 1
            };

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <ActivityByActivityIdQuery>())).Returns(new Activity {
                Campaign = new Campaign {
                    ManagingOrganizationId = 1
                }
            });
            mediator.Setup(x => x.SendAsync(It.IsAny <TaskQueryAsync>())).ReturnsAsync(taskModelSummary);

            var sut = new TaskController(mediator.Object);

            sut.SetDefaultHttpContext();
            await sut.Assign(taskId, null);

            mediator.Verify(x => x.SendAsync(It.Is <TaskQueryAsync>(y => y.TaskId == taskId)), Times.Once);
        }