public async Task MessageAllVolunteersSendsMessageTaskVolunteersCommandAsyncWithCorrectData()
        {
            const int organizationId = 1;
            var model = new MessageTaskVolunteersModel();

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<TaskQueryAsync>())).ReturnsAsync(new TaskSummaryModel { 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);
        }
Exemple #2
0
        public IActionResult MessageAllVolunteers(MessageTaskVolunteersModel model)
        {
            //TODO: Query only for the tenant Id rather than the whole activity detail
            if (!ModelState.IsValid)
            {
                return HttpBadRequest(ModelState);
            }

            var task = _bus.Send(new TaskQuery { TaskId = model.TaskId });
            if (task == null)
            {
                return HttpNotFound();
            }

            if (!User.IsTenantAdmin(task.TenantId))
            {
                return HttpUnauthorized();
            }

            _bus.Send(new MessageTaskVolunteersCommand { Model = model });
            return Ok();
        }
        public async Task MessageAllVounteersSendsTaskQueryAsyncWithCorrectTaskId()
        {
            var model = new MessageTaskVolunteersModel { 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);
        }
Exemple #4
0
        public async Task<IActionResult> MessageAllVolunteers(MessageTaskVolunteersModel model)
        {
            //TODO: Query only for the organization Id rather than the whole event detail
            if (!ModelState.IsValid)
            {
                return HttpBadRequest(ModelState);
            }
            
            var task = await _mediator.SendAsync(new TaskQueryAsync { TaskId = model.TaskId });
            if (task == null)
            {
                return HttpNotFound();
            }

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

            return Ok();
        }