public void AttachFireSafetyControlMeasuresToRiskAssessment(AttachFireSafetyControlMeasuresToRiskAssessmentRequest request) { _log.Add(request); var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId); var riskAssessment = _fireRiskAssessmentRepository.GetByIdAndCompanyId(request.RiskAssessmentId, request.CompanyId); var fireSafetyControlMeasures = _fireSafetyControlMeasureRepository.GetByIds(request.FireSafetyControlMeasureIds); riskAssessment.AttachFireSafetyControlMeasuresToRiskAssessment(fireSafetyControlMeasures, user); _fireRiskAssessmentRepository.SaveOrUpdate(riskAssessment); }
public void Given_valid_request_When_AttachPeopleAtRisk_is_called_Then_should_call_appropiate_methods() { //Given var riskAssessmentService = CreateRiskAssessmentService(); var attachPeopleAtRiskToRiskAssessmentRequest = new AttachFireSafetyControlMeasuresToRiskAssessmentRequest() { FireSafetyControlMeasureIds = new List<long> { 1, 2, 3 }, RiskAssessmentId = 2, CompanyId = 1, UserId = Guid.NewGuid() }; var mockRiskAssessment = new Mock<FireRiskAssessment>(); _riskAssessmentRepository .Setup(rr => rr.GetByIdAndCompanyId(attachPeopleAtRiskToRiskAssessmentRequest.RiskAssessmentId, attachPeopleAtRiskToRiskAssessmentRequest.CompanyId)) .Returns(mockRiskAssessment.Object); var fireSafetyControlMeasures = new List<FireSafetyControlMeasure>() { new FireSafetyControlMeasure(), new FireSafetyControlMeasure(), new FireSafetyControlMeasure() }; _fireSafetyControlMeasureRepository .Setup(x => x.GetByIds(attachPeopleAtRiskToRiskAssessmentRequest.FireSafetyControlMeasureIds)) .Returns(fireSafetyControlMeasures); _userRepository .Setup(x => x.GetByIdAndCompanyId(attachPeopleAtRiskToRiskAssessmentRequest.UserId, attachPeopleAtRiskToRiskAssessmentRequest.CompanyId)) .Returns(_user); //When riskAssessmentService.AttachFireSafetyControlMeasuresToRiskAssessment(attachPeopleAtRiskToRiskAssessmentRequest); //Then _riskAssessmentRepository.Verify(x => x.SaveOrUpdate(mockRiskAssessment.Object)); _userRepository.Verify(x => x.GetByIdAndCompanyId(attachPeopleAtRiskToRiskAssessmentRequest.UserId, attachPeopleAtRiskToRiskAssessmentRequest.CompanyId)); mockRiskAssessment.Verify(x => x.AttachFireSafetyControlMeasuresToRiskAssessment(fireSafetyControlMeasures, _user)); }