public void SetUp()
        {
            _bus = new Mock<IBus>();
            _accidentRecordRepository = new Mock<IAccidentRecordRepository>();
            _siteRepository = new Mock<ISiteRepository>();
            _userRepository = new Mock<IUserForAuditingRepository>();
            _user = new UserForAuditing { Id = new Guid() };
            _site = new Site();
            _accidentRecord = new AccidentRecord()
            {
                Id = _accidentRecordId,
                CompanyId = _companyId,
                SiteWhereHappened = _site,
                DoNotSendEmailNotification = false,
                EmailNotificationSent = false
            };


            _userRepository
                .Setup(curUserRepository => curUserRepository.GetByIdAndCompanyId(It.IsAny<Guid>(),It.IsAny<long>()))
                .Returns(_user);


            _accidentRecordRepository.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(_accidentRecord);

            var emp = new Employee();
            emp.ContactDetails = new List<EmployeeContactDetail>();
            emp.ContactDetails.Add(new EmployeeContactDetail() { Employee = emp, Email = "*****@*****.**" });

            _site.AddAccidentRecordNotificationMember(emp, _user);

            _siteRepository.Setup(x => x.GetById(It.IsAny<long>())).Returns(_site);
            
        }
        public void Setup()
        {
            _accidentRecordRepository = new Mock<IAccidentRecordRepository>();
            _userRepository = new Mock<IUserForAuditingRepository>();
            _log = new Mock<IPeninsulaLog>();

            _userRepository
                .Setup(curUserRepository => curUserRepository.GetByIdAndCompanyId(It.IsAny<Guid>(),It.IsAny<long>()))
                .Returns(() => _user);

            _userRepository
                .Setup(curUserRepository => curUserRepository.GetById(It.IsAny<Guid>()))
                .Returns(() => _user);

            _accidentRecordRepository.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => _accidentRecord);

            _accidentRecord = new AccidentRecord() { Id = 123123 };
          

            _request = new RemoveDocumentsFromAccidentRecordRequest()
                           {
                               AccidentRecordId = 123123,
                               CompanyId = 589,
                               DocumentLibraryIds = new List<long>() {56, 154, 234},
                               UserId = _user.Id
                           };
        }
        public void Given_accident_is_fatal_then_next_steps_available_equals_true()
        {
            var accidentRecord = new AccidentRecord();
            accidentRecord.SeverityOfInjury = SeverityOfInjuryEnum.Fatal;

            Assert.IsTrue(accidentRecord.NextStepsAvailable);
        }
