public long CreateRiskAssessment(CreateRiskAssessmentRequest request)
        {
            _log.Add(request);

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

            Site site = null;
            if (request.SiteId != null)
            {
                site = _siteRepository.GetByIdAndCompanyId(request.SiteId.Value, request.CompanyId);
            }

            RiskAssessor riskAssessor = null;
            if (request.RiskAssessorId.HasValue)
            {
                riskAssessor = _riskAssessorRepository.GetByIdAndCompanyId(request.RiskAssessorId.Value, request.CompanyId);
            }

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

            var riskAssessment = GeneralRiskAssessment.Create(request.Title,
                                                       request.Reference,
                                                       request.CompanyId,
                                                       user,
                                                       request.Location,
                                                       request.TaskProcessDescription,
                                                       site
                                                       ,request.AssessmentDate,riskAssessor);

            _generalRiskAssessmentRepository.SaveOrUpdate(riskAssessment);

            return riskAssessment.Id;

        }
        public CreateRiskAssessmentRequest Build()
        {
            var saveRiskAssessmentRequest = new CreateRiskAssessmentRequest
            {
                Title = _title,
                Reference = _reference,
            };

            return saveRiskAssessmentRequest;
        }
        public void When_CreateRiskAssessment_Then_Log_Request()
        {
            // Given
            var target = GetTarget();
            var request = new CreateRiskAssessmentRequest()
            {
                Title = "Title",
                Reference = "Reference"
            };

            // When
            target.CreateRiskAssessment(request);

            // Then
            _log.Verify(x => x.Add(request), Times.Once());
        }
        public void When_CreateRiskAssessment_Then_Retrieve_Requesting_User_From_Repo()
        {
            // Given
            var target = GetTarget();
            var request = new CreateRiskAssessmentRequest()
            {
                UserId = Guid.NewGuid(),
                CompanyId = 100,
                Title = "title",
                Reference = "reference"
            };

            // When
            target.CreateRiskAssessment(request);

            // Then
            _userRepo.Verify(x => x.GetByIdAndCompanyId(request.UserId, request.CompanyId), Times.Once());
        }
        private static long CreateRiskAssessment()
        {
            
            var userId = GetRandomUserId();

            var riskAssessmentService = ObjectFactory.GetInstance<IGeneralRiskAssessmentService>();

            string titleReference = DateTime.Now.Ticks.ToString() + new Random().Next(2500) + new Random().Next(3000);
            var request = new CreateRiskAssessmentRequest()
                              {
                                  CompanyId = companyId,
                                  Reference = titleReference,
                                  Title = titleReference,
                                  UserId = userId
                              };


            var result = riskAssessmentService.CreateRiskAssessment(request);
            ObjectFactory.GetInstance<IBusinessSafeSessionManager>().Session.Flush();
            return result;
        }
        public void Given_a_reference_exists_when_IsSatisfiedBy_then_return_false()
        {
            //given
            _riskAssessmentRepository.Setup(x =>
                x.DoesAssessmentExistWithTheSameReference < GeneralRiskAssessment>(It.IsAny<long>()
                                                         , It.IsAny<string>()
                                                         , It.IsAny<long?>())).Returns(true);
            var target =  GetTarget();
            var riskAss = new CreateRiskAssessmentRequest()
                              {
                                  Title = "Title this is",
                                  Reference = "reference here",
                                  CompanyId = 45698
                              };  

            //when
            var result = target.IsSatisfiedBy(riskAss);

            //then
            Assert.IsFalse(result);

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

            var user = _auditedUserRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId);
            var checklist = _checklistRepository.GetFireRiskAssessmentChecklist();

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

            var riskAssessment = FireRiskAssessment.Create(request.Title,
                                                           request.Reference,
                                                           request.CompanyId,
                                                           checklist,
                                                           user);


            
            _fireRiskAssessmentRepository.Save(riskAssessment);

            return riskAssessment.Id;

        }
        public void Given_any_scenario_when_IsSatisfiedBy_then_repository_access_is_correct()
        {
            //given
            var target = GetTarget();
            var riskAss = new CreateRiskAssessmentRequest()
            {
                Title = "Title this is",
                Reference = "reference here",
                CompanyId = 45698
            };  
            

            //when
            target.IsSatisfiedBy(riskAss);

            //then
            _riskAssessmentRepository.Verify(x =>
                                             x.DoesAssessmentExistWithTheSameReference < GeneralRiskAssessment>(riskAss.CompanyId
                                                                                       , riskAss.Reference
                                                                                       , 0));


        }
        public long CreateRiskAssessmentWithChecklist(CreateRiskAssessmentRequest request, Guid employeeChecklistId)
        {
            var checklist = _employeeChecklistRepository.GetById(employeeChecklistId);
            if (checklist == null)
                throw new EmployeeChecklistNotFoundException(employeeChecklistId);

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

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

            var riskAssessment = PersonalRiskAssessment.Create(request.Title,
                                                       request.Reference,
                                                       request.CompanyId,
                                                       user);

            riskAssessment.AddChecklist(checklist, user);
            
            _personalRiskAssessmentRepository.Save(riskAssessment);

            return riskAssessment.Id;
        }
Ejemplo n.º 10
0
        public void When_CreateRiskAssessment_Then_Pass_Populated_RiskAssessment_To_Repo_To_Save()
        {
            // Given
            var request = new CreateRiskAssessmentRequest()
            {
                UserId = Guid.NewGuid(),
                Title = "Title",
                Reference = "Reference",
                CompanyId = 100
            };

            _userRepo
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>()))
                .Returns(new UserForAuditing()
                {
                    Id = request.UserId
                });

            var passedFireRiskAssessment = new FireRiskAssessment();

            _fireRiskAssessmentRepo
                .Setup(x => x.Save(It.IsAny<FireRiskAssessment>()))
                .Callback<FireRiskAssessment>(y => passedFireRiskAssessment = y);

            var target = GetTarget();

            // When
            target.CreateRiskAssessment(request);

            // Then
            _fireRiskAssessmentRepo.Verify(x => x.Save(It.IsAny<FireRiskAssessment>()));
            Assert.That(passedFireRiskAssessment.Title, Is.EqualTo(request.Title));
            Assert.That(passedFireRiskAssessment.Reference, Is.EqualTo(request.Reference));
            Assert.That(passedFireRiskAssessment.CompanyId, Is.EqualTo(request.CompanyId));
            Assert.That(passedFireRiskAssessment.CreatedBy.Id, Is.EqualTo(request.UserId));
        }
Ejemplo n.º 11
0
        public void When_CreateRiskAssessment_Then_Check_If_RiskAssessment_title_Has_Already_Been_Used()
        {
            // Given
            var request = new CreateRiskAssessmentRequest()
            {
                UserId = Guid.NewGuid(),
                Title = "Title",
                Reference = "Reference",
                CompanyId = 100
            };

            var target = GetTarget();

            // When
            target.CreateRiskAssessment(request);

            // Then
            _riskAssessmentRepository.Verify(x => x.DoesAssessmentExistWithTheSameTitle<FireRiskAssessment>  (It.IsAny<long>(), "Title", 0),Times.Once());
            _riskAssessmentRepository.Verify(x => x.DoesAssessmentExistWithTheSameTitle<FireRiskAssessment>(100, It.IsAny<string>(), 0), Times.Once());
        }
Ejemplo n.º 12
0
        public void When_CreateRiskAssessment_and_reference_is_empty_Then_do_not_Check_If_RiskAssessment_Reference_Has_Already_Been_Used()
        {
            // Given
            var request = new CreateRiskAssessmentRequest()
            {
                UserId = Guid.NewGuid(),
                Title = "Title",
                Reference = "",
                CompanyId = 100
            };

            var target = GetTarget();

            // When
            target.CreateRiskAssessment(request);

            // Then
            _riskAssessmentRepository
                .Verify(x => x.DoesAssessmentExistWithTheSameReference<FireRiskAssessment>(It.IsAny<long>(), It.IsAny<string>(), It.IsAny<long?>()), Times.Never());
        }
Ejemplo n.º 13
0
        public void When_CreateRiskAssessment_Then_New_RiskAssessment_Id_Is_Returned()
        {
            // Given
            var request = new CreateRiskAssessmentRequest()
            {
                UserId = Guid.NewGuid(),
                Title = "Title",
                Reference = "Reference",
                CompanyId = 100
            };

            var passedFireRiskAssessment = new FireRiskAssessment();

            _fireRiskAssessmentRepo
                .Setup(x => x.Save(It.IsAny<FireRiskAssessment>()))
                .Callback<FireRiskAssessment>(y => passedFireRiskAssessment = y);

            var target = GetTarget();

            // When
            var result = target.CreateRiskAssessment(request);

            // Then
            Assert.That(result, Is.EqualTo(passedFireRiskAssessment.Id));
        }
        public long CreateRiskAssessmentFromChecklist(Guid employeeChecklistId, Guid currentUserId)
        {
            var employeeChecklist = _employeeChecklistRepository.GetById(employeeChecklistId);
            var user = _userForAuditingRepository.GetByIdAndCompanyId(currentUserId, employeeChecklist.Employee.CompanyId);
            var createPRARequest = new CreateRiskAssessmentRequest()
                                       {
                                           CompanyId = employeeChecklist.Employee.CompanyId,
                                           Title = string.Format("{0}_{1}{2}", employeeChecklist.Employee.FullName, employeeChecklist.Checklist.Title, employeeChecklist.FriendlyReference),
                                           Reference = employeeChecklist.FriendlyReference,
                                           UserId = user.Id
                                       };
            new CreateRiskAssessmentValidator<PersonalRiskAssessment>(_riskAssessmentRepository).ValidateAndThrow(createPRARequest);

            var riskAssessment = PersonalRiskAssessment.Create(createPRARequest.Title,
                                                               createPRARequest.Reference,
                                                               createPRARequest.CompanyId,
                                                               user);

            riskAssessment.AddChecklist(employeeChecklist, user);

            _personalRiskAssessmentRepository.Save(riskAssessment);

            return riskAssessment.Id;

        }