public SaveHazardousSubstanceRiskAssessmentRequest Build()
        {
            var saveRiskAssessmentRequest = new SaveHazardousSubstanceRiskAssessmentRequest
                                                {
                                                    Title = _title,
                                                    Reference = _reference,
                                                    AssessmentDate = _assessmentDate,
                                                    RiskAssessorId = _riskAssessorId,
                                                    WorkspaceExposureLimits = string.Empty,
                                                    HazardousSubstanceId = _hazardousSubstanceId,
                                                };

            return saveRiskAssessmentRequest;
        }
        public void UpdateRiskAssessmentSummary(SaveHazardousSubstanceRiskAssessmentRequest request)
        {
            var hazardousSubstanceAssessment = _hazardousSubstanceRiskAssessmentRepository.GetByIdAndCompanyId(request.Id, request.CompanyId);
            var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId);
            var riskAssessor = request.RiskAssessorId.HasValue ? _riskAssessorRepository.GetByIdAndCompanyId(request.RiskAssessorId.Value, request.CompanyId) : null;
            var site = request.SiteId.HasValue ? _siteRepository.GetByIdAndCompanyId(request.SiteId.Value, request.CompanyId) : null;
            var hazardousSubstance = _hazardousSubstancesRepository.GetByIdAndCompanyId(request.HazardousSubstanceId, request.CompanyId);
            new UpdateRiskAssessmentValidator<HazardousSubstanceRiskAssessment>(_riskAssessmentRepository).ValidateAndThrow(request);

            hazardousSubstanceAssessment.UpdateSummary(
                request.Title,
                request.Reference,
                request.AssessmentDate,
                riskAssessor,
                hazardousSubstance,
                site, user);

            _hazardousSubstanceRiskAssessmentRepository.SaveOrUpdate(hazardousSubstanceAssessment);

        }
        public long CreateRiskAssessment(SaveHazardousSubstanceRiskAssessmentRequest request)
        {
            _log.Add(request);

            var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId);
            var hazardousSubstance = _hazardousSubstancesRepository.GetByIdAndCompanyId(request.HazardousSubstanceId, request.CompanyId);

            new CreateRiskAssessmentValidator<HazardousSubstanceRiskAssessment>(_riskAssessmentRepository).ValidateAndThrow(request);

            var hazardousSubstanceAssessment = HazardousSubstanceRiskAssessment.Create(request.Title,
                                                       request.Reference,
                                                       request.CompanyId,
                                                       user,
                                                       hazardousSubstance);


            _hazardousSubstanceRiskAssessmentRepository.SaveOrUpdate(hazardousSubstanceAssessment);

            return hazardousSubstanceAssessment.Id;
        }
        public void UpdateRiskAssessmentDescription(SaveHazardousSubstanceRiskAssessmentRequest request)
        {
            _log.Add(request);

            var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId);
            var riskAssessment = _hazardousSubstanceRiskAssessmentRepository.GetByIdAndCompanyId(request.Id, request.CompanyId);
            riskAssessment.Update(
                user,
                request.IsInhalationRouteOfEntry,
                request.IsIngestionRouteOfEntry,
                request.IsAbsorptionRouteOfEntry,
                request.WorkspaceExposureLimits);

            _hazardousSubstanceRiskAssessmentRepository.SaveOrUpdate(riskAssessment);

        }
Exemplo n.º 5
0
        public void Given_valid_request_Then_selected_hazardous_substance_is_passed_to_service()
        {
            //Given
            var target = GetTarget();
            var passedSaveHazardousSubstanceRiskAssessmentRequest = new SaveHazardousSubstanceRiskAssessmentRequest();
            var createRiskAssessmentViewModel = new CreateRiskAssessmentViewModel()
            {
                CompanyId = 1234,
                Reference = "Ref",
                Title = "Title",
                NewHazardousSubstanceId = 5678
            };
            _hazardousSubstanceAssessmentService
                .Setup(r => r.CreateRiskAssessment(It.IsAny<SaveHazardousSubstanceRiskAssessmentRequest>()))
                .Callback<SaveHazardousSubstanceRiskAssessmentRequest>(y => passedSaveHazardousSubstanceRiskAssessmentRequest = y);

            //When
            target.Create(createRiskAssessmentViewModel);

            //Then
            Assert.That(passedSaveHazardousSubstanceRiskAssessmentRequest.HazardousSubstanceId, Is.EqualTo(createRiskAssessmentViewModel.NewHazardousSubstanceId));
        }
Exemplo n.º 6
0
        public void Given_Valid_Model_When_Save_Then_Send_Update_Request_To_Service()
        {
            // Given
            var editSummaryViewModel = new EditSummaryViewModel()
            {
                RiskAssessmentId = 100,
                CompanyId = 200,
                Title = "New Title",
                Reference = "New Reference",
                HazardousSubstanceId = 300,
                RiskAssessorId = 1234L,
                SiteId = 678L
            };
            var passedSaveRiskAssessmentRequest = new SaveHazardousSubstanceRiskAssessmentRequest();
            _riskAssessmentService
                .Setup(x => x.UpdateRiskAssessmentSummary(It.IsAny<SaveHazardousSubstanceRiskAssessmentRequest>()))
                .Callback<SaveHazardousSubstanceRiskAssessmentRequest>(y => passedSaveRiskAssessmentRequest = y);
            var target = GetTarget();

            // When
            var result = target.Save(editSummaryViewModel);
            var viewResult = result as ViewResult;

            // Then
            _riskAssessmentService.Verify(x => x.UpdateRiskAssessmentSummary(It.IsAny<SaveHazardousSubstanceRiskAssessmentRequest>()));
            Assert.That(passedSaveRiskAssessmentRequest.Id, Is.EqualTo(editSummaryViewModel.RiskAssessmentId));
            Assert.That(passedSaveRiskAssessmentRequest.CompanyId, Is.EqualTo(editSummaryViewModel.CompanyId));
            Assert.That(passedSaveRiskAssessmentRequest.Title, Is.EqualTo(editSummaryViewModel.Title));
            Assert.That(passedSaveRiskAssessmentRequest.Reference, Is.EqualTo(editSummaryViewModel.Reference));
            Assert.That(passedSaveRiskAssessmentRequest.UserId, Is.EqualTo(target.CurrentUser.UserId));
            Assert.That(passedSaveRiskAssessmentRequest.HazardousSubstanceId, Is.EqualTo(editSummaryViewModel.HazardousSubstanceId));
        }