public void TestResponseConversion() { //Arrange var viewModel = new CandidateSearchViewModel(); var candidateSummaries = new Fixture().Build <CandidateSummary>().CreateMany(3).ToList(); _candidateSearchService.Setup(s => s.SearchCandidates(It.IsAny <CandidateSearchRequest>())).Returns(candidateSummaries); //Act var response = _provider.SearchCandidates(viewModel, null); //Assert response.Should().NotBeNull(); response.SearchViewModel.Should().Be(viewModel); response.Candidates.Should().NotBeNull(); response.Candidates.Page.Should().NotBeNull(); var candidateSummaryViewModels = response.Candidates.Page.ToList(); candidateSummaryViewModels.Count.Should().Be(candidateSummaries.Count); foreach (var candidateSummary in candidateSummaries) { candidateSummaryViewModels.Should().Contain(c => c.Id == candidateSummary.EntityId && c.Name == candidateSummary.FirstName + " " + candidateSummary.LastName && c.Address.AddressLine1 == candidateSummary.Address.AddressLine1 && c.DateOfBirth == candidateSummary.DateOfBirth); } }
public void DefaultShouldNotHaveAnyValidationErrors() { var viewModel = new CandidateSearchViewModel(); var result = _validator.Validate(viewModel); result.IsValid.Should().BeTrue(); }
public void ValidationFailedNoSearchCriteria() { //Arrange var viewModel = new CandidateSearchViewModel(); //Act var result = _mediator.Search(viewModel); //Assert result.AssertValidationResult(CandidateMediatorCodes.Search.FailedValidation); }
public void TestOrdering() { //Arrange var viewModel = new CandidateSearchViewModel(); var candidateSummaries = new List <CandidateSummary> { new CandidateSummary { EntityId = Guid.NewGuid(), FirstName = "bbb", LastName = "ddd", Address = new Address { AddressLine1 = "1", Postcode = "zzz" } }, new CandidateSummary { EntityId = Guid.NewGuid(), FirstName = "aaa", LastName = "ddd", Address = new Address { AddressLine1 = "3", Postcode = "ccc" } }, new CandidateSummary { EntityId = Guid.NewGuid(), FirstName = "bbb", LastName = "ddd", Address = new Address { AddressLine1 = "2", Postcode = "ccc" } }, new CandidateSummary { EntityId = Guid.NewGuid(), FirstName = "bbb", LastName = "ddd", Address = new Address { AddressLine1 = "1", Postcode = "ccc" } }, new CandidateSummary { EntityId = Guid.NewGuid(), FirstName = "bbb", LastName = "ccc", Address = new Address { AddressLine1 = "1", Postcode = "ccc" } }, }; var expectedOrder = new[] { 4, 1, 3, 2, 0 }; _candidateSearchService.Setup(s => s.SearchCandidates(It.IsAny <CandidateSearchRequest>())).Returns(candidateSummaries); //Act var response = _provider.SearchCandidates(viewModel, null); //Assert var index = 0; foreach (var candidateSummaryViewModel in response.Candidates.Page) { var candidateSummary = candidateSummaries[expectedOrder[index]]; candidateSummaryViewModel.Id.Should().Be(candidateSummary.EntityId); candidateSummaryViewModel.Name.Should().Be(candidateSummary.FirstName + " " + candidateSummary.LastName); index++; } }
public void Ok() { //Arrange var viewModel = new CandidateSearchViewModel { FirstName = "First" }; //Act var result = _mediator.Search(viewModel); //Assert result.AssertCodeAndMessage(CandidateMediatorCodes.Search.Ok); _candidateProvider.Verify(p => p.SearchCandidates(viewModel, null)); }
public void TestApplicantIdConversion(string applicantId, string expectedCandidateGuidPrefix, int expectedCandidateId) { //Arrange var viewModel = new CandidateSearchViewModel { ApplicantId = applicantId }; //Act _provider.SearchCandidates(viewModel, null); //Assert _candidateSearchService.Verify(s => s.SearchCandidates(It.Is <CandidateSearchRequest>(r => r.CandidateGuidPrefix == expectedCandidateGuidPrefix && r.CandidateId == (expectedCandidateId == 0 ? (int?)null : expectedCandidateId)))); }
public MediatorResponse <CandidateSearchResultsViewModel> Search(CandidateSearchViewModel searchViewModel, string ukprn) { searchViewModel.PageSizes = SelectListItemsFactory.GetPageSizes(searchViewModel.PageSize); var validatonResult = _candidateSearchViewModelServerValidator.Validate(searchViewModel); if (!validatonResult.IsValid) { return(GetMediatorResponse(CandidateMediatorCodes.Search.FailedValidation, new CandidateSearchResultsViewModel { SearchViewModel = searchViewModel }, validatonResult)); } var resultsViewModel = _candidateProvider.SearchCandidates(searchViewModel, ukprn); return(GetMediatorResponse(CandidateMediatorCodes.Search.Ok, resultsViewModel)); }
public void PostcodeInvalidCharacters(string postcode, bool expectValid) { var viewModel = new CandidateSearchViewModel { Postcode = postcode }; _validator.Validate(viewModel); if (expectValid) { _validator.ShouldNotHaveValidationErrorFor(vm => vm.Postcode, viewModel); } else { _validator.ShouldHaveValidationErrorFor(vm => vm.Postcode, viewModel); } }
public void DateOfBirthInvalidCharacters(string dateOfBirth, bool expectValid) { var viewModel = new CandidateSearchViewModel { DateOfBirth = dateOfBirth }; _validator.Validate(viewModel); if (expectValid) { _validator.ShouldNotHaveValidationErrorFor(vm => vm.DateOfBirth, viewModel); } else { _validator.ShouldHaveValidationErrorFor(vm => vm.DateOfBirth, viewModel); } }
public void LastNameInvalidCharacters(string lastName, bool expectValid) { var viewModel = new CandidateSearchViewModel { LastName = lastName }; _validator.Validate(viewModel); if (expectValid) { _validator.ShouldNotHaveValidationErrorFor(vm => vm.LastName, viewModel); } else { _validator.ShouldHaveValidationErrorFor(vm => vm.LastName, viewModel); } }
public void TestPageLimit() { //Arrange var viewModel = new CandidateSearchViewModel(); var candidateSummaries = new Fixture().Build <CandidateSummary>().CreateMany(13).ToList(); _candidateSearchService.Setup(s => s.SearchCandidates(It.IsAny <CandidateSearchRequest>())).Returns(candidateSummaries); //Act var response = _provider.SearchCandidates(viewModel, null); //Assert var candidateSummaryViewModels = response.Candidates.Page.ToList(); candidateSummaryViewModels.Count.Should().Be(10); response.Candidates.ResultsCount.Should().Be(candidateSummaries.Count); response.Candidates.CurrentPage.Should().Be(1); response.Candidates.TotalNumberOfPages.Should().Be(2); }
public ActionResult Search(CandidateSearchViewModel viewModel) { var response = _candidateMediator.Search(viewModel); ModelState.Clear(); switch (response.Code) { case CandidateMediatorCodes.Search.FailedValidation: response.ValidationResult.AddToModelState(ModelState, "SearchViewModel"); return(View(response.ViewModel)); case CandidateMediatorCodes.Search.Ok: return(View(response.ViewModel)); default: throw new InvalidMediatorCodeException(response.Code); } }
public FileContentResult CandidatesBySourceCSV(CandidateSearchViewModel vm) { Func <IQueryable <Candidate>, IQueryable <Candidate> > candidateFilter = q => { q = q.Include("Person"); if (vm.Source.HasValue) { q = q.Where(r => r.Source == vm.Source.Value); } if (vm.Status.HasValue) { q = q.Where(r => r.Status == vm.Status.Value); } if (!string.IsNullOrEmpty(vm.Organization)) { q = q.Where(r => r.Person.Organization.Contains(vm.Organization)); } return(q); }; var csv = new StringBuilder(); var candidatesBySource = _candidateRepository.Search(candidateFilter).GroupBy(l => l.Source) .Select(x => new { x.Key, Value = x.Count() }) .ToList(); var keys = string.Join(",", candidatesBySource.Select(x => x.Key).ToArray()); csv.AppendLine(keys); var values = string.Join(",", candidatesBySource.Select(x => x.Value).ToArray()); csv.AppendLine(values); return(File(new UTF8Encoding().GetBytes(csv.ToString()), "text/csv", "CandidatesBySourceCSV.csv")); }
public CandidateSearchResultsViewModel SearchCandidates(CandidateSearchViewModel searchViewModel, string ukprn) { var dateOfBirth = string.IsNullOrEmpty(searchViewModel.DateOfBirth) ? (DateTime?)null : DateTime.Parse(searchViewModel.DateOfBirth, _dateCultureInfo); IEnumerable <int> providerSiteIds = null; if (!string.IsNullOrEmpty(ukprn)) { var providerId = _providerService.GetProvider(ukprn).ProviderId; var ownedProviderSites = _providerService.GetOwnedProviderSites(providerId); providerSiteIds = ownedProviderSites.Select(ps => ps.ProviderSiteId).ToList(); } var request = new CandidateSearchRequest(searchViewModel.FirstName, searchViewModel.LastName, dateOfBirth, searchViewModel.Postcode, CandidateSearchExtensions.GetCandidateGuidPrefix(searchViewModel.ApplicantId), CandidateSearchExtensions.GetCandidateId(searchViewModel.ApplicantId), providerSiteIds, !string.IsNullOrEmpty(ukprn)); var candidates = _candidateSearchService.SearchCandidates(request) ?? new List <CandidateSummary>(); var results = new CandidateSearchResultsViewModel { SearchViewModel = searchViewModel, Candidates = new PageableViewModel <CandidateSummaryViewModel> { Page = candidates.OrderBy(c => c.LastName) .ThenBy(c => c.FirstName) .ThenBy(c => c.Address.Postcode) .ThenBy(c => c.Address.AddressLine1) .Skip((searchViewModel.CurrentPage - 1) * searchViewModel.PageSize) .Take(searchViewModel.PageSize) .Select(c => _mapper.Map <CandidateSummary, CandidateSummaryViewModel>(c)) .ToList(), ResultsCount = candidates.Count, CurrentPage = searchViewModel.CurrentPage, TotalNumberOfPages = candidates.Count == 0 ? 1 : (int)Math.Ceiling((double)candidates.Count / searchViewModel.PageSize) } }; return(results); }
public void TestEmptyDateRequestConversion() { //Arrange var viewModel = new CandidateSearchViewModel { FirstName = "First", LastName = "Last", DateOfBirth = "", Postcode = "CV1 2WT" }; //Act _provider.SearchCandidates(viewModel, null); //Assert _candidateSearchService.Verify(s => s.SearchCandidates(It.Is <CandidateSearchRequest>(r => r.FirstName == viewModel.FirstName && r.LastName == viewModel.LastName && r.DateOfBirth == null && r.Postcode == viewModel.Postcode))); }
public void TestRequestConversion() { //Arrange var viewModel = new CandidateSearchViewModel { FirstName = "First", LastName = "Last", DateOfBirth = "10/02/1990", Postcode = "CV1 2WT" }; //Act _provider.SearchCandidates(viewModel, null); //Assert var expectedDate = new DateTime(1990, 2, 10); _candidateSearchService.Verify(s => s.SearchCandidates(It.Is <CandidateSearchRequest>(r => r.FirstName == viewModel.FirstName && r.LastName == viewModel.LastName && r.DateOfBirth == expectedDate && r.Postcode == viewModel.Postcode))); }
public void AtLeastOneSearchCriteriaRequired(string firstName, string lastName, string dateOfBirth, string postCode, bool expectValid) { var viewModel = new CandidateSearchViewModel { FirstName = firstName, LastName = lastName, DateOfBirth = dateOfBirth, Postcode = postCode }; var result = _validator.Validate(viewModel); if (expectValid) { result.IsValid.Should().BeTrue(); } else { result.IsValid.Should().BeFalse(); result.Errors.Count.Should().Be(1); result.Errors[0].ErrorMessage.Should().Be(CandidateSearchViewModelMessages.NoSearchCriteriaErrorText); } }
public ActionResult Index(CandidateSearchViewModel vm) { var candidateDesignations = _candidateDesignationRepository.GetAll(); ViewBag.CandidateDesignationId = new SelectList(candidateDesignations, "Id", "Title"); Func <IQueryable <Candidate>, IQueryable <Candidate> > candidateFilter = q => { q = q.Include(c => c.Person).Include(c => c.Designation); if (vm.CandidateDesignationId.HasValue) { q = q.Where(r => r.DesignationId == vm.CandidateDesignationId.Value); } if (vm.MinExperience.HasValue) { q = q.Where(r => r.TotalExperience >= vm.MinExperience.Value); } if (vm.MaxExperience.HasValue) { q = q.Where(r => r.TotalExperience <= vm.MaxExperience.Value); } if (vm.Source.HasValue) { q = q.Where(r => r.Source == vm.Source.Value); } if (vm.Status.HasValue) { q = q.Where(r => r.Status == vm.Status.Value); } if (!string.IsNullOrEmpty(vm.FirstName)) { q = q.Where(r => r.Person.FirstName.Contains(vm.FirstName)); } if (!string.IsNullOrEmpty(vm.LastName)) { q = q.Where(r => r.Person.LastName.Contains(vm.LastName)); } if (vm.Gender.HasValue) { q = q.Where(r => r.Person.Gender == vm.Gender.Value); } if (!string.IsNullOrEmpty(vm.Organization)) { q = q.Where(r => r.Person.Organization.Contains(vm.Organization)); } if (!string.IsNullOrEmpty(vm.Designation)) { q = q.Where(r => r.Person.Designation.Contains(vm.Designation)); } if (!string.IsNullOrEmpty(vm.Email)) { q = q.Where(r => r.Person.Email.Contains(vm.Email)); } if (!string.IsNullOrEmpty(vm.Phone)) { q = q.Where(r => r.Person.PhoneNo.Contains(vm.Phone)); } return(q); }; vm.Candidates = _candidateRepository.SearchPage(candidateFilter, o => o.OrderByDescending(c => c.RecievedOn), vm.GetPageNo(), vm.PageSize); return(View(vm)); }
public ActionResult Index(CandidateSearchViewModel vm) { var firstDay = DateTime.UtcNow.AddDays(-31); var lastDay = DateTime.UtcNow; Func <IQueryable <Candidate>, IQueryable <Candidate> > candidateFilter = q => { q = q.Include("Person"); if (vm.Source.HasValue) { q = q.Where(r => r.Source == vm.Source.Value); } if (vm.Status.HasValue) { q = q.Where(r => r.Status == vm.Status.Value); } if (!string.IsNullOrEmpty(vm.Organization)) { q = q.Where(r => r.Person.Organization.Contains(vm.Organization)); } if (vm.StartDate.HasValue) { q = q.Where(r => r.CreatedOn >= vm.StartDate.Value); firstDay = vm.StartDate.Value; } if (vm.EndDate.HasValue) { q = q.Where(r => r.CreatedOn <= vm.EndDate.Value); lastDay = vm.EndDate.Value; } q = q.Where(r => r.RecievedOn >= firstDay); return(q); }; vm.Total = _candidateRepository.Count(); var postedRequirements = _candidateRepository.Search(candidateFilter) .ToList() .GroupBy(r => r.RecievedOn.ToShortDateString()) .Select(r => new { Day = r.Key, Total = r.Count() }); var dateArray = new List <string> { "x" }; var postedArray = new List <string> { "new" }; var counter = firstDay; while (counter <= lastDay) { var selectedDay = counter.ToShortDateString(); dateArray.Add(selectedDay); var selectedPost = postedRequirements.FirstOrDefault(p => p.Day == selectedDay); postedArray.Add(selectedPost?.Total.ToString() ?? "0"); counter = counter.AddDays(1); } ViewBag.Dates = dateArray; ViewBag.Posts = postedArray; return(View(vm)); }