Exemple #1
0
        public void give_valid_request_when_save_then_service_called_with_correct_parameters()
        {
            //given
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
                            {
                                AccidentRecordId = 1L,
                                SeverityOfInjury = SeverityOfInjuryEnum.Major,
                                SelectedInjuryIds = new long[]{2L},
                                SelectedBodyPartIds = new long[]{3L,4L},
                                InjuredPersonWasTakenToHospital = true,
                                InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.No,
                                LengthOfTimeUnableToCarryOutWork = LengthOfTimeUnableToCarryOutWorkEnum.MoreThanSevenDays
                            };

            UpdateInjuryDetailsRequest request = null;
            _accidentRecordService.Setup(x => x.UpdateInjuryDetails(It.IsAny<UpdateInjuryDetailsRequest>()))
                .Callback<UpdateInjuryDetailsRequest>(x => request = x);

            //when
            controller.Save(model);

            //then
            Assert.That(model.AccidentRecordId,Is.EqualTo(request.AccidentRecordId)); 
            Assert.That(TestControllerHelpers.CompanyIdAssigned,Is.EqualTo(request.CompanyId));
            Assert.That(TestControllerHelpers.UserIdAssigned,Is.EqualTo(request.CurrentUserId));
            Assert.That(model.SelectedInjuryIds,Is.EqualTo(request.Injuries));
            Assert.That(model.SelectedBodyPartIds, Is.EqualTo(request.BodyPartsInjured));
            Assert.That(model.InjuredPersonWasTakenToHospital, Is.EqualTo(request.WasTheInjuredPersonBeenTakenToHospital));
            Assert.That(model.InjuredPersonAbleToCarryOutWork,Is.EqualTo(request.HasTheInjuredPersonBeenAbleToCarryOutTheirNormalWorkActivity));
            Assert.That(model.LengthOfTimeUnableToCarryOutWork,Is.EqualTo(request.LengthOfTimeUnableToCarryOutWork));
            Assert.That(model.CustomInjuryDescription,Is.EqualTo(request.CustomInjuryDescription));
            Assert.That(model.CustomBodyPartyDescription, Is.EqualTo(request.CustomBodyPartDescription));

        }
        public ActionResult Save(InjuryDetailsViewModel model)
        {
            Validate(model);

            if (!ModelState.IsValid)
            {
                return InvalidIjnuryDetailsViewResult(model);
            }

            UpdateAccidentRecordInjuryDetailsOverview(model);
            TempData["Notice"] = "Injury details successfully updated";
   
            return RedirectToAction("Index", new { AccidentRecordId = model.AccidentRecordId , CompanyId = CurrentUser.CompanyId});

        }
Exemple #3
0
        public void Given_severity_is_fatal_and_injury_not_specified_when_save_then_model_state_returns_error()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                SeverityOfInjury = SeverityOfInjuryEnum.Fatal,
                SelectedInjuryIds = new long[0],
                SelectedBodyPartIds = new long[] { 3L, 4L },
                InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.Yes,
                InjuredPersonWasTakenToHospital = false
            };

            controller.Save(model);
            Assert.IsFalse(controller.ModelState.IsValid);
            Assert.True(controller.ModelState.Keys.Contains("Injury"), "Injury is mandatory when severity is fatal");
        }
        private void Validate(InjuryDetailsViewModel model)
        {
            var severityTypesThatRequireInjuryAndBodyParts = new [] {SeverityOfInjuryEnum.Fatal, SeverityOfInjuryEnum.Major, SeverityOfInjuryEnum.Minor};

            if (!model.SeverityOfInjury.HasValue)
            {
                ModelState.AddModelError("SeverityOfInjury", "Severity of injury is required.");
            }
            else
            {
                ValidateInjurySelection(model, severityTypesThatRequireInjuryAndBodyParts);
                ValidateBodyPartSelection(model, severityTypesThatRequireInjuryAndBodyParts);
                ValidateTakenToHospital(model);
                ValidateAbleToCarryOutWork(model);
                ValidateTimeOff(model);
            }
        }
 private void UpdateAccidentRecordInjuryDetailsOverview(InjuryDetailsViewModel model)
 {
     var request = new UpdateInjuryDetailsRequest()
                       {
                           AccidentRecordId = model.AccidentRecordId
                           , BodyPartsInjured = model.SelectedBodyPartIds == null ? new List<long>() : model.SelectedBodyPartIds.ToList()
                           , CompanyId = CurrentUser.CompanyId
                           , CurrentUserId = CurrentUser.UserId
                           , WasTheInjuredPersonBeenTakenToHospital = model.InjuredPersonWasTakenToHospital
                           , HasTheInjuredPersonBeenAbleToCarryOutTheirNormalWorkActivity = model.InjuredPersonAbleToCarryOutWork
                           , Injuries = model.SelectedInjuryIds == null ? new List<long>() : model.SelectedInjuryIds.ToList()
                           , SeverityOfInjury = model.SeverityOfInjury
                           , LengthOfTimeUnableToCarryOutWork = model.LengthOfTimeUnableToCarryOutWork
                           , CustomInjuryDescription = model.CustomInjuryDescription
                           , CustomBodyPartDescription = model.CustomBodyPartyDescription
                       };
     _accidentRecordService.UpdateInjuryDetails(request);
 }
        private ActionResult InvalidIjnuryDetailsViewResult(InjuryDetailsViewModel model)
        {
            var viewModel = _injuryDetailsViewModelFactory.GetViewModel(model.AccidentRecordId, CurrentUser.CompanyId);

            
            var selectedBodyParts = from selectedBodyPartIds in (model.SelectedBodyPartIds ?? new long[0])
                                    join bodyPart in viewModel.BodyParts on selectedBodyPartIds equals bodyPart.Id
                                    select bodyPart;

            var selectedInjuries = from selectedInjuryIds in (model.SelectedInjuryIds ?? new long[0])
                                   join injury in (viewModel.Injuries ?? new List<LookupDto>()) on selectedInjuryIds equals injury.Id
                                 select injury;


            viewModel.SelectedInjuries = selectedInjuries.ToList();
            viewModel.SelectedBodyParts = selectedBodyParts.ToList();
            return View("Index", viewModel);
        }
        private void ValidateInjurySelection(InjuryDetailsViewModel model, SeverityOfInjuryEnum[] severityTypesThatRequireInjuryAndBodyParts)
        {
            if (severityTypesThatRequireInjuryAndBodyParts.Contains(model.SeverityOfInjury.Value)
                && (model.SelectedInjuryIds == null || !model.SelectedInjuryIds.Any()))
            {
                ModelState.AddModelError("Injury", "Please select injuries suffered.");
            }

            if (model.SelectedInjuryIds != null
                        && model.SelectedInjuryIds.Contains(Injury.UNKOWN_INJURY)
                        && string.IsNullOrEmpty(model.CustomInjuryDescription))
            {
                ModelState.AddModelError("CustomInjuryDescription", "Please provide description of unknown injury.");
            }
        }
        private void ValidateBodyPartSelection(InjuryDetailsViewModel model, SeverityOfInjuryEnum[] severityTypesThatRequireInjuryAndBodyParts)
        {
            if (severityTypesThatRequireInjuryAndBodyParts.Contains(model.SeverityOfInjury.Value)
                && (model.SelectedBodyPartIds == null || !model.SelectedBodyPartIds.Any()))
            {
                ModelState.AddModelError("BodyPartsSection", "Please select body parts injured.");
            }

            if (model.SelectedBodyPartIds != null
                        && model.SelectedBodyPartIds.Contains(BodyPart.UNKOWN_BODY_PART)
                        && string.IsNullOrEmpty(model.CustomBodyPartyDescription))
            {
                ModelState.AddModelError("CustomBodyPartyDescription", "Please provide description of unknown location.");
            }
        }
 private void ValidateTakenToHospital(InjuryDetailsViewModel model)
 {
     if (model.SeverityOfInjury.Value != SeverityOfInjuryEnum.Fatal && !model.InjuredPersonWasTakenToHospital.HasValue)
     {
         ModelState.AddModelError("TakenToHospitalSection", "Please select an answer for the taken to hospital question.");
     }
 }
 private void ValidateAbleToCarryOutWork(InjuryDetailsViewModel model)
 {
     if (model.SeverityOfInjury.Value != SeverityOfInjuryEnum.Fatal && !model.InjuredPersonAbleToCarryOutWork.HasValue && model.ShowInjuredPersonAbleToCarryOutWorkSection)
     {
         ModelState.AddModelError("InjuredPersonAbleToCarryOutWork", "Please select an answer for the able to carry out normal work activity question.");
     }
 }
Exemple #11
0
        public void Given_severity_is_not_fatal_and_carry_out_work_question_answered_no_and_time_off_not_entered_then_model_state_returns_error()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                SeverityOfInjury = SeverityOfInjuryEnum.Minor,
                SelectedInjuryIds = new long[] { 3L, 4L },
                SelectedBodyPartIds = new long[] { 3L, 4L },
                InjuredPersonWasTakenToHospital = false,
                InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.No,
                LengthOfTimeUnableToCarryOutWork = null
            };

            controller.Save(model);
            Assert.IsFalse(controller.ModelState.IsValid);
            Assert.True(controller.ModelState.Keys.Contains("LengthOfTimeUnableToCarryOutWork"), "Time off is mandatory when injured person has not been able to carry out their normal work.");
        }
Exemple #12
0
        public void Given_severity_is_not_fatal_and_taken_to_hospital_question_not_answered_then_model_state_returns_error()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                SeverityOfInjury = SeverityOfInjuryEnum.Minor,
                SelectedInjuryIds = new long[] { 3L, 4L },
                SelectedBodyPartIds = new long[] { 3L, 4L },
                InjuredPersonWasTakenToHospital = null
            };

            controller.Save(model);
            Assert.IsFalse(controller.ModelState.IsValid);
            Assert.True(controller.ModelState.Keys.Contains("TakenToHospitalSection"), "Taken to hospital question is mandatory when severity is not fatal");
        }
Exemple #13
0
        public void Given_other_unknown_body_part_selected_but_description_not_specified_when_save_then_model_state_returns_error()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
                            {
                                AccidentRecordId = 1L,
                                SeverityOfInjury = SeverityOfInjuryEnum.Minor,
                                SelectedInjuryIds = new long[] {3L, 4L},
                                SelectedBodyPartIds = new long[] {BodyPart.UNKOWN_BODY_PART},
                                InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.Yes,
                                InjuredPersonWasTakenToHospital = false,
                                CustomBodyPartyDescription = null
                            };

            controller.Save(model);

            Assert.IsFalse(controller.ModelState.IsValid);
            Assert.True(controller.ModelState.Keys.Contains("CustomBodyPartyDescription"), "Custom body part description is mandatory when unknown body part is selected");
        }
Exemple #14
0
        public void Given_other_unknown_body_part_selected_and_description_entered_when_save_then_model_is_saved()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                SeverityOfInjury = SeverityOfInjuryEnum.Minor,
                SelectedInjuryIds = new long[] { 3L, 4L },
                SelectedBodyPartIds = new long[] {  BodyPart.UNKOWN_BODY_PART},
                InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.Yes,
                InjuredPersonWasTakenToHospital = false,
                CustomBodyPartyDescription = "Patella"
            };

            controller.Save(model);

            Assert.IsTrue(controller.ModelState.IsValid);
            _accidentRecordService.Verify(x => x.UpdateInjuryDetails(It.IsAny<UpdateInjuryDetailsRequest>()), Times.Once());
        }
Exemple #15
0
        public void Given_other_unknown_injury_selected_but_description_not_specified_when_save_then_model_state_returns_error()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                SeverityOfInjury = SeverityOfInjuryEnum.Minor,
                SelectedInjuryIds = new long[] { Injury.UNKOWN_INJURY },
                SelectedBodyPartIds = new long[] { 3L, 4L },
            };

            controller.Save(model);

            Assert.IsFalse(controller.ModelState.IsValid);
            Assert.True(controller.ModelState.Keys.Contains("CustomInjuryDescription"), "Custom Injury Description is mandatory when unknown injury is selected");
        }
Exemple #16
0
        public void Given_severity_not_entered_then_model_state_returns_error()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                SeverityOfInjury = null,
                SelectedInjuryIds = new long[] { 3L, 4L },
                SelectedBodyPartIds = new long[] { 3L, 4L },
                InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.No,
                LengthOfTimeUnableToCarryOutWork = null
            };

            controller.Save(model);

            Assert.True(controller.ModelState.Keys.Contains("SeverityOfInjury"), "Severity of injury is mandatory.");
        }
Exemple #17
0
        public void Given_severity_is_fatal_and_carry_out_work_question_answered_no_and_time_off_not_entered_then_model_is_saved()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                SeverityOfInjury = SeverityOfInjuryEnum.Fatal,
                SelectedInjuryIds = new long[] { 3L, 4L },
                SelectedBodyPartIds = new long[] { 3L, 4L },
                InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.No,
                LengthOfTimeUnableToCarryOutWork = null
            };

            controller.Save(model);

            Assert.IsTrue(controller.ModelState.IsValid);
            _accidentRecordService.Verify(x => x.UpdateInjuryDetails(It.IsAny<UpdateInjuryDetailsRequest>()), Times.Once());
        }
        public JsonResult SaveAndNext(InjuryDetailsViewModel model)
        {
            Validate(model);

            if (ModelState.IsValid)
            {
                UpdateAccidentRecordInjuryDetailsOverview(model);
                return Json(new {Success = true});
            }
            else
            {
                return ModelStateErrorsAsJson();
            }
        }
Exemple #19
0
        public void Given_severity_is_fatal_and_injury_specified_when_save_then_model_state_does_not_return_error()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                SeverityOfInjury = SeverityOfInjuryEnum.Fatal,
                SelectedInjuryIds = new long[] { 1L, 2L },
                SelectedBodyPartIds = new long[] { 3L, 4L },
                InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.Yes,
                InjuredPersonWasTakenToHospital = false
            };

            controller.Save(model);

            Assert.IsTrue(controller.ModelState.IsValid);
            _accidentRecordService.Verify(x=>x.UpdateInjuryDetails(It.IsAny<UpdateInjuryDetailsRequest>()),Times.Once());
        }
Exemple #20
0
        public void Given_severity_is_not_fatal_and_carry_out_work_question_not_answered_then_model_state_returns_error()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                ShowInjuredPersonAbleToCarryOutWorkSection = true,
                SeverityOfInjury = SeverityOfInjuryEnum.Minor,
                SelectedInjuryIds = new long[] { 3L, 4L },
                SelectedBodyPartIds = new long[] { 3L, 4L },
                InjuredPersonWasTakenToHospital = false,
                InjuredPersonAbleToCarryOutWork = null
            };

            controller.Save(model);
            Assert.IsFalse(controller.ModelState.IsValid);
            Assert.True(controller.ModelState.Keys.Contains("InjuredPersonAbleToCarryOutWork"), "Injured person able to carry out work is mandatory when severity is not fatal");
        }
 private void ValidateTimeOff(InjuryDetailsViewModel model)
 {
     if (model.SeverityOfInjury.Value != SeverityOfInjuryEnum.Fatal
         && model.InjuredPersonAbleToCarryOutWork.HasValue
         && model.InjuredPersonAbleToCarryOutWork.Value == YesNoUnknownEnum.No
         && !model.LengthOfTimeUnableToCarryOutWork.HasValue)
     {
         ModelState.AddModelError("LengthOfTimeUnableToCarryOutWork", "Please select the length of time the injured person has been unable to carry out their normal work activity.");
     }
 }
Exemple #22
0
        public void Given_severity_is_Minor_and_bodypart_specified_when_save_then_model_is_saved()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                SeverityOfInjury = SeverityOfInjuryEnum.Minor,
                SelectedInjuryIds = new long[] { 1L, 2L },
                SelectedBodyPartIds = new long[] { 3L, 4L },
                InjuredPersonAbleToCarryOutWork = YesNoUnknownEnum.Yes,
                InjuredPersonWasTakenToHospital = false
            };

            controller.Save(model);

            _accidentRecordService.Verify(x => x.UpdateInjuryDetails(It.IsAny<UpdateInjuryDetailsRequest>()), Times.Once());
        }
Exemple #23
0
        public void Given_severity_is_not_fatal_back_to_work_section_is_not_visible_then_model_state_is_valid()
        {
            var controller = GetTarget();
            var model = new InjuryDetailsViewModel
            {
                AccidentRecordId = 1L,
                ShowInjuredPersonAbleToCarryOutWorkSection = false,
                SeverityOfInjury = SeverityOfInjuryEnum.Minor,
                SelectedInjuryIds = new long[] { 3L, 4L },
                SelectedBodyPartIds = new long[] { 3L, 4L },
                InjuredPersonWasTakenToHospital = false,
                InjuredPersonAbleToCarryOutWork = null
            };

            controller.Save(model);
            Assert.That(controller.ModelState.IsValid,Is.True);
        }