public void Given_valid_request_When_mark_employee_as_deleted_Then_should_call_correct_methods()
        {

            // Given
            var request = new SearchEmployeesRequest()
                              {
                                  CompanyId = 1
                              };


            var target = CreateEmployeeService();

            var employees = new Employee[] { };
            _employeeRepository
                .Setup(x => x.Search(
                    request.CompanyId, 
                    request.EmployeeReferenceLike, 
                    request.ForenameLike, 
                    request.SurnameLike, 
                    request.SiteIds, 
                    request.ShowDeleted, 
                    request.MaximumResults,
                    request.IncludeSiteless, 
                    request.ExcludeWithActiveUser,
                    null,
                    true))
                .Returns(employees);

            // When
            target.Search(request);

            // Then
            _employeeRepository.VerifyAll();

        }
        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 void Given_valid_request_When_mark_employee_as_deleted_Then_should_return_correct_result()
        {

            // Given
            var request = new SearchEmployeesRequest()
                              {
                                  CompanyId = 1
                              };

            var target = CreateEmployeeService();

            var employees = new Employee[]
                                {
                                    new Employee()
                                        {
                                            EmployeeReference = "1"
                                        }, 
                                    new Employee()
                                        {
                                            EmployeeReference = "2"
                                        }, 
                                    new Employee()
                                        {
                                            EmployeeReference = "3"
                                        },
                                };
            _employeeRepository
                .Setup(x => x.Search(
                    request.CompanyId, 
                    request.EmployeeReferenceLike, 
                    request.ForenameLike, 
                    request.SurnameLike, 
                    request.SiteIds, 
                    request.ShowDeleted, 
                    request.MaximumResults,
                    request.IncludeSiteless, 
                    request.ExcludeWithActiveUser,
                    null,
                    true))
                .Returns(employees);

            // When
            var result = target.Search(request);

            // Then
            Assert.That(result.Count, Is.EqualTo(employees.Length));
            Assert.That(result.Count(x => x.EmployeeReference == "1"), Is.EqualTo(1));
            Assert.That(result.Count(x => x.EmployeeReference == "2"), Is.EqualTo(1));
            Assert.That(result.Count(x => x.EmployeeReference == "3"), Is.EqualTo(1));
        }
        public List<EmployeeDto> Search(SearchEmployeesRequest request)
        {
            _log.Add(request);

            try
            {
                IEnumerable<Employee> employees = _employeeRepository.Search(request.CompanyId,
                                                                             request.EmployeeReferenceLike,
                                                                             request.ForenameLike,
                                                                             request.SurnameLike,
                                                                             request.SiteIds,
                                                                             request.ShowDeleted,
                                                                             request.MaximumResults,
                                                                             request.IncludeSiteless,
                                                                             request.ExcludeWithActiveUser,
                                                                             null,
                                                                             true);


                return employees.Select(new EmployeeDtoMapper().MapWithNationalityAndContactDetailsAndEmergencyContactDetailsAndUser).ToList();
            }
            catch (Exception ex)
            {
                _log.Add(ex);
                throw;
            }
        }
        public void Given_GetViewModel_When_specific_siteId_requested_Then_Employee_Search_only_requests_requested_siteId()
        {
            // Given
            var siteService = new Mock<ISiteService>();
            siteService
                .Setup(x => x.Search(It.IsAny<SearchSitesRequest>()))
                .Returns(new List<SiteDto>());

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

            var lookupService = new Mock<ILookupService>();
            lookupService.Setup(x => x.GetEmploymentStatuses()).Returns(new List<LookupDto>());

            var sessionManager = new Mock<IBusinessSafeSessionManager>();
            var session = new Mock<ISession>();
            sessionManager.SetupGet(x => x.Session).Returns(session.Object);

            var controller = CreateEmployeeSearchControllerWithUserAndFactory(new EmployeeSearchViewModelFactory(employeeService.Object, siteService.Object, lookupService.Object, sessionManager.Object));

            const string employeeReference = "Reference";
            const string forename = "Forname";
            const string surname = "Surname";
            const long siteId = 100;

            // When
            controller.Index(_companyId, employeeReference, forename, surname, siteId);

            // Then
            Assert.That(passedSearchEmployeesRequest.SiteIds.Length, Is.EqualTo(1));
            Assert.That(passedSearchEmployeesRequest.SiteIds[0], Is.EqualTo(siteId));
            Assert.That(passedSearchEmployeesRequest.IncludeSiteless, Is.False);
        }
 private SearchEmployeesRequest CreateEmployeeSearchRequest()
 {
     var employeeSearchRequest = new SearchEmployeesRequest()
     {
         CompanyId = _companyId,
         ShowDeleted = false
     };
     return employeeSearchRequest;
 }
        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--'
        }