public void Given_valid_request_When_AttachNonEmployee_is_called_Then_should_call_appropiate_methods()
        {

            //Given
            var riskAssessmentService = CreateRiskAssessmentService();
            var attachNonEmployeeToRiskAssessmentRequest = new AttachNonEmployeeToRiskAssessmentRequest()
                                                               {
                                                                   NonEmployeeToAttachId = 1,
                                                                   RiskAssessmentId = 2
                                                               };

            var mockRiskAssessment = new Mock<GeneralRiskAssessment>();
            _riskAssessmentRepository
                    .Setup(rr => rr.GetByIdAndCompanyId(attachNonEmployeeToRiskAssessmentRequest.RiskAssessmentId, attachNonEmployeeToRiskAssessmentRequest.CompanyId))
                    .Returns(mockRiskAssessment.Object);

            var mockNonEmployee = new Mock<NonEmployee>();
            _nonEmployeeRepository
                    .Setup(x => x.GetByIdAndCompanyId(attachNonEmployeeToRiskAssessmentRequest.NonEmployeeToAttachId, attachNonEmployeeToRiskAssessmentRequest.CompanyId))
                    .Returns(mockNonEmployee.Object);

            SetupValidUser(attachNonEmployeeToRiskAssessmentRequest);

            //When
            riskAssessmentService.AttachNonEmployeeToRiskAssessment(attachNonEmployeeToRiskAssessmentRequest);

            //Then
            _riskAssessmentRepository.VerifyAll();
            _nonEmployeeRepository.VerifyAll(); 
            mockRiskAssessment.Verify(x => x.AttachNonEmployeeToRiskAssessment(mockNonEmployee.Object, _user));
        }
        public void AttachNonEmployeeToRiskAssessment(AttachNonEmployeeToRiskAssessmentRequest request)
        {
            _log.Add(request);

            try
            {
                var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId);
                var riskAssessment = _riskAssessmentRepository.GetByIdAndCompanyId(request.RiskAssessmentId, request.CompanyId);
                var nonEmployee = _nonEmployeeRepository.GetByIdAndCompanyId(request.NonEmployeeToAttachId, request.CompanyId);

                riskAssessment.AttachNonEmployeeToRiskAssessment(nonEmployee, user);
                _riskAssessmentRepository.SaveOrUpdate(riskAssessment);
            }
            catch (Exception ex)
            {
                _log.Add(ex);
                throw;
            }
        }
 private void SetupValidUser(AttachNonEmployeeToRiskAssessmentRequest attachNonEmployeeToRiskAssessmentRequest)
 {
     _userRepository.Setup(x => x.GetByIdAndCompanyId(attachNonEmployeeToRiskAssessmentRequest.UserId, attachNonEmployeeToRiskAssessmentRequest.CompanyId)).Returns(_user);
 }