コード例 #1
0
        public async Task MessageAllVolunteersSendsMessageTaskVolunteersCommandAsyncWithCorrectData()
        {
            const int organizationId = 1;
            var model = new MessageTaskVolunteersViewModel();

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdByTaskIdQueryAsync>())).ReturnsAsync(organizationId);

            var sut = new TaskController(mediator.Object, null);
            sut.MakeUserAnOrgAdmin(organizationId.ToString());
            await sut.MessageAllVolunteers(model);

            mediator.Verify(x => x.SendAsync(It.Is<MessageTaskVolunteersCommandAsync>(y => y.Model == model)), Times.Once);
        }
コード例 #2
0
        public async Task MessageAllVolunteersSendsMessageTaskVolunteersCommandAsyncWithCorrectData()
        {
            const int organizationId = 1;
            var model = new MessageTaskVolunteersViewModel();

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<TaskQueryAsync>())).ReturnsAsync(new TaskSummaryViewModel { OrganizationId = organizationId });

            var sut = new TaskController(mediator.Object, Mock.Of<ITaskSummaryModelValidator>());
            MakeUserOrganizationAdminUser(sut, organizationId.ToString());
            await sut.MessageAllVolunteers(model);

            mediator.Verify(x => x.SendAsync(It.Is<MessageTaskVolunteersCommandAsync>(y => y.Model == model)), Times.Once);
        }
コード例 #3
0
        public async Task<IActionResult> MessageAllVolunteers(MessageTaskVolunteersViewModel model)
        {
            //TODO: Query only for the organization Id rather than the whole event detail
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            
            var task = await _mediator.SendAsync(new TaskQueryAsync { TaskId = model.TaskId });
            if (task == null)
            {
                return NotFound();
            }

            if (!User.IsOrganizationAdmin(task.OrganizationId))
            {
                return Unauthorized();
            }
            
            await _mediator.SendAsync(new MessageTaskVolunteersCommandAsync { Model = model });

            return Ok();
        }
コード例 #4
0
        public async Task MessageAllVounteersSendsTaskQueryAsyncWithCorrectTaskId()
        {
            var model = new MessageTaskVolunteersViewModel { TaskId = 1 };
            var mediator = new Mock<IMediator>();

            var sut = new TaskController(mediator.Object, Mock.Of<ITaskSummaryModelValidator>());
            await sut.MessageAllVolunteers(model);

            mediator.Verify(x => x.SendAsync(It.Is<TaskQueryAsync>(y => y.TaskId == model.TaskId)), Times.Once);
        }
コード例 #5
0
        public async Task<IActionResult> MessageAllVolunteers(MessageTaskVolunteersViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var tasksOrganizationId = await _mediator.SendAsync(new OrganizationIdByTaskIdQuery { TaskId = viewModel.TaskId });
            if (!User.IsOrganizationAdmin(tasksOrganizationId))
            {
                return Unauthorized();
            }

            await _mediator.SendAsync(new MessageTaskVolunteersCommand { Model = viewModel });

            return Ok();
        }