public void SetUp()
 {
     _clientId = 3423L;
     _currentUser = new UserForAuditing { Id = Guid.NewGuid() };
     _hazardousSubstance = new HazardousSubstance {Id = 3764L};
     _hazardousSubstanceRiskAssessment = HazardousSubstanceRiskAssessment.Create(
         "Hazardous Substance Risk Assessment 2", "GRA02", _clientId, _currentUser, _hazardousSubstance);
 }
        public void GetByIdAndCompanyId_Requests_HazardousSubstance_From_Repo()
        {
            // Given
            var returnedHazardousSubstances = new HazardousSubstance();

            repository.Setup(x => x.GetByIdAndCompanyId(_hazardousSubstanceId, _company)).Returns(returnedHazardousSubstances);

            // When
            var result = _target.GetByIdAndCompanyId(_hazardousSubstanceId, _company);

            // Then
            repository.Verify(x => x.GetByIdAndCompanyId(_hazardousSubstanceId, _company), Times.Once());
        }    
 public static HazardousSubstanceRiskAssessment Create(string title, string reference, long clientId, UserForAuditing currentUser, HazardousSubstance hazardousSubstance)
 {
     var riskAssessment = new HazardousSubstanceRiskAssessment
     {
         CompanyId = clientId,
         Reference = reference,
         Title = title,
         CreatedBy = currentUser,
         CreatedOn = DateTime.Now,
         Status = RiskAssessmentStatus.Draft,
         HazardousSubstance = hazardousSubstance
     };
     return riskAssessment;
 }
Example #4
0
        public void Given_a_HSRA_when_copy_then_createdby_and_createdDate_are_set()
        {
            //given
            var originalCreatingUser = new UserForAuditing { Id = Guid.NewGuid() };
            var currentUser = new UserForAuditing { Id = Guid.NewGuid() };
            var hazsub = new HazardousSubstance() { Id = 1234L };
            var hsraToCopy = HazardousSubstanceRiskAssessment.Create("this is the title", "the ref", 1312, originalCreatingUser, hazsub);

            //when
            var copiedFra = hsraToCopy.Copy("new title", "new ref", currentUser) as HazardousSubstanceRiskAssessment;

            //then
            Assert.AreEqual(currentUser.Id, copiedFra.CreatedBy.Id);
            Assert.AreEqual(copiedFra.CreatedOn.Value.Date, DateTime.Now.Date);
        }
        public void When_GetHazardousSubstancesForSearchTerm_Then_should_call_correct_methods()
        {
            // Given
            string term = "anything";
            long companyId = 1;
            int pageLimit = 100;

            var hazardousSubstances = new HazardousSubstance[] { };
            hazardousSubstanceRepository
                .Setup(x => x.GetByTermSearch(term, companyId, pageLimit))
                .Returns(hazardousSubstances);

            // When
            target.GetHazardousSubstancesForSearchTerm(term, companyId, pageLimit);

            // Then
            hazardousSubstanceRepository.VerifyAll();
        }
Example #6
0
        public void Given_a_HSRA_when_copy_then_summary_information_is_copied()
        {
            //given
            var originalCreatingUser = new UserForAuditing { Id = Guid.NewGuid() };
            var currentUser = new UserForAuditing { Id = Guid.NewGuid() };
            var hazsub = new HazardousSubstance() { Id = 1234L };
            var hsraToCopy = HazardousSubstanceRiskAssessment.Create("this is the title", "the ref", 1312, originalCreatingUser, hazsub);
            hsraToCopy.AssessmentDate = DateTime.Now.Date.AddDays(-5);
            hsraToCopy.RiskAssessor = new RiskAssessor() { Id = 255L };

            //when
            var copiedHsra = hsraToCopy.Copy("new title", "new ref", currentUser) as HazardousSubstanceRiskAssessment;

            //then
            Assert.AreEqual("new title", copiedHsra.Title);
            Assert.AreEqual("new ref", copiedHsra.Reference);
            Assert.AreEqual(hsraToCopy.AssessmentDate, copiedHsra.AssessmentDate);
            Assert.That(copiedHsra.RiskAssessor, Is.Null);
            Assert.AreEqual(hsraToCopy.HazardousSubstance.Id, copiedHsra.HazardousSubstance.Id);
        }
 public HazardousSubstanceDto Map(HazardousSubstance entity)
 {
     return new HazardousSubstanceDto
     {
         Id = entity.Id,
         Name = entity.Name,
         Reference = entity.Reference,
         SdsDate = entity.SdsDate,
         DetailsOfUse = entity.DetailsOfUse,
         AssessmentRequired = entity.AssessmentRequired,
         CompanyId = entity.CompanyId,
         CreatedOn = entity.CreatedOn,
         Supplier = entity.Supplier != null ? new SupplierDtoMapper().Map(entity.Supplier) : null,
         Pictograms = entity.HazardousSubstancePictograms != null ? new PictogramDtoMapper().Map(entity.HazardousSubstancePictograms.Select(hsp => hsp.Pictogram)).ToList() : null,
         RiskPhrases = entity.HazardousSubstanceRiskPhrases != null ? new RiskPhraseDtoMapper().Map(entity.HazardousSubstanceRiskPhrases.Select(x => x.RiskPhrase)).ToList() : null,
         HazardousSubstanceSafetyPhrases = entity.HazardousSubstanceSafetyPhrases != null  ? new HazardousSubstanceSafetyPhraseDtoMapper().Map(entity.HazardousSubstanceSafetyPhrases): null,
         Standard = entity.Standard,
         LinkedRiskAsessments = new HazardousSubstanceLinkedRiskAssessmentDtoMapper().Map(entity.HazardousSubstanceRiskAssessments)
     };
 }
