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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }