public void given_valid_request_when_get_view_model__then_returns_correct_viewmodel()
        {
            //given
            long companyId = 1234L;
            long accidentRecordId = 1L;
            var accidentRecord = new AccidentRecordDto
                                     {
                                         Id = accidentRecordId,
                                         CompanyId = companyId,
                                         Title = "Tite",
                                         Reference = "Referene",
                                         Jurisdiction = new JurisdictionDto { Id=1L}
                                     };

            _accidentRecordService
            .Setup(x => x.GetByIdAndCompanyIdWithSite(It.IsAny<long>(), It.IsAny<long>()))
            .Returns(accidentRecord);

            var accidentSummaryViewModelFactory = GetTarget();
            accidentSummaryViewModelFactory = accidentSummaryViewModelFactory.WithCompanyId(companyId);

            //when

            var viewmodel = accidentSummaryViewModelFactory.GetViewModel();
            //then

            Assert.That(viewmodel.CompanyId,Is.EqualTo(companyId));
            Assert.That(viewmodel.AccidentRecordId, Is.EqualTo(accidentRecordId));
            Assert.That(viewmodel.Title, Is.EqualTo(accidentRecord.Title));
            Assert.That(viewmodel.Reference, Is.EqualTo(accidentRecord.Reference));
            Assert.That(viewmodel.JurisdictionId, Is.EqualTo(accidentRecord.Jurisdiction.Id));
            

        }
        public void SetUp()
        {
            _siteService = new Mock<ISiteService>();
            _emailSender = new Mock<IEmailSender>();
            _accidentRecordService = new Mock<IAccidentRecordService>();
            _businesSafeEmailLinkBaseUrlConfiguration = new Mock<IBusinessSafeEmailLinkBaseUrlConfiguration>();

            _businesSafeEmailLinkBaseUrlConfiguration.Setup(x => x.GetBaseUrl()).Returns("url");

            _message = new SendAccidentRecordEmail()
            {
                AccidentRecordId = 11L,
                CompanyId = 222L
            };

        
            var siteNotificationMembers = new List<AccidentRecordNotificationMember>()
            {
                new AccidentRecordNotificationEmployeeMember()
                {
                    Id = 1,
                    Employee = new Employee()
                    {
                        ContactDetails = new List<EmployeeContactDetail>()
                        {
                            new EmployeeContactDetail()
                            {
                                Email = "*****@*****.**"
                            }
                        }
                    }
                }
            };


            _siteService.Setup(x => x.GetAccidentRecordNotificationMembers(It.IsAny<long>()))
            .Returns(siteNotificationMembers);

            var accidentRecord1 = new AccidentRecordDto()
            {
                Id = 11L,
                DateAndTimeOfAccident = DateTime.Now,
                Location = "Location",
                PersonInvolved = PersonInvolvedEnum.Employee,
                SeverityOfInjury = SeverityOfInjuryEnum.Fatal,
                DescriptionHowAccidentHappened = "dd",
                InjuredPersonWasTakenToHospital = true,
                IsReportable = true,
                AccidentRecordInjuries = new List<AccidentRecordInjuryDto>() { new AccidentRecordInjuryDto() { Injury = new InjuryDto() { Description = "injury" } } },
                SiteWhereHappened = new SiteDto() { Id = 11, Name = "Site 1" }
            };

           
            _accidentRecordService.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
               .Returns(accidentRecord1);
            

        }
        public void SetUp()
        {
            _accidentRecordDto = new AccidentRecordDto() {Id = 123123, AccidentRecordDocuments = new List<AccidentRecordDocumentDto>()};
            _accidentRecordService = new Mock<IAccidentRecordService>();
            _siteService = new Mock<ISiteService>();

            _accidentRecordService.Setup(x => x.GetByIdAndCompanyIdWithAccidentRecordDocuments(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => _accidentRecordDto);
        }
        public void Setup()
        {
            _injuryService = new Mock<IInjuryService>();
            _bodyPartService = new Mock<IBodyPartService>();
            _accidentRecordService = new Mock<IAccidentRecordService>();

            _accidentRecord = new AccidentRecordDto();

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

            _accidentRecordService.Setup(x => x.GetByIdAndCompanyIdWithEverything(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => _accidentRecord);

            _bodyPartService.Setup(x => x.GetAll())
                .Returns(() => new BodyPartDto[] {new BodyPartDto() {Id = 123}});

            _injuryService.Setup(x => x.GetAll())
                .Returns(() => new InjuryDto[] { new InjuryDto() { Id = 123 } });
        }
        public void given_valid_accident_record_id_when_getviewmodel_then_result_contains_correct_accident_record()
        {
            //given
            var accidentRecordId = 1L;
            var accidentRecord = new AccidentRecordDto
                                     {
                                         Id = accidentRecordId,
                                         DateAndTimeOfAccident = DateTime.Now,
                                         SiteWhereHappened = new SiteDto { Id = 1L, Name = "Site" },
                                         OffSiteSpecifics = string.Empty,
                                         Location = "Location",
                                         AccidentType = new AccidentTypeDto { Id = 1L, Description = "Accident Type" },
                                         AccidentTypeOther = "Other accident type",
                                         CauseOfAccident = new CauseOfAccidentDto() { Id = 1L, Description = "Accident Cause" },
                                         CauseOfAccidentOther = "Other accident cause",
                                         EmployeeFirstAider = new EmployeeDto { Id = new Guid(), FullName = "Joe Blogs"},
                                         NonEmployeeFirstAiderSpecifics = "Another Person",
                                         DetailsOfFirstAidTreatment = "First Aid Details" 

                                     };

            _accidentRecordService.Setup(x => x.GetByIdAndCompanyIdWithSite(It.IsAny<long>(), It.IsAny<long>())).Returns(accidentRecord);

            var factory = GetTarget();

            //when
            var result = factory
                .WithCompanyId(1L)
                .GetViewModel();

            Assert.That(result.AccidentRecordId, Is.EqualTo(accidentRecordId));
            Assert.That(result.DateOfAccident, Is.EqualTo(accidentRecord.DateAndTimeOfAccident.Value.ToShortDateString()));
            Assert.That(result.TimeOfAccident, Is.EqualTo(accidentRecord.DateAndTimeOfAccident.Value.ToShortTimeString()));
            Assert.That(result.SiteId, Is.EqualTo(accidentRecord.SiteWhereHappened.Id));
            Assert.That(result.Site, Is.EqualTo(accidentRecord.SiteWhereHappened.Name));
            Assert.That(result.OffSiteName, Is.EqualTo(accidentRecord.OffSiteSpecifics));
            Assert.That(result.Location, Is.EqualTo(accidentRecord.Location));
            Assert.That(result.AccidentTypeId, Is.EqualTo(accidentRecord.AccidentType.Id));
            Assert.That(result.AccidentType, Is.EqualTo(accidentRecord.AccidentType.Description));
            Assert.That(result.OtherAccidentType, Is.EqualTo(accidentRecord.AccidentTypeOther));
            Assert.That(result.AccidentCauseId, Is.EqualTo(accidentRecord.CauseOfAccident.Id));
            Assert.That(result.AccidentCause, Is.EqualTo(accidentRecord.CauseOfAccident.Description));
            Assert.That(result.OtherAccidentCause, Is.EqualTo(accidentRecord.CauseOfAccidentOther));
            Assert.That(result.FirstAiderEmployeeId, Is.EqualTo(accidentRecord.EmployeeFirstAider.Id));
            Assert.That(result.FirstAiderEmployee, Is.EqualTo(accidentRecord.EmployeeFirstAider.FullName));
            Assert.That(result.NonEmployeeFirstAiderName, Is.EqualTo(accidentRecord.NonEmployeeFirstAiderSpecifics));
            Assert.That(result.DetailsOfFirstAid, Is.EqualTo(accidentRecord.DetailsOfFirstAidTreatment));
        }
        public void given_injured_person_is_other_then_injured_person_able_to_carry_out_work_section_is_not_visible()
        {
            //given
            _accidentRecord = new AccidentRecordDto
            {
                Id = 1L,
                PersonInvolved = PersonInvolvedEnum.Other
            };

            _accidentRecordService
                .Setup(x => x.GetByIdAndCompanyIdWithEverything(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(_accidentRecord);

            //when
            var target = GetTarget();
            var result = target.GetViewModel(1L, 1L);

            //then
            Assert.That(result.ShowInjuredPersonAbleToCarryOutWorkSection, Is.False);
        }
 private string GetSiteDisplay(AccidentRecordDto accidentRecord)
 {
     var result = string.Empty;
     if(accidentRecord.SiteWhereHappened != null)
     {
         result = accidentRecord.SiteWhereHappened.Name;
     }  
     else if(!string.IsNullOrEmpty(accidentRecord.OffSiteSpecifics))
     {
         result = "Off-site";
     }
     
     return result; 
 }
        public void given_email_notification_sent_getviewmodel_then_result_contains_correct_email_sent_status()
        {
            //given
            var company = 1L;
            
            var accidentRecord = new AccidentRecordDto()
            {
                EmailNotificationSent = true,
                Id = 1
            };

            _accidentRecordService.Setup(x => x.GetByIdAndCompanyIdWithAccidentRecordDocuments(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => accidentRecord);

            var factory = GetTarget();

            //when
            var result = factory
               .WithCompanyId(company)
                .GetViewModel();

            //then            
            Assert.That(result.EmailNotificationSent, Is.EqualTo(true));
        }
        public void When_notification_email_list_assert_multiple_emails_Sent()
        {
            var siteNotificationMembers = new List<AccidentRecordNotificationMember>()
            {
                new AccidentRecordNotificationEmployeeMember()
                {
                    Id = 1,
                    Employee = new Employee()
                    {
                        ContactDetails = new List<EmployeeContactDetail>()
                        {
                            new EmployeeContactDetail()
                            {
                                Email = "*****@*****.**"
                            }
                        }
                    }
                },

                new AccidentRecordNotificationEmployeeMember()
                {
                    Id = 2,
                    Employee = new Employee()
                    {
                        ContactDetails = new List<EmployeeContactDetail>()
                        {
                            new EmployeeContactDetail()
                            {
                                Email = "*****@*****.**"
                            }
                        }
                    }
                },

                new AccidentRecordNotificationNonEmployeeMember() 
                {
                    Id = 3,
                    NonEmployeeEmail = "*****@*****.**",
                    NonEmployeeName = "Norman Notemployedhere"
                }
            };

            _siteService.Setup(x => x.GetAccidentRecordNotificationMembers(It.IsAny<long>()))
                .Returns(siteNotificationMembers);

            //Given
            var accidentRecord1 = new AccidentRecordDto()
            {
                Id = 11L,
                DateAndTimeOfAccident = DateTime.Now,
                Location = "Location",
                PersonInvolved = PersonInvolvedEnum.Employee,
                SeverityOfInjury = SeverityOfInjuryEnum.Fatal,
                DescriptionHowAccidentHappened = "dd",
                InjuredPersonWasTakenToHospital = true,
                IsReportable = true,
                AccidentRecordInjuries = new List<AccidentRecordInjuryDto>() { new AccidentRecordInjuryDto() { Injury = new InjuryDto() { Description = "injury" } } },
                SiteWhereHappened = new SiteDto() { Id = 11, Name = "Site 1" }
            };

            _accidentRecordService.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
               .Returns(accidentRecord1);

             var handler = CreateTarget();

            // When
            handler.Handle(_message);

            // Then
            _emailSender.Verify(x => x.Send(It.IsAny<RazorEmailResult>()), Times.Exactly(3));
        }
        public void When_handle_but_notify_members_not_defined_Then_should_not_send_email()
        {
            //Given
            var accidentMembers =
               new List<AccidentRecordNotificationMember>()
                {
                    new AccidentRecordNotificationEmployeeMember()
                    {
                        Employee = new Employee()
                        {
                            Id = Guid.NewGuid(),
                            ContactDetails = new List<EmployeeContactDetail>() { new EmployeeContactDetail() { Email = null} }
                        }
                    }
                };

            _siteService.Setup(x => x.GetAccidentRecordNotificationMembers(It.IsAny<long>())).Returns(accidentMembers);

            var accidentRecord1 = new AccidentRecordDto()
            {
                Id = 11L,
                DateAndTimeOfAccident = DateTime.Now,
                Location = "Location",
                PersonInvolved = PersonInvolvedEnum.Employee,
                SeverityOfInjury = SeverityOfInjuryEnum.Fatal,
                DescriptionHowAccidentHappened = "dd",
                InjuredPersonWasTakenToHospital = true,
                IsReportable = true,
                AccidentRecordInjuries = new List<AccidentRecordInjuryDto>() { new AccidentRecordInjuryDto() { Injury = new InjuryDto() { Description = "injury" } } },
                SiteWhereHappened = new SiteDto() { Id = 11, Name = "Site 1" }
            };
            
            _accidentRecordService.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
               .Returns(accidentRecord1);

            var handler = CreateTarget();

            // When
            handler.Handle(_message);

            // Then
            _emailSender.Verify(x => x.Send(It.IsAny<RazorEmailResult>()), Times.Never());
        }