public void Setup() { _currentUserId = Guid.NewGuid(); _log = new Mock<IPeninsulaLog>(); _log.Setup(x => x.Add(It.IsAny<Object>())); _personalRiskAssessmentRepository = new Mock<IPersonalRiskAssessmentRepository>(); _userRepository = new Mock<IUserForAuditingRepository>(); _user = new UserForAuditing(); _userRepository .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>())) .Returns(_user); _employeeRepository = new Mock<IEmployeeRepository>(); _employeeRepository .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>())) .Returns(_employee); _riskAssessorRepository = new Mock<IRiskAssessorRepository>(); _riskAssessorRepository .Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())) .Returns(_riskAssessor); _request = new UpdatePersonalRiskAssessmentSummaryRequest() { CompanyId = 100, Reference = "Reference", Title = "Title", UserId = _currentUserId, Id = 200, AssessmentDate = DateTime.Now, RiskAssessorId = 266L, }; _checklistRepository = new Mock<IChecklistRepository>(); _riskAssessmentRepository = new Mock<IRiskAssessmentRepository>(); }
public void UpdateRiskAssessmentSummary(UpdatePersonalRiskAssessmentSummaryRequest request) { 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 riskAssessment = _personalRiskAssessmentRepository.GetByIdAndCompanyId(request.Id, request.CompanyId, request.UserId); if (!riskAssessment.CanUserAccess(request.UserId)) { throw new Exception("Invalid attempt to access Personal Risk Assessment with Id " + request.Id); } new UpdateRiskAssessmentValidator<PersonalRiskAssessment>(_riskAssessmentRepository).ValidateAndThrow(request); riskAssessment.UpdateSummary(request.Title, request.Reference, request.AssessmentDate, riskAssessor, request.Sensitive, site, user); _personalRiskAssessmentRepository.SaveOrUpdate(riskAssessment); }