public AssessmentViewModel GetViewModel() { var viewModel = new AssessmentViewModel(); var hazardousSubstanceRiskAssessment = _hazardousSubstanceRiskAssessmentService.GetRiskAssessment(_hazardousSubstanceRiskAssessmentId.Value, _companyId.Value); if (hazardousSubstanceRiskAssessment.Group != null) { viewModel.HazardGroup = hazardousSubstanceRiskAssessment.Group.Code; var controlSystemDto = _controlSystemService.Calculate(hazardousSubstanceRiskAssessment.Group.Code, hazardousSubstanceRiskAssessment.MatterState, hazardousSubstanceRiskAssessment.Quantity, hazardousSubstanceRiskAssessment.DustinessOrVolatility); var url = _virtualPathUtilityWrapper.ToAbsolute("~/Documents/Document/DownloadPublicDocument?enc=" + HttpUtility.UrlEncode(EncryptionHelper.Encrypt("documentLibraryId=" + controlSystemDto.DocumentLibraryId))); viewModel.ControlSystemId = controlSystemDto.Id; viewModel.WorkApproach = controlSystemDto.Description; viewModel.Url = url; } else { viewModel.WorkApproach = "None"; viewModel.Url = string.Empty; } viewModel.RiskAssessmentId = hazardousSubstanceRiskAssessment.Id; viewModel.Quantity = hazardousSubstanceRiskAssessment.Quantity; viewModel.MatterState = hazardousSubstanceRiskAssessment.MatterState; viewModel.DustinessOrVolatility = hazardousSubstanceRiskAssessment.DustinessOrVolatility; viewModel.HealthSurveillanceRequired = hazardousSubstanceRiskAssessment.HealthSurveillanceRequired; viewModel.CompanyId = _companyId.Value; viewModel.RiskAssessmentId = _hazardousSubstanceRiskAssessmentId.Value; return viewModel; }
public void Given_valid_data_is_entered_When_save_is_clicked_Then_correct_methods_are_called() { //Given long companyId = 1234L; long hazardousSubstanceRiskAssessmentId = 5678L; _hazardousSubstanceRiskAssessmentService .Setup(x => x.GetRiskAssessment(hazardousSubstanceRiskAssessmentId, companyId)) .Returns(new HazardousSubstanceRiskAssessmentDto()); var assessmentViewModel = new AssessmentViewModel(); _assessmentViewModelFactory .Setup(x => x.GetViewModel()) .Returns(assessmentViewModel); var target = CreateController(); //When target.Save(new AssessmentViewModel()); // Then _hazardousSubstanceRiskAssessmentService.Verify(x => x.UpdateHazardousSubstanceRiskAssessmentAssessmentDetails(It.IsAny<UpdateHazardousSubstanceRiskAssessmentAssessmentDetailsRequest>())); }