public void Given_GetViewModel_Then_Request_From_Service()
        {
            // Given
            const long riskAssessmentId = 100;
            const long companyId = 200;

            var passedSearchEmployeesRequest = new SearchEmployeesRequest();

            _employeeService
                .Setup(x => x.Search(It.IsAny<SearchEmployeesRequest>()))
                .Returns(new List<EmployeeDto>())
                .Callback<SearchEmployeesRequest>(y => passedSearchEmployeesRequest = y);

            var passedSearchHazardousSubstancesRequest = new SearchHazardousSubstancesRequest();

            _substanceService
                .Setup(x => x.Search(It.IsAny<SearchHazardousSubstancesRequest>()))
                .Returns(new List<HazardousSubstanceDto>())
                .Callback<SearchHazardousSubstancesRequest>(y => passedSearchHazardousSubstancesRequest = y);

            // When
            var result = target
                .WithRiskAssessmentId(riskAssessmentId)
                .WithCompanyId(companyId)
                .GetViewModel();

            // Then
            _riskAssessmentService.Verify(x => x.GetRiskAssessment(riskAssessmentId, companyId));
            Assert.That(result, Is.InstanceOf<EditSummaryViewModel>());
            Assert.That(passedSearchEmployeesRequest.CompanyId, Is.EqualTo(companyId));
            Assert.That(passedSearchEmployeesRequest.MaximumResults, Is.EqualTo(100));
            Assert.That(passedSearchHazardousSubstancesRequest.CompanyId, Is.EqualTo(companyId));
        }
        public IEnumerable<HazardousSubstanceDto> Search(SearchHazardousSubstancesRequest request)
        {
            var hazardousSubstances = _hazardousSubstancesRepository.Search(
                request.CompanyId,
                request.SupplierId,
                request.SubstanceNameLike,
                request.ShowDeleted);

            return new HazardousSubstanceDtoMapper().Map(hazardousSubstances); 
        }
        public void Check_for_duplicated_substance_performs_search_on_service_to_check()
        {
            // Given 
            var passedSearchHazardousSubstancesRequest = new SearchHazardousSubstancesRequest();
            var checkForDuplicatedSubstanceRequest = new CheckForDuplicatedSubstanceRequest()
                                                     {
                                                         CompanyId = 1234,
                                                         NewSubstanceName = "magic beans"
                                                     };
            hazardousSubstancesService
                .Setup(x => x.Search(It.IsAny<SearchHazardousSubstancesRequest>()))
                .Returns(new List<HazardousSubstanceDto>())
                .Callback<SearchHazardousSubstancesRequest>(y => passedSearchHazardousSubstancesRequest = y);

            // When
            var result = target.CheckForDuplicatedSubstance(checkForDuplicatedSubstanceRequest);

            // Then
            hazardousSubstancesService.Verify(x => x.Search(It.IsAny<SearchHazardousSubstancesRequest>()), Times.Once());
            Assert.That(passedSearchHazardousSubstancesRequest.CompanyId, Is.EqualTo(checkForDuplicatedSubstanceRequest.CompanyId));
            Assert.That(passedSearchHazardousSubstancesRequest.SubstanceNameLike, Is.EqualTo(checkForDuplicatedSubstanceRequest.NewSubstanceName));
        }
Example #4
0
        public void Given_valid_criteria_entered_When_search_clicked_correct_methods_called_and_correct_result_returned()
        {
            //Given
            var now = DateTime.Now;

            var request = new SearchHazardousSubstancesRequest
                          {
                              CompanyId = 5678L,
                              SubstanceNameLike = "Test name like",
                              SupplierId = 2345L
                          };

            _hazardousSubstanceService
                .Setup(x => x.Search(It.Is<SearchHazardousSubstancesRequest>(
                    y => y.CompanyId == request.CompanyId
                    && y.SubstanceNameLike == request.SubstanceNameLike
                    && y.SupplierId == request.SupplierId)))
                .Returns(new List<HazardousSubstanceDto>
                         {
                             new HazardousSubstanceDto
                             {
                                 CompanyId = 2345,
                                 AssessmentRequired = true,
                                 CreatedOn = now,
                                 DetailsOfUse = "Test details of use 1",
                                 Id = 1,
                                 Name = "Test Substance 1",
                                 Reference = "ref01",
                                 RiskPhrases = new List<RiskPhraseDto>
                                               {
                                                   new RiskPhraseDto{ Id = 1, ReferenceNumber = "RY01" },
                                                   new RiskPhraseDto{ Id = 2, ReferenceNumber = "RY02" }
                                               },
                                 HazardousSubstanceSafetyPhrases = new List<HazardousSubstanceSafetyPhraseDto>
                                               {
                                                   new HazardousSubstanceSafetyPhraseDto{ SafetyPhase  = new SafetyPhraseDto{Id = 1, ReferenceNumber = "SY01" }},
                                                   new HazardousSubstanceSafetyPhraseDto{ SafetyPhase  = new SafetyPhraseDto{Id = 2, ReferenceNumber = "SY02" }}
                                               },
                                 SdsDate = now,
                                 Standard = HazardousSubstanceStandard.European,
                                 Supplier = new SupplierDto { Id = 2345L, Name = "Test Supplier 3" }
                             },
                             new HazardousSubstanceDto
                             {
                                 CompanyId = 2345,
                                 AssessmentRequired = true,
                                 CreatedOn = now,
                                 DetailsOfUse = "Test details of use 2",
                                 Id = 2,
                                 Name = "Test Substance 2",
                                 Reference = "ref02",
                                 RiskPhrases = new List<RiskPhraseDto>
                                               {
                                                   new RiskPhraseDto{ Id = 3, ReferenceNumber = "RY03" },
                                                   new RiskPhraseDto{ Id = 4, ReferenceNumber = "RY04" }
                                               },
                                 HazardousSubstanceSafetyPhrases = new List<HazardousSubstanceSafetyPhraseDto>
                                               {
                                                   new HazardousSubstanceSafetyPhraseDto{ SafetyPhase  = new SafetyPhraseDto{ Id = 3, ReferenceNumber = "SY03" }},
                                                   new HazardousSubstanceSafetyPhraseDto{ SafetyPhase  = new SafetyPhraseDto{ Id = 4, ReferenceNumber = "SY04" }}
                                               },
                                 SdsDate = now,
                                 Standard = HazardousSubstanceStandard.Global,
                                 Supplier = new SupplierDto { Id = 2345L, Name = "Test Supplier 3" }
                             }
                         });

            //When
            var result = _target
                .WithCompanyId(5678L)
                .WithSubstanceNameLike("Test name like")
                .WithSupplierId(2345L)
                .GetViewModel();

            var substances = result.Substances.ToList();

            //Then
            _hazardousSubstanceService.Verify(x => x.Search(It.Is<SearchHazardousSubstancesRequest>(
                y => y.CompanyId == request.CompanyId
                    && y.SubstanceNameLike == request.SubstanceNameLike
                        && y.SupplierId == request.SupplierId)));

            Assert.AreEqual(5678L, result.CompanyId);
            Assert.AreEqual(2345L, result.SupplierId);
            Assert.AreEqual("Test name like", result.SubstanceNameLike);
            Assert.AreEqual(2, substances.Count());
            Assert.AreEqual("Test Substance 1", substances[0].Name);
            Assert.AreEqual("Test Substance 2", substances[1].Name);
            Assert.AreEqual("Test details of use 1", substances[0].DetailsOfUse);
            Assert.AreEqual("Test details of use 2", substances[1].DetailsOfUse);
            Assert.AreEqual("Test Supplier 3", substances[0].Supplier);
            Assert.AreEqual("Test Supplier 3", substances[1].Supplier);
            Assert.AreEqual("RY01, RY02", substances[0].RiskPhraseReferences);
            Assert.AreEqual("RY03, RY04", substances[1].RiskPhraseReferences);
            Assert.AreEqual("SY01, SY02", substances[0].SafetyPhraseReferences);
            Assert.AreEqual("SY03, SY04", substances[1].SafetyPhraseReferences);
            Assert.AreEqual("European", substances[0].Standard);
            Assert.AreEqual("Global", substances[1].Standard);
        }
        public void Given_AttachDropdownData_Then_Requests_From_Service()
        {
            // Given
            const long companyId = 200;

            var passedSearchEmployeesRequest = new SearchEmployeesRequest();

            _employeeService
                .Setup(x => x.Search(It.IsAny<SearchEmployeesRequest>()))
                .Returns(new List<EmployeeDto>()
                         {
                             new EmployeeDto(),
                             new EmployeeDto(),
                             new EmployeeDto()
                         })
                .Callback<SearchEmployeesRequest>(y => passedSearchEmployeesRequest = y);

            var passedSearchHazardousSubstancesRequest = new SearchHazardousSubstancesRequest();

            _substanceService
                .Setup(x => x.Search(It.IsAny<SearchHazardousSubstancesRequest>()))
                .Returns(new List<HazardousSubstanceDto>()
                         {
                             new HazardousSubstanceDto(),
                             new HazardousSubstanceDto(),
                             new HazardousSubstanceDto(),
                             new HazardousSubstanceDto()
                         })
                .Callback<SearchHazardousSubstancesRequest>(y => passedSearchHazardousSubstancesRequest = y);

            var model = new EditSummaryViewModel();

            // When
            var result = target
                .WithCompanyId(companyId)
                .AttachDropDownData(model);

            // Then
            Assert.That(result, Is.InstanceOf<EditSummaryViewModel>());
            Assert.That(passedSearchEmployeesRequest.CompanyId, Is.EqualTo(companyId));
            Assert.That(passedSearchEmployeesRequest.MaximumResults, Is.EqualTo(100));
            Assert.That(passedSearchHazardousSubstancesRequest.CompanyId, Is.EqualTo(companyId));
            Assert.That(model.HazardousSubstances.Count(), Is.EqualTo(5)); // plus 1 for '--select option--'
            Assert.That(model.RiskAssessmentAssessors.Count(), Is.EqualTo(4)); // plus 1 for '--select option--'
        }