Example #8
0
        public void Given_pictograms_are_included_When_add_is_clicked_then_pictograms_persisted_against_substance()
        {
            //Given
            userRepository
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), 5678)).Returns(new UserForAuditing());

            supplierRepository
                .Setup(x => x.GetByIdAndCompanyId(1234, 5678))
                .Returns(new Supplier() { Id = 1234, Name = "Test Supplier 1" });

            var requestedPictogramIds = new long[0];

            pictogramRepository
                .Setup(x => x.GetByIds(new long[] { 1L, 2L, 3L }))
                .Returns(new List<Domain.Entities.Pictogram>()
                         {
                             new Domain.Entities.Pictogram() { Id = 1, Title = "Picto 1", HazardousSubstanceStandard = HazardousSubstanceStandard.Global},
                             new Domain.Entities.Pictogram() { Id = 2, Title = "Picto 2", HazardousSubstanceStandard = HazardousSubstanceStandard.Global},
                             new Domain.Entities.Pictogram() { Id = 3, Title = "Picto 3", HazardousSubstanceStandard = HazardousSubstanceStandard.Global}
                         })
                .Callback<long[]>(y => requestedPictogramIds = y);

            var passedRequest = new HazardousSubstance();
            var request = new AddHazardousSubstanceRequest()
            {
                CompanyId = 5678,
                Name = "new title",
                PictogramIds = new long[] { 1L, 2L, 3L  }

            };

            hazardousSubstanceRepository
                .Setup(x => x.SaveOrUpdate(It.IsAny<HazardousSubstance>()))
                .Callback<HazardousSubstance>(y => passedRequest = y);

            // When
            target.Add(request);

            // Then
            pictogramRepository.Verify(x => x.GetByIds(new long[] { 1L, 2L, 3L }), Times.Once());

            var pictograms = passedRequest.HazardousSubstancePictograms.Select(hs => hs.Pictogram).ToList();
            Assert.That(pictograms.Count, Is.EqualTo(3));
            Assert.That(pictograms[0].Title, Is.EqualTo("Picto 1"));
            Assert.That(pictograms[1].Title, Is.EqualTo("Picto 2"));
            Assert.That(pictograms[2].Title, Is.EqualTo("Picto 3"));
            Assert.That(pictograms[0].Id, Is.EqualTo(1));
            Assert.That(pictograms[1].Id, Is.EqualTo(2));
            Assert.That(pictograms[2].Id, Is.EqualTo(3));
            Assert.That(pictograms[0].HazardousSubstanceStandard, Is.EqualTo(HazardousSubstanceStandard.Global));
            Assert.That(pictograms[1].HazardousSubstanceStandard, Is.EqualTo(HazardousSubstanceStandard.Global));
            Assert.That(pictograms[2].HazardousSubstanceStandard, Is.EqualTo(HazardousSubstanceStandard.Global));
        }
Example #9
0
        public void Given_risk_and_safety_phrases_are_included_When_add_is_clicked_then_risk_and_safety_phrases_persited_against_substance()
        {
            //Given
            userRepository
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), 5678)).Returns(new UserForAuditing());

            supplierRepository
                .Setup(x => x.GetByIdAndCompanyId(1234, 5678))
                .Returns(new Supplier() { Id = 1234, Name = "Test Supplier 1" });

            riskPhraseRepository
                .Setup(x => x.GetByIds(new long[] { 5L, 6L, 7L }))
                .Returns(new List<RiskPhrase>
                         {
                             new RiskPhrase() { Id = 5, Title = "RX05" },
                             new RiskPhrase() { Id = 6, Title = "RX06" },
                             new RiskPhrase() { Id = 7, Title = "RX07" },
                         });

            safetyPhraseRepository
                .Setup(x => x.GetByIds(new long[] { 8L, 9L, 10L }))
                .Returns(new List<SafetyPhrase>
                         {
                             new SafetyPhrase() { Id = 8, Title = "SX08" },
                             new SafetyPhrase() { Id = 9, Title = "SX09" },
                             new SafetyPhrase() { Id = 10, Title = "SX10" },
                         });

            var passedRequest = new HazardousSubstance();
            var request = new AddHazardousSubstanceRequest()
                          {
                              CompanyId = 5678,
                              Name = "new title",
                              RiskPhraseIds = new long[] { 5L, 6L, 7L },
                              SafetyPhraseIds = new long[] { 8L, 9L, 10L,},
                              AdditionalInformation = new List<SafetyPhraseAdditionalInformationRequest>()
                                                          {
                                                              new SafetyPhraseAdditionalInformationRequest()
                                                                  {
                                                                      SafetyPhaseId =  8L,
                                                                      AdditionalInformation = "Testing Additional Information"
                                                                  }
                                                          }
                          };

            hazardousSubstanceRepository
                .Setup(x => x.SaveOrUpdate(It.IsAny<HazardousSubstance>()))
                .Callback<HazardousSubstance>(y => passedRequest = y);

            // When
            target.Add(request);

            // Then
            var riskPhrases = passedRequest.HazardousSubstanceRiskPhrases.Select(x => x.RiskPhrase).ToList();
            Assert.That(riskPhrases.Count, Is.EqualTo(3));
            Assert.That(riskPhrases[0].Title, Is.EqualTo("RX05"));
            Assert.That(riskPhrases[1].Title, Is.EqualTo("RX06"));
            Assert.That(riskPhrases[2].Title, Is.EqualTo("RX07"));
            
            var safetyPhrases = passedRequest.HazardousSubstanceSafetyPhrases.ToList();
            Assert.That(safetyPhrases.Count, Is.EqualTo(3));
            Assert.That(safetyPhrases[0].SafetyPhrase.Title, Is.EqualTo("SX08"));
            Assert.That(safetyPhrases[0].AdditionalInformation, Is.EqualTo("Testing Additional Information"));
            Assert.That(safetyPhrases[1].SafetyPhrase.Title, Is.EqualTo("SX09"));
            Assert.That(safetyPhrases[2].SafetyPhrase.Title, Is.EqualTo("SX10"));
        }
Example #10
0
        public void On_create_populates_new_hazardous_substance()
        {
            // Given
            var userId = Guid.NewGuid();
            var returnedUser = new UserForAuditing()
                               {
                                   CompanyId = 5678,
                                   Id = userId
                               };
            userRepository
                .Setup(x => x.GetByIdAndCompanyId(userId, 5678)).Returns(returnedUser);

            supplierRepository
                .Setup(x => x.GetByIdAndCompanyId(1234, 5678))
                .Returns(new Supplier() { Id = 1234, Name = "Test Supplier 1" });

            var passedRequest = new HazardousSubstance();
            var request = new AddHazardousSubstanceRequest()
                          {
                              CompanyId = 5678,
                              UserId = userId,
                              Name = "new title",
                              Reference = "new reference",
                              SdsDate = new DateTime(2012, 6, 23),
                              SupplierId = 1234
                          };

            hazardousSubstanceRepository
                .Setup(x => x.SaveOrUpdate(It.IsAny<HazardousSubstance>()))
                .Callback<HazardousSubstance>(y => passedRequest = y);

            // When
            target.Add(request);

            // Then
            Assert.That(passedRequest.Name, Is.EqualTo(request.Name));
            Assert.That(passedRequest.CompanyId, Is.EqualTo(request.CompanyId));
            Assert.That(passedRequest.CreatedBy, Is.EqualTo(returnedUser));
            Assert.That(passedRequest.CreatedBy.Id, Is.EqualTo(request.UserId));
            Assert.That(passedRequest.Reference, Is.EqualTo(request.Reference));
            Assert.That(passedRequest.SdsDate, Is.EqualTo(request.SdsDate));
            Assert.That(passedRequest.Supplier.Id, Is.EqualTo(request.SupplierId));
        }
        public void Given_ra_is_hazardous_substance_When_RiskAssessmentReview_Create_is_called_Then_correct_methods_are_called_RiskAssessmentReview_is_correct_and_Task_is_also_created()
        {
            //Given
            const long companyId = 300L;
            var employeeContactDetail = new EmployeeContactDetail { Email = "*****@*****.**" };
            var employee = new Employee { Forename = "Gary", Surname = "Green", ContactDetails = new List<EmployeeContactDetail> { employeeContactDetail } };
            var user = new UserForAuditing
                           {
                               Id = Guid.NewGuid()
                           };
            var completionDueDate = DateTime.Now.AddDays(10);

            var employeeToAssignTo = Employee.Create(new AddUpdateEmployeeParameters
                                                    {
                                                        ClientId = companyId,
                                                        Forename = "Brian",
                                                        Surname = "Beige"
                                                    },
                                                    user);

            var hazardousSubstance = new HazardousSubstance();
            var riskAssessment = HazardousSubstanceRiskAssessment.Create("Risk Assessment 02", "RA02", companyId, user, hazardousSubstance);
            var taskCategory = TaskCategory.Create(3, "Test GRA Review");

            _responsibilityTaskCategoryRepository
                .Setup(x => x.GetHazardousSubstanceRiskAssessmentTaskCategory())
                .Returns(taskCategory);

            //When
            var riskAssessmentReview = RiskAssessmentReviewFactory.Create(
                riskAssessment,
                user,
                employeeToAssignTo,
                completionDueDate,
                _responsibilityTaskCategoryRepository.Object,
                false,
                false,
                false,
                false,
                Guid.NewGuid());

            //Then
            _responsibilityTaskCategoryRepository.VerifyAll();
            Assert.That(riskAssessmentReview.RiskAssessment, Is.SameAs(riskAssessment));
            Assert.That(riskAssessmentReview.ReviewAssignedTo, Is.SameAs(employeeToAssignTo));
            Assert.That(riskAssessmentReview.CreatedBy, Is.SameAs(user));
            Assert.That(riskAssessmentReview.CompletionDueDate, Is.EqualTo((completionDueDate)));
            Assert.That(riskAssessment.Reviews.Count(), Is.EqualTo(1));
            Assert.That(riskAssessment.Reviews.Contains(riskAssessmentReview));
            var task = riskAssessmentReview.RiskAssessmentReviewTask;
            Assert.That(task, Is.Not.Null);
            Assert.That(task.Reference, Is.EqualTo(riskAssessment.Reference));
            Assert.That(task.Title, Is.EqualTo(riskAssessment.Title));
            Assert.That(task.Description, Is.EqualTo("HSRA Review"));
            Assert.That(task.TaskCompletionDueDate, Is.EqualTo(completionDueDate));
            Assert.That(task.TaskStatus, Is.EqualTo(TaskStatus.Outstanding));
            Assert.That(task.TaskAssignedTo, Is.EqualTo(riskAssessmentReview.ReviewAssignedTo));
            Assert.That(task.TaskReoccurringType, Is.EqualTo(TaskReoccurringType.None));
            Assert.That(task.Category, Is.SameAs(taskCategory));
        }
        public virtual void UpdateSummary(string title, string reference, DateTime? assessmentDate, RiskAssessor riskAssessor, HazardousSubstance hazardousSubstance, Site site, UserForAuditing currentUser)
        {
            if (IsDifferentRiskAssessor(riskAssessor))
            {
                if (AreThereAnyFurtherControlMeasureTasks())
                {
                    FurtherControlMeasureTasks
                        .ToList()
                        .ForEach(task =>
                        {
                            task.SendTaskCompletedNotification = riskAssessor == null ? true : !riskAssessor.DoNotSendTaskCompletedNotifications;
                            task.SendTaskOverdueNotification = riskAssessor == null ? true : !riskAssessor.DoNotSendTaskOverdueNotifications;
                            task.SetLastModifiedDetails(currentUser);
                        });
                }
            }

            Title = title;
            Reference = reference;
            RiskAssessor = riskAssessor;
            AssessmentDate = assessmentDate;
            HazardousSubstance = hazardousSubstance;
            RiskAssessmentSite = site;
            SetLastModifiedDetails(currentUser);
        }