public void When_GetViewModel_Then_should_call_the_correct_methods()
        {
            // Given
            var target = CreateTarget();

            var riskAssessment = new HazardousSubstanceRiskAssessmentDto()
                                {
                                    CompanyId = _companyId,
                                    Id = _riskAssessmentId,
                                    HazardousSubstance = new HazardousSubstanceDto { Name = "Test Hazardous Substance 1" }
                                };

            _riskAssessmentService
                .Setup(x => x.GetRiskAssessment(_riskAssessmentId, _companyId))
                .Returns(riskAssessment);

          
            var hazardousSubstances = new HazardousSubstanceDto[]{ new HazardousSubstanceDto(), };
            _hazardousSubstanceService
                .Setup(x => x.GetHazardousSubstancesForSearchTerm("", _companyId, 100))
                .Returns(hazardousSubstances);

            // When
            target
                .WithCompanyId(_companyId)
                .WithRiskAssessmentId(_riskAssessmentId)
                .GetViewModel();

            // Then
            _riskAssessmentService.VerifyAll();
        }
        public void When_GetViewModel_Then_should_return_the_correct_viewmodel()
        {
            // Given
            var target = CreateTarget();

            var riskAssessment = new HazardousSubstanceRiskAssessmentDto()
                                     {
                                         CompanyId = _companyId,
                                         Id = _riskAssessmentId,
                                         HazardousSubstance = new HazardousSubstanceDto { Name = "Test Hazardous Substance 1" }
                                     };

            _riskAssessmentService
                .Setup(x => x.GetRiskAssessment(_riskAssessmentId, _companyId))
                .Returns(riskAssessment);
            
           
            var hazardousSubstances = new HazardousSubstanceDto[] { new HazardousSubstanceDto(), };
            _hazardousSubstanceService
                .Setup(x => x.GetHazardousSubstancesForSearchTerm("", _companyId, 100))
                .Returns(hazardousSubstances);

            // When
            var result = target
                            .WithCompanyId(_companyId)
                            .WithRiskAssessmentId(_riskAssessmentId)
                            .GetViewModel();

            // Then
            Assert.That(result, Is.TypeOf<DescriptionViewModel>());
            Assert.That(result.CompanyId, Is.EqualTo(_companyId));
            Assert.That(result.RiskAssessmentId, Is.EqualTo(_riskAssessmentId));
        }
 public static DescriptionViewModel CreateFrom(HazardousSubstanceRiskAssessmentDto riskAssessment)
 {
     return new DescriptionViewModel()
                {
                    RiskAssessmentId = riskAssessment.Id,
                    CompanyId = riskAssessment.CompanyId,
                    IsInhalationRouteOfEntry = riskAssessment.IsInhalationRouteOfEntry,
                    IsIngestionRouteOfEntry = riskAssessment.IsIngestionRouteOfEntry,
                    IsAbsorptionRouteOfEntry = riskAssessment.IsAbsorptionRouteOfEntry,
                    WorkspaceExposureLimits = riskAssessment.WorkspaceExposureLimits,
                    NonEmployees = riskAssessment.NonEmployees,
                    Employees = riskAssessment.Employees,
                    HazardousSubstanceId = riskAssessment.HazardousSubstance != null ? riskAssessment.HazardousSubstance.Id : 0,
                };
 }
        public void When_get_view_model_is_called_Then_correct_methods_are_called()
        {
            //Given
            long companyId = 1234L;
            long hazardousSubstanceRiskAssessmentId = 5678L;

            var hazardousSubstanceRiskAssessmentDto = new HazardousSubstanceRiskAssessmentDto
                                                          {
                                                              Id = 99L,
                                                              MatterState = MatterState.Solid,
                                                              Quantity = Quantity.Medium,
                                                              DustinessOrVolatility = DustinessOrVolatility.Medium,
                                                              Group =
                                                                  new HazardousSubstanceGroupDto { Id = 1L, Code = "A" },
                                                              HazardousSubstance = new HazardousSubstanceDto(),
                                                              CreatedOn = DateTime.Now

                                                          };

            _hazardousSubstanceRiskAssessmentService
                .Setup(x => x.GetRiskAssessment(hazardousSubstanceRiskAssessmentId, companyId))
                .Returns(hazardousSubstanceRiskAssessmentDto);

            _controlSystemService
                .Setup(x => x.Calculate(
                    hazardousSubstanceRiskAssessmentDto.Group.Code,
                    hazardousSubstanceRiskAssessmentDto.MatterState,
                    hazardousSubstanceRiskAssessmentDto.Quantity,
                    hazardousSubstanceRiskAssessmentDto.DustinessOrVolatility))
                .Returns(new ControlSystemDto());

            _virtualPathUtilityWrapper
                .Setup(x => x.ToAbsolute(It.IsAny<string>()));

            // When
            _target
                .WithCompanyId(companyId)
                .WithRiskAssessmentId(hazardousSubstanceRiskAssessmentId)
                .GetViewModel();

            // Then
            _hazardousSubstanceRiskAssessmentService.Verify(x => x.GetRiskAssessment(hazardousSubstanceRiskAssessmentId, companyId));
            _controlSystemService.VerifyAll();
            _virtualPathUtilityWrapper.VerifyAll();
        }
 public void Setup()
 {
     _riskAssessmentService = new Mock<IHazardousSubstanceRiskAssessmentService>();
     _target = new ControlMeasuresViewModelFactory(_riskAssessmentService.Object);
     _riskAssessmentId = 300;
     _companyId = 500;
     _hazardousSubstanceRiskAssessmentDto = new HazardousSubstanceRiskAssessmentDto()
                                                {
                                                    HazardousSubstance = new HazardousSubstanceDto()
                                                                             {
                                                                                 Name = "JS"
                                                                             },
                                                    ControlMeasures = new List<HazardousSubstanceRiskAssessmentControlMeasureDto>()
                                                                               {
                                                                                   new HazardousSubstanceRiskAssessmentControlMeasureDto()
                                                                                       {
                                                                                           Id = 1,
                                                                                           ControlMeasure = "hey hey",
                                                                                           HazardousSubstanceRiskAssessmentId = _riskAssessmentId
                                                                                       }
                                                                               }
                                                };
 }
        public void When_get_view_model_is_called_Then_correct_view_model_is_returned()
        {
            //Given
            const long companyId = 1234L;
            const long hazardousSubstanceRiskAssessmentId = 5678L;

            var hazardousSubstanceRiskAssessmentDto = new HazardousSubstanceRiskAssessmentDto
            {
                Id = 99L,
                MatterState = MatterState.Solid,
                Quantity = Quantity.Medium,
                DustinessOrVolatility = DustinessOrVolatility.Medium,
                Group = new HazardousSubstanceGroupDto { Id = 1L, Code = "A" },
                HazardousSubstance = new HazardousSubstanceDto(),
                CreatedOn = DateTime.Now
            };

            _hazardousSubstanceRiskAssessmentService
                .Setup(x => x.GetRiskAssessment(hazardousSubstanceRiskAssessmentId, companyId))
                .Returns(hazardousSubstanceRiskAssessmentDto);

            var controlSystemDto = new ControlSystemDto
                                       {
                                           Id = 98L,
                                           Description = "Test Control System",
                                           DocumentLibraryId = 1020L
                                       };

            _controlSystemService
                .Setup(x => x.Calculate(
                    hazardousSubstanceRiskAssessmentDto.Group.Code,
                    hazardousSubstanceRiskAssessmentDto.MatterState,
                    hazardousSubstanceRiskAssessmentDto.Quantity,
                    hazardousSubstanceRiskAssessmentDto.DustinessOrVolatility))
                .Returns(controlSystemDto);

            var expectedUrlIn = "~/Documents/Document/DownloadPublicDocument?enc=" +
                              HttpUtility.UrlEncode(
                                  EncryptionHelper.Encrypt("documentLibraryId=" + controlSystemDto.DocumentLibraryId));

            var expectedUrlOut = "Test URL";

            _virtualPathUtilityWrapper
                .Setup(x => x.ToAbsolute(expectedUrlIn))
                .Returns(expectedUrlOut);

            // When
            var result = _target
                .WithCompanyId(companyId)
                .WithRiskAssessmentId(hazardousSubstanceRiskAssessmentId)
                .GetViewModel();

            // Then
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.MatterState, result.MatterState);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.Quantity, result.Quantity);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.DustinessOrVolatility, result.DustinessOrVolatility);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.Group.Code, result.HazardGroup);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.HealthSurveillanceRequired, result.HealthSurveillanceRequired);
            Assert.AreEqual(controlSystemDto.Description, result.WorkApproach);
            Assert.AreEqual(expectedUrlOut, result.Url);
        }
        public void When_get_view_model_is_called_for_hsra_hazardous_substance_without_risk_phrases_Then_correct_view_model_is_returned()
        {
            //Given
            const long companyId = 1234L;
            const long hazardousSubstanceRiskAssessmentId = 5678L;

            var hazardousSubstanceRiskAssessmentDto = new HazardousSubstanceRiskAssessmentDto
            {
                Id = 99L,
                MatterState = MatterState.Solid,
                Quantity = Quantity.Medium,
                DustinessOrVolatility = DustinessOrVolatility.Medium,
                Group = null,
                HazardousSubstance = new HazardousSubstanceDto(),
                CreatedOn = DateTime.Now
            };

            _hazardousSubstanceRiskAssessmentService
                .Setup(x => x.GetRiskAssessment(hazardousSubstanceRiskAssessmentId, companyId))
                .Returns(hazardousSubstanceRiskAssessmentDto);

            // When
            var result = _target
                .WithCompanyId(companyId)
                .WithRiskAssessmentId(hazardousSubstanceRiskAssessmentId)
                .GetViewModel();

            // Then
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.MatterState, result.MatterState);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.Quantity, result.Quantity);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.DustinessOrVolatility, result.DustinessOrVolatility);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.HealthSurveillanceRequired, result.HealthSurveillanceRequired);
            Assert.AreEqual("None", result.WorkApproach);
            Assert.AreEqual("", result.Url);
        }
        public HazardousSubstanceRiskAssessmentDto Map(HazardousSubstanceRiskAssessment riskAssessment)
        {
            var result = new HazardousSubstanceRiskAssessmentDto()
                             {
                                 CompanyId = riskAssessment.CompanyId,
                                 Id = riskAssessment.Id,
                                 Title = riskAssessment.Title,
                                 Reference = riskAssessment.Reference,
                                 CreatedOn = riskAssessment.CreatedOn,
                                 CreatedBy = riskAssessment.CreatedBy != null ? new AuditedUserDtoMapper().Map(riskAssessment.CreatedBy) : null,
                                 Status = riskAssessment.Status,
                                 AssessmentDate = riskAssessment.AssessmentDate,
                                 Deleted = riskAssessment.Deleted,
                                 IsInhalationRouteOfEntry = riskAssessment.IsInhalationRouteOfEntry.HasValue ? riskAssessment.IsInhalationRouteOfEntry.Value : false,
                                 IsIngestionRouteOfEntry = riskAssessment.IsIngestionRouteOfEntry.HasValue ? riskAssessment.IsIngestionRouteOfEntry.Value : false,
                                 IsAbsorptionRouteOfEntry = riskAssessment.IsAbsorptionRouteOfEntry.HasValue ? riskAssessment.IsAbsorptionRouteOfEntry.Value : false,
                                 WorkspaceExposureLimits = riskAssessment.WorkspaceExposureLimits,
                                 NonEmployees = GetNonEmployees(riskAssessment),
                                 Employees = GetEmployees(riskAssessment),
                                 Quantity = riskAssessment.Quantity,
                                 MatterState = riskAssessment.MatterState,
                                 DustinessOrVolatility = riskAssessment.DustinessOrVolatility,
                                 Group = riskAssessment.Group != null ? new HazardousSubstanceGroupDtoMapper().Map(riskAssessment.Group) : null,
                                 HealthSurveillanceRequired = riskAssessment.HealthSurveillanceRequired,
                                 NextReviewDate = riskAssessment.NextReviewDate,
                                 CompletionDueDate = riskAssessment.CompletionDueDate
                             };

            if (riskAssessment.HazardousSubstance != null)
            {
                result.HazardousSubstance = new HazardousSubstanceDtoMapper().Map(riskAssessment.HazardousSubstance);
            }

            if (riskAssessment.RiskAssessor != null)
            {
                result.RiskAssessor = new RiskAssessorDtoMapper().MapWithEmployee(riskAssessment.RiskAssessor);
            }

            if (riskAssessment.RiskAssessmentSite != null)
            {
                result.Site = new SiteStructureElementDtoMapper().Map(riskAssessment.RiskAssessmentSite);
            }

            if (riskAssessment.ControlMeasures != null && riskAssessment.ControlMeasures.Any())
            {
                result.ControlMeasures = new HazardousSubstanceRiskAssessmentControlMeasureDtoMapper().Map(riskAssessment.ControlMeasures);
            }

            if (riskAssessment.FurtherControlMeasureTasks != null && riskAssessment.FurtherControlMeasureTasks.Any())
            {
                result.FurtherControlMeasureTasks = new TaskDtoMapper().MapWithAssignedTo(riskAssessment.FurtherControlMeasureTasks);
            }

            result.Reviews = riskAssessment.Reviews != null ? riskAssessment.Reviews.Select(review => new RiskAssessmentReviewDto()
                                                                                                          {
                                                                                                              Comments = review.Comments
                                                                                                              ,
                                                                                                              CompletedBy = review.CompletedBy != null ? new EmployeeDtoMapper().Map(review.CompletedBy) : null
                                                                                                              ,
                                                                                                              CompletedDate = review.CompletedDate
                                                                                                              ,
                                                                                                              CompletionDueDate = review.CompletionDueDate,
                                                                                                              Id = review.Id,
                                                                                                              IsReviewOutstanding = review.IsReviewOutstanding
                                                                                                              ,
                                                                                                              ReviewAssignedTo = review.ReviewAssignedTo != null ? new EmployeeDtoMapper().Map(review.ReviewAssignedTo) : null
                                                                                                          }).ToList() : new List<RiskAssessmentReviewDto>();

            return result;
        }
