public void When_reassign_further_action_Then_should_call_correct_methods()
        {
            // Given
            var target = CreateController();
            var viewModel = new ReassignTaskViewModel()
                                {
                                    CompanyId = 1,
                                    FurtherControlMeasureTaskId = 4,
                                    ReassignTaskToId = Guid.NewGuid()
                                };

            _taskService
                .Setup(x => x.ReassignTask(It.IsAny<ReassignTaskToEmployeeRequest>()));

            // When
            target.ReassignTask(viewModel);


            // Then
            _taskService
                .Verify(x => x.ReassignTask(It.Is<ReassignTaskToEmployeeRequest>(y => y.GetType() == typeof(ReassignTaskToEmployeeRequest))));
            _taskService
                .Verify(x => x.ReassignTask(It.Is<ReassignTaskToEmployeeRequest>(y => y.CompanyId == viewModel.CompanyId)));
            _taskService
                .Verify(x => x.ReassignTask(It.Is<ReassignTaskToEmployeeRequest>(y => y.TaskId == viewModel.FurtherControlMeasureTaskId)));
            _taskService
                .Verify(x => x.ReassignTask(It.Is<ReassignTaskToEmployeeRequest>(y => y.ReassignTaskToId == viewModel.ReassignTaskToId)));
            _taskService
                .Verify(x => x.ReassignTask(It.Is<ReassignTaskToEmployeeRequest>(y => y.UserId == target.CurrentUser.UserId)));

        }
        public void When_invalid_view_model_Then_should_throw_correct_exception()
        {
            // Given
            var target = CreateController();
            var viewModel = new ReassignTaskViewModel();

            target.ModelState.AddModelError("Anything", "Some Error Doesn't Matter");

            // When
            // Then
            Assert.Throws<ArgumentException>(() => target.ReassignTask(viewModel));
        }
        public void When_reassign_further_action_with_valid_request_Then_should_return_correct_result()
        {
            // Given
            var target = CreateController();
            var viewModel = new ReassignTaskViewModel();

            // When
            var result = target.ReassignTask(viewModel);

            // Then
            dynamic data = result.Data;
            Assert.That(data.Success, Is.EqualTo(true));
        }
        public JsonResult ReassignTask(ReassignTaskViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                throw new ArgumentException("Invalid Arguments To Reassign Task");
            }

            using (var session = _businessSafeSessionManager.Session)
            {
                var reassignTaskToEmployeeRequest = CreateReassignRequest(viewModel);
                _taskService.ReassignTask(reassignTaskToEmployeeRequest);

                _businessSafeSessionManager.CloseSession();
            }

            _bus.Publish(new TaskAssigned { TaskGuid = viewModel.TaskGuid });

            return Json(new ReassignTaskResultViewModel()
            {
                Success = true
            });
        }
 private ReassignTaskToEmployeeRequest CreateReassignRequest(ReassignTaskViewModel viewModel)
 {
     return new ReassignTaskToEmployeeRequest()
     {
         CompanyId = viewModel.CompanyId,
         TaskId = viewModel.FurtherControlMeasureTaskId,
         ReassignTaskToId = viewModel.ReassignTaskToId,
         UserId = CurrentUser.UserId
         ,
         TaskGuid = viewModel.TaskGuid
     };
 }