public void Given_valid_request_When_RemoveControlMeasure_Then_should_call_correct_methods()
        {

            //Given
            var request = new RemoveControlMeasureRequest()
                              {
                                  ControlMeasureId = 500,
                                  CompanyId = 200,
                                  UserId = Guid.NewGuid(),
                                  RiskAssessmentId = 250
                              };

            var mockRiskAssessment = new Mock<BusinessSafe.Domain.Entities.HazardousSubstanceRiskAssessment>();
            mockRiskAssessment
                .Setup(x => x.RemoveControlMeasure(request.ControlMeasureId, _user));

            _repository
                .Setup(x => x.GetByIdAndCompanyId(request.RiskAssessmentId, request.CompanyId)).
                Returns(mockRiskAssessment.Object);

            _repository
                .Setup(x => x.SaveOrUpdate(mockRiskAssessment.Object));

            _userRepository
                .Setup(x => x.GetByIdAndCompanyId(request.UserId, request.CompanyId))
                .Returns(_user);

            //When
            _target.RemoveControlMeasureFromRiskAssessment(request);

            //Then
            _repository.VerifyAll();
            _userRepository.VerifyAll();
            mockRiskAssessment.Verify();
        }
        public void Given_valid_request_When_remove_control_measure_from_risk_assessment_Then_should_call_correct_methods()
        {
            //Given
            var target = CreateRiskAssessmentHazardService();
            var request = new RemoveControlMeasureRequest()
                              {
                                  CompanyId = 1000,
                                  RiskAssessmentId = 2000,
                                  UserId = Guid.NewGuid(),
                                  ControlMeasureId = 1,
                                  RiskAssessmentHazardId = 2
                              };

            var user = new UserForAuditing();
            _userRepo
                .Setup(x => x.GetByIdAndCompanyId(request.UserId, request.CompanyId))
                .Returns(user);

            var stubRiskAssessment = new Mock<GeneralRiskAssessment>();
            _riskAssessmentRepo
                .Setup(x => x.GetByIdAndCompanyId(request.RiskAssessmentId, request.CompanyId))
                .Returns(stubRiskAssessment.Object);

            var mockHazard = new Mock<MultiHazardRiskAssessmentHazard>();
            stubRiskAssessment
                .Setup(x => x.FindRiskAssessmentHazard(request.RiskAssessmentHazardId))
                .Returns(mockHazard.Object);


            //When
            target.RemoveControlMeasureFromRiskAssessmentHazard(request);

            //Then
            _userRepo.VerifyAll();
            _riskAssessmentRepo.VerifyAll();
            mockHazard.Verify(x => x.RemoveControlMeasure(request.ControlMeasureId, user));
        }
        public void RemoveControlMeasureFromRiskAssessmentHazard(RemoveControlMeasureRequest request)
        {
            _log.Add(request);

            try
            {
                var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId);
                var riskAssessment = _riskAssessmentRepository.GetByIdAndCompanyId(request.RiskAssessmentId, request.CompanyId);
                var riskAssessmentHazard = riskAssessment.FindRiskAssessmentHazard(request.RiskAssessmentHazardId);

                riskAssessmentHazard.RemoveControlMeasure(request.ControlMeasureId, user);
                _riskAssessmentRepository.SaveOrUpdate(riskAssessment);
            }
            catch (Exception ex)
            {
                _log.Add(ex);
                throw;
            }
            

        }
        public void RemoveControlMeasureFromRiskAssessment(RemoveControlMeasureRequest request)
        {
            _log.Add(request);

            var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId);
            var riskAssessment = _hazardousSubstanceRiskAssessmentRepository.GetByIdAndCompanyId(request.RiskAssessmentId, request.CompanyId);

            riskAssessment.RemoveControlMeasure(request.ControlMeasureId, user);

            _hazardousSubstanceRiskAssessmentRepository.SaveOrUpdate(riskAssessment);

        }