Ejemplo n.º 9
0
        public void When_RiskAssessment_Not_In_Users_Allowed_Sites_Then_Throw_Exception()
        {
            // Given
            const long riskAssessmentId = 1234;

            var riskAssessment = new HazardousSubstanceRiskAssessmentDto()
            {
                Id = 1,
                Site = new SiteStructureElementDto(){Id = 2} 
            };

            _riskAssessmentService
                .Setup(x => x.GetRiskAssessment(riskAssessmentId, 1))
                .Returns(riskAssessment);

            var target = GetTarget();

            // When
            // Then
            Assert.Throws<SitePermissionsInvalidForUserException>(() => target.Index(riskAssessmentId));

            _riskAssessmentService.Verify(x => x.GetRiskAssessment(It.IsAny<long>(), It.IsAny<long>()));
        }
Ejemplo n.º 10
0
        public void When_valid_RiskAssessment_requested_Then_returned_filename_is_RiskAssessment_Sanitised_Title(string input, string output)
        {
            // Given
            var target = GetTarget();
            const string filename = "filename";
            const string mimeType = "mimetype";

            var riskAssessment = new HazardousSubstanceRiskAssessmentDto()
            {
                Id = 1234,
                Title = input,
                CreatedBy = new AuditedUserDto()
                            {
                                Id = target.CurrentUser.UserId
                            }
            };

            _riskAssessmentService
                .Setup(x => x.GetRiskAssessment(riskAssessment.Id, 1))
                .Returns(riskAssessment);

            _reportExecutionServiceFacade
                .Setup(x => x.GetReport(
                    It.IsAny<SqlReportHelper.ReportType>(),
                    new object[] { riskAssessment.Id },
                    It.IsAny<SqlReportHelper.ReportFormatType>()
                                ))
                .Returns(new DocumentViewModel()
                {
                    FileName = filename,
                    FileStream = new MemoryStream(),
                    MimeType = mimeType
                });

            // When
            var result = target.Index(riskAssessment.Id);

            // Then
            Assert.That(result.FileDownloadName, Is.EqualTo(output));
        }
Ejemplo n.º 11
0
        public void When_RiskAssessment_With_No_SiteId_requested_That_Was_Created_By_Another_User_Then_Throw_Exception()
        {
            // Given
            const long riskAssessmentId = 1234;

            var target = GetTarget();

            var riskAssessment = new HazardousSubstanceRiskAssessmentDto()
            {
                Id = 1,
                Site = null,
                Title = "My GRA",
                CreatedBy = new AuditedUserDto()
                {
                    Id = Guid.NewGuid()
                }
            };

            _riskAssessmentService
                .Setup(x => x.GetRiskAssessment(riskAssessmentId, 1))
                .Returns(riskAssessment);


            // When
            // Then
            Assert.Throws<SitePermissionsInvalidForUserException>(() => target.Index(riskAssessmentId));
        }
Ejemplo n.º 12
0
        public void When_RiskAssessment_With_No_SiteId_requested_That_The_User_Created_Then_return_FileResult()
        {
            // Given
            const long riskAssessmentId = 1234;

            var target = GetTarget();

            var riskAssessment = new HazardousSubstanceRiskAssessmentDto()
            {
                Id = 1,
                Site = null,
                Title = "My GRA",
                CreatedBy = new AuditedUserDto()
                {
                    Id = target.CurrentUser.UserId
                }
            };

            _riskAssessmentService
                .Setup(x => x.GetRiskAssessment(riskAssessmentId, 1))
                .Returns(riskAssessment);


            // When
            var result = target.Index(riskAssessmentId);

            // Then
            Assert.IsInstanceOf<FileResult>(result);
        }