Пример #4
0
        public void When_requesting_Create_values_are_set_correctly()
        {
            //Given
            var user = new UserForAuditing()
                           {
                               Id = Guid.NewGuid()
                           };


            var createAccidentRecordParams = new AccidentRecord()
                                                 {
                                                     CompanyId = 1L,
                                                     Title = "title",
                                                     Reference = "reference",
                                                     CreatedBy = user,
                                                     CreatedOn = _now,
                                                     Deleted = false
                                                 };

            DocumentType docType = new DocumentType() {Name = "Accident Record Doc", Id = 17};

            //When
            var result = AccidentRecordDocument.Create("description", "Filename.ext", 1L, docType, createAccidentRecordParams, user);

            //Then
            Assert.That(result.ClientId, Is.EqualTo(1L));
            Assert.That(result.DocumentLibraryId, Is.EqualTo(1L));
            Assert.That(result.Description, Is.EqualTo("description"));
            Assert.That(result.Title, Is.EqualTo("Filename.ext"));
            Assert.That(result.Filename, Is.EqualTo("Filename.ext"));
            Assert.That(result.CreatedBy, Is.EqualTo(createAccidentRecordParams.CreatedBy));
        }
        public void When_handle_Then_should_call_correct_methods()
        {
            // Given
            var handler = GetTarget();
            var message = new SendOffWorkReminderEmail
            {
                AccidentRecordId = 1L,
                RecipientEmail = "*****@*****.**",
                Title = "Test",
                AccidentRecordReference = "AR99",
                DateOfAccident = DateTime.Now
            };

            AccidentRecord accidentRecord = new AccidentRecord
            {
                EmployeeInjured = new Employee { Forename = "Injured", Surname = "Person" },
                DateAndTimeOfAccident = DateTime.Now,
                Jurisdiction = new Jurisdiction { Name = "GB" }
            };

            _accidentRecordRepository.Setup(x => x.GetById(It.IsAny<long>())).Returns(accidentRecord);

            // When
            handler.Handle(message);

            // Then
            _emailSender.Verify(x => x.Send(It.IsAny<RazorEmailResult>()));
        }
        private Employee GetCreator(AccidentRecord rec)
        {
            var employee =
                _getEmployeeQuery
                    .WithCompanyId(rec.CompanyId)
                    .WithEmployeeId(rec.CreatedBy.Employee.Id)
                    .Execute(_businessSafeSessionManager.Session);

            return employee;
        }
        public void Given_person_involved_NOT_answered_then_next_steps_available_equals_false()
        {
            var accidentRecord = new AccidentRecord();
            accidentRecord.SeverityOfInjury = SeverityOfInjuryEnum.Minor;
            accidentRecord.PersonInvolved = null;
            accidentRecord.InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.Yes;
            accidentRecord.InjuredPersonWasTakenToHospital = true;

            Assert.IsFalse(accidentRecord.NextStepsAvailable);
        }
        public void Given_employee_is_in_a_non_fatal_accident_taken_to_hospital_question_NOT_answered_and_able_continue_working_then_next_steps_available_equals_false()
        {
            var accidentRecord = new AccidentRecord();
            accidentRecord.SeverityOfInjury = SeverityOfInjuryEnum.Minor;
            accidentRecord.PersonInvolved = PersonInvolvedEnum.Employee;
            accidentRecord.InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.Yes;
            accidentRecord.InjuredPersonWasTakenToHospital = null;

            Assert.IsFalse(accidentRecord.NextStepsAvailable);
        }
        public void Given_employee_is_in_a_non_fatal_accident_taken_to_hospital_question_answered_not_able_to_continue_working_and_length_of_time_off_answered_then_next_steps_available_equals_true()
        {
            var accidentRecord = new AccidentRecord();
            accidentRecord.SeverityOfInjury = SeverityOfInjuryEnum.Minor;
            accidentRecord.PersonInvolved = PersonInvolvedEnum.Employee;
            accidentRecord.InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.No;
            accidentRecord.InjuredPersonWasTakenToHospital = true;
            accidentRecord.LengthOfTimeUnableToCarryOutWork = LengthOfTimeUnableToCarryOutWorkEnum.ThreeOrLessDays;

            Assert.IsTrue(accidentRecord.NextStepsAvailable);
        }
Пример #10
0
        public void Given_injury_is_in_list_when_AddInjury_then_Injury_is_not_duplicated()
        {
            //given
            var injury = new Injury() { Id = 3425, Description = "Anterior cruciate ligament" };

            var target = new AccidentRecord();

            target.AddInjury(injury, null);
            target.AddInjury(injury, null);

            Assert.AreEqual(1, target.AccidentRecordInjuries.Count);
        }
Пример #11
0
        public void Given_body_part_is_in_list_when_AddBodyPart_then_body_part_is_not_duplicated()
        {
            //given
            var bodyPart = new BodyPart() { Id = 3425, Description = "Finger nail" };

            var target = new AccidentRecord();

            target.AddBodyPartThatWasInjured(bodyPart, null);
            target.AddBodyPartThatWasInjured(bodyPart, null);

            Assert.AreEqual(1, target.AccidentRecordBodyParts.Count);
        }
Пример #12
0
        public void Given_injury_list_is_empty_when_AddInjury_then_Injury_appears_in_list()
        {
            //given
            var injury = new Injury() {Id = 3425, Description = "Anterior cruciate ligament"};

            var target = new AccidentRecord();

            target.AddInjury(injury,null);

            Assert.IsTrue(target.AccidentRecordInjuries.Any(x => x.Injury.Id == injury.Id));

            Assert.AreEqual(target, target.AccidentRecordInjuries.First(x => x.Injury.Id == injury.Id));
        }
Пример #13
0
        public void Given_body_part_list_is_empty_when_AddBodyPart_then_body_part_appears_in_list()
        {
            //given
            var bodyPart = new BodyPart() { Id = 3425, Description = "Toe nail" };

            var target = new AccidentRecord();

            target.AddBodyPartThatWasInjured(bodyPart, null);

            Assert.IsTrue(target.AccidentRecordBodyParts.Any(x => x.BodyPart.Id == bodyPart.Id));

            Assert.AreEqual(target, target.AccidentRecordBodyParts.First(x => x.BodyPart.Id == bodyPart.Id));
        }
 public static AccidentRecordDocument Create(string description, string filename, long documentLibraryId, DocumentType documentType, AccidentRecord accidentRecordRequest, UserForAuditing user)
 {
     return new AccidentRecordDocument
     {
         Description = description,
         ClientId = accidentRecordRequest.CompanyId,
         Title = filename,
         CreatedBy = user,
         CreatedOn = DateTime.Now,
         Filename = filename,
         DocumentLibraryId = documentLibraryId,
         AccidentRecord = accidentRecordRequest,
         Deleted = false,
         DocumentType = documentType
     };
 }
Пример #15
0
        public void Given_bodypart_is_not_in_list_when_RemoveInjury_then_Injury_list_remains_the_same()
        {
            //given
            var bodypart = new BodyPart() { Id = 3425, Description = "Anterior cruciate ligament" };
            var bodypart2 = new BodyPart() { Id = 123124, Description = "Hip flexior" };

            var target = new AccidentRecord();

            target.AddBodyPartThatWasInjured(bodypart, null);
            target.AddBodyPartThatWasInjured(bodypart2, null);

            //when
            target.RemoveBodyPartThatWasInjured(new BodyPart() { Id = 124314, Description = "Test" }, null);


            Assert.AreEqual(2, target.AccidentRecordBodyParts.Count);
        }
Пример #16
0
        public void Given_injury_is_in_list_when_RemoveInjury_then_Injury_removed_from_list()
        {
            //given
            var injury = new Injury() { Id = 3425, Description = "Anterior cruciate ligament", Deleted = false};
            var injury2 = new Injury() { Id = 123124, Description = "Hip flexior", Deleted = false };

            var target = new AccidentRecord();

            target.AddInjury(injury, null);
            target.AddInjury(injury2, null);

            //when
            target.RemoveInjury(injury2, null);

            Assert.AreEqual(1, target.AccidentRecordInjuries.Count);
            Assert.IsTrue(target.AccidentRecordInjuries.All(x => x.Injury.Id != injury2.Id));
        }
Пример #17
0
        public void Given_bodypart_is_in_list_when_RemoveInjury_then_Injury_removed_from_list()
        {
            //given
            var bodypart = new BodyPart() { Id = 3425, Description = "Anterior cruciate ligament", Deleted = false};
            var bodypart2 = new BodyPart() { Id = 123124, Description = "Hip flexior", Deleted = false };

            var target = new AccidentRecord();

            target.AddBodyPartThatWasInjured(bodypart, null);
            target.AddBodyPartThatWasInjured(bodypart2, null);

            //when
            target.RemoveBodyPartThatWasInjured(bodypart2, null);

            Assert.AreEqual(1, target.AccidentRecordBodyParts.Count);
            Assert.IsTrue(target.AccidentRecordBodyParts.All(x => x.BodyPart.Id != bodypart2.Id));
        }
Пример #18
0
        public void Given_injury_is_not_in_list_when_RemoveInjury_then_Injury_list_remains_the_same()
        {
            //given
            var injury = new Injury() { Id = 3425, Description = "Anterior cruciate ligament" };
            var injury2 = new Injury() { Id = 123124, Description = "Hip flexior" };

            var target = new AccidentRecord();

            target.AddInjury(injury, null);
            target.AddInjury(injury2, null);

            //when
            target.RemoveInjury(new Injury() {Id = 124314, Description = "Test"},null);


            Assert.AreEqual(2, target.AccidentRecordInjuries.Count);
        }
Пример #19
0
        public void Setup()
        {
            _accidentRecordRepository = new Mock<IAccidentRecordRepository>();
            _userRepository = new Mock<IUserForAuditingRepository>();
            _log = new Mock<IPeninsulaLog>();
         
            _userRepository
                .Setup(curUserRepository => curUserRepository.GetByIdAndCompanyId(It.IsAny<Guid>(),It.IsAny<long>()))
                .Returns(() => _user);

            _userRepository
                .Setup(curUserRepository => curUserRepository.GetById(It.IsAny<Guid>()))
                .Returns(() => _user);

            _accidentRecordRepository.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => _accidentRecord);

            _accidentRecord = new AccidentRecord() { Id = 123123 };
        }
        public void Setup()
        {
            _accidentRecord = new AccidentRecord() { Id = 123123, Jurisdiction = new Jurisdiction{ Name = JurisdictionNames.GB } };

            _accidentRecordRepository = new Mock<IAccidentRecordRepository>();
            _userRepository = new Mock<IUserForAuditingRepository>();
            _log = new Mock<IPeninsulaLog>();
            _injuryRepo = new Mock<IInjuryRepository>();
            _bodyRepo = new Mock<IBodyPartRepository>();

            _userRepository
                .Setup(curUserRepository => curUserRepository.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>()))
                .Returns(() => _user);

            _userRepository
                .Setup(curUserRepository => curUserRepository.GetById(It.IsAny<Guid>()))
                .Returns(() => _user);

            _accidentRecordRepository.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => _accidentRecord);

            _bodyRepo.Setup(x => x.GetById(It.IsAny<long>()))
                .Returns<long>(x => new BodyPart(){Id = x});

            _injuryRepo.Setup(x => x.GetById(It.IsAny<long>()))
                .Returns<long>(x => new Injury() { Id = x });

            _bodyRepo.Setup(x => x.GetByIds(It.IsAny<IList<long>>()))
                .Returns<IList<long>>(x =>  x.Select(id => new BodyPart() { Id = id }));

            _injuryRepo.Setup(x => x.GetByIds(It.IsAny<IList<long>>()))
                .Returns<IList<long>>(ids => ids.Select(id => new Injury() { Id = id }));

            _request = new UpdateInjuryDetailsRequest()
            {
                AccidentRecordId = 56456,
                CurrentUserId = _user.Id
            };
        }
        public void Setup()
        {
            _accidentRecordRepository = new Mock<IAccidentRecordRepository>();
            _userRepository = new Mock<IUserForAuditingRepository>();
            _log = new Mock<IPeninsulaLog>();
            _documentTypeRepository = new Mock<IDocumentTypeRepository>();

            _userRepository
                .Setup(curUserRepository => curUserRepository.GetByIdAndCompanyId(It.IsAny<Guid>(),It.IsAny<long>()))
                .Returns(() => _user);

            _userRepository
                .Setup(curUserRepository => curUserRepository.GetById(It.IsAny<Guid>()))
                .Returns(() => _user);

            _accidentRecordRepository.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => _accidentRecord);
            
            _accidentRecord = new AccidentRecord() { Id = 123123 };

            _documentTypeRepository.Setup(x => x.GetById(It.IsAny<long>()))
                .Returns(new DocumentType() {Id = 17, Name = "Accident Record"});

            _request = new AddDocumentToAccidentReportRequest()
                           {
                               AccidentRecordId = 56456,
                               CompanyId = _user.CompanyId,
                               DocumentLibraryIds =
                                   new List<DocumentLibraryFile>()
                                       {
                                           new DocumentLibraryFile()
                                               {Id = 123, Description = "descaf", Filename = "test.txt"}
                                       }
                                       ,
                               UserId = _user.Id

                           };
        }
        public void Given_employee_was_in_a_non_fatal_accident_and_its_unknown_whether_they_have_been_able_to_return_to_work_then_next_steps_available_equals_true()
        {
            var accidentRecord = new AccidentRecord();
            accidentRecord.SeverityOfInjury = SeverityOfInjuryEnum.Minor;
            accidentRecord.PersonInvolved = PersonInvolvedEnum.Employee;
            accidentRecord.InjuredPersonWasTakenToHospital = false;
            accidentRecord.InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.Unknown;

            Assert.True(accidentRecord.NextStepsAvailable);
        }
        public void Given_InjuredPersonAbleToCarryOutWork_NOT_answered_then_next_steps_available_equals_false()
        {
            var accidentRecord = new AccidentRecord();
            accidentRecord.SeverityOfInjury = SeverityOfInjuryEnum.Minor;
            accidentRecord.PersonInvolved = PersonInvolvedEnum.Employee;
            accidentRecord.InjuredPersonAbleToCarryOutWork = null;

            Assert.IsFalse(accidentRecord.NextStepsAvailable);
        }
        public void given_employee_escalation_task_then_call_nservice_bus_send_method_with_correct_parameters()
        {

            //given
            var email = "*****@*****.**";
            var employee = new Employee
            {
                Id = Guid.NewGuid(),
                ContactDetails = new List<EmployeeContactDetail>() {new EmployeeContactDetail{Id = 1L,Email = email} }
            };

            _employeeQuery.Setup(x => x.WithCompanyId(It.IsAny<long>())).Returns(_employeeQuery.Object);
            _employeeQuery.Setup(x => x.WithEmployeeId(It.IsAny<Guid>())).Returns(_employeeQuery.Object);
            _employeeQuery.Setup(x => x.Execute(It.IsAny<ISession>())).Returns(employee);

            var accidentRecord = new AccidentRecord
                                     {
                                         Id = 1L,
                                         CompanyId = 1234L,
                                         Jurisdiction = new Jurisdiction {Id = 1},
                                         InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.Unknown,
                                         Title = "Test accident record",
                                         Reference = "AR1",
                                         DateAndTimeOfAccident = DateTime.Now,
                                         CreatedBy =
                                             new UserForAuditing
                                                 {Employee = new EmployeeForAuditing {Id = Guid.NewGuid()}}
                                     };
            
            _query
                .Setup(x => x.Execute(_sessionManager.Object.Session))
                .Returns( new List<AccidentRecord>(){ accidentRecord } );

            EmployeeOffWorkEscalation task = CreateEscalationTask();

            //when
            task.Execute();

            //then
            _command.Verify(x => x.Execute(_sessionManager.Object.Session, It.IsAny<long>(), It.IsAny<DateTime>()), Times.Once());
            _bus.Verify(x => x.Send(It.Is<SendOffWorkReminderEmail>( y => 
                                                                         y.AccidentRecordId == accidentRecord.Id &&
                                                                         y.RecipientEmail == email &&
                                                                         y.Title == accidentRecord.Title &&
                                                                         y.AccidentRecordReference == accidentRecord.Reference &&
                                                                         y.DateOfAccident == accidentRecord.DateAndTimeOfAccident
                                        )));

            
        }
        public void given_accident_record_when_execute_then_employee_query_returns_employee()
        {
            //given
            EmployeeOffWorkEscalation task = CreateEscalationTask();
            var employee = new Employee
                               {
                                   Id = Guid.NewGuid()
                               };

            var accidentRecord = new AccidentRecord
            {
                Id = 1L,
                CompanyId = 1234L,
                Jurisdiction = new Jurisdiction { Id = 1 },
                InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.Unknown,
                Title = "Test accident record",
                Reference = "AR1",
                DateAndTimeOfAccident = DateTime.Now,
                CreatedBy = new UserForAuditing {Employee = new EmployeeForAuditing {Id = Guid.NewGuid()}}
            };

            _query
                .Setup(x => x.Execute(_sessionManager.Object.Session))
                .Returns(new List<AccidentRecord>(){accidentRecord});

            _employeeQuery.Setup(x => x.WithCompanyId(It.IsAny<long>())).Returns(_employeeQuery.Object);
            _employeeQuery.Setup(x => x.WithEmployeeId(It.IsAny<Guid>())).Returns(_employeeQuery.Object);
            _employeeQuery.Setup(x => x.Execute(It.IsAny<ISession>())).Returns(employee);

            _employeeQuery.Object
                .WithCompanyId(_companyId)
                .WithEmployeeId(employee.Id);

            //when
            task.Execute();

            //then
            _employeeQuery.Verify(x => x.WithCompanyId(_companyId), Times.AtLeastOnce());
            _employeeQuery.Verify(x => x.WithEmployeeId(employee.Id), Times.AtLeastOnce());
            _employeeQuery.Verify(x=>x.Execute(It.IsAny<ISession>()));

        }
        public void Given_a_vistor_was_in_an_accident_then_next_steps_available_equals_true()
        {
            var accidentRecord = new AccidentRecord();
            accidentRecord.SeverityOfInjury = SeverityOfInjuryEnum.Minor;
            accidentRecord.PersonInvolved = PersonInvolvedEnum.Visitor;
            accidentRecord.InjuredPersonWasTakenToHospital = false;

            Assert.True(accidentRecord.NextStepsAvailable);
        }
        public void Given_email_notification_is_required_when_SendAccidentRecordEmails_and_email_sent_then_email_notification_sent_status_is_set_to_true()
        {
            //Given
           SendAccidentRecordEmail emailCommand = null;

            _bus.Setup(x => x.Send(It.IsAny<object[]>()))
                .Callback<object[]>(y => emailCommand = y.First() as SendAccidentRecordEmail);

            //when
            var target = GetTarget();
            
            var updatedActionRecord = new AccidentRecord();
            _accidentRecordRepository.Setup(x => x.Save(It.IsAny<AccidentRecord>())).
                Callback<AccidentRecord>(y => updatedActionRecord = y);
                
            target.SendAccidentRecordEmails(_accidentRecordId, _companyId, _user.Id);

            // Then
            _bus.Verify(x => x.Send(It.IsAny<object[]>()));
            Assert.That(emailCommand.CompanyId, Is.EqualTo(_companyId));
            Assert.That(emailCommand.AccidentRecordId, Is.EqualTo(_accidentRecordId));
            Assert.That(updatedActionRecord.EmailNotificationSent, Is.EqualTo(true));
        }