public void Given_valid_request_When_copy_risk_assessment_Then_should_call_correct_methods()
        {
            // Given
            var controller = GetTarget();
            controller.CurrentUser.CompanyId = _companyId;
            var title = "the title";
            var viewModel = new CopyRiskAssessmentViewModel {Reference = _reference, RiskAssessmentId = _riskAssessmentId, Title = title};

            // When
            controller.Copy(viewModel);

            // Then
            _riskAssessmentService.Verify(x => x.CopyRiskAssessment(It.Is<CopyRiskAssessmentRequest>(y => y.CompanyId == _companyId 
                && y.RiskAssessmentToCopyId == _riskAssessmentId 
                && y.Reference == _reference
                && y.Title == title)));
        }
        public void Given_valid_request_When_copy_risk_assessment_Then_should_return_correct_result()
        {
            // Given
            var controller = GetTarget();
            
            long expectedResult = 300;
            _riskAssessmentService
                .Setup(x => x.CopyRiskAssessment(It.IsAny<CopyRiskAssessmentRequest>()))
                .Returns(expectedResult);

            var viewModel = new CopyRiskAssessmentViewModel { Reference = _reference, RiskAssessmentId = _riskAssessmentId, Title = "" };

            // When
            var result = controller.Copy(viewModel) as JsonResult;

            // Then
            dynamic data = result.Data;
            Assert.That(data.ToString(), Contains.Substring("Success = True"));
            Assert.That(data.ToString(), Contains.Substring("Id = " + expectedResult));
        }
        public JsonResult Copy(CopyRiskAssessmentViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return ModelStateErrorsWithKeysAsJson();
            }

            try
            {
                var result = _fireRiskAssessmentService.CopyRiskAssessment(
                    new CopyRiskAssessmentRequest
                        {
                            CompanyId = CurrentUser.CompanyId,
                            RiskAssessmentToCopyId = viewModel.RiskAssessmentId,
                            Reference = viewModel.Reference,
                            Title = viewModel.Title,
                            UserId = CurrentUser.UserId
                        });

                return Json(new {Success = true, Id = result});
            }
            catch (ValidationException validationException)
            {
                ModelState.AddValidationErrors(validationException);
                return ModelStateErrorsWithKeysAsJson();
            }
        }