示例#1
0
        public void Given_hazards_have_been_selected_then_these_hazards_do_not_appear_in_the_hazard_list_of_the_view_model()
        {
            //Given
            const long companyId = 100;
            const long riskAssessmentId = 50;
            var selectedHazard = new HazardDto() { Id = 349875, Name = "Eden" };

            _riskAssessmentService
               .Setup(x => x.GetRiskAssessmentWithHazards(It.IsAny<long>(), It.IsAny<long>(), It.IsAny<Guid>()))
               .Returns(new PersonalRiskAssessmentDto()
               {
                   Id = riskAssessmentId,
                   CreatedOn = DateTime.Now,
                   CompanyId = companyId,
                   Hazards = new List<HazardDto>() { selectedHazard }
                  
               });

            _companyDefaultService
                .Setup(x => x.GetAllMultiHazardRiskAssessmentHazardsForCompany(It.IsAny<long>(), It.IsAny<HazardTypeEnum>(), It.IsAny<long>()))
                .Returns(() => new List<CompanyDefaultDto>()
                {
                    new CompanyDefaultDto() {Id = selectedHazard.Id, Name = selectedHazard.Name}
                });


            var target = GetTarget();

            //When
            var result = (target.Index(companyId, riskAssessmentId) as ViewResult).Model as HazardsViewModel;

            //Then
            Assert.That(result.SelectedHazards.Count(), Is.EqualTo(1));
            Assert.That(result.Hazards.Count(), Is.EqualTo(0));
        }
 private static HazardViewModel CreateFrom(HazardDto hazard)
 {
     return new HazardViewModel
                {
                    Id = hazard.Id,
                    RiskAssessmentHazardId = hazard.RiskAssessmentHazardId,
                    Description = hazard.Description,
                    Title = hazard.Name,
                    ActionsRequired = FurtherControlMeasureTaskViewModel.CreateFrom(hazard.FurtherActionTasks),
                    ControlMeasures = RiskAssessmentHazardControlMeasureViewModel.CreateFrom(hazard.ControlMeasures),
                    AllowEditingOfTitle = hazard.RiskAssessmentId.HasValue
                };
 }