public void ShouldRenderSavedSearchPromptWhenCandidateHasNoSavedSearches() { // Arrange. var @partial = new savedSearches(); var candidateId = Guid.NewGuid(); var mockViewModel = new List <SavedSearchViewModel>(); CandidateServiceProvider.Setup(mock => mock.GetSavedSearches(candidateId)).Returns(mockViewModel); var candidate = new Domain.Entities.Candidates.Candidate { RegistrationDetails = new RegistrationDetails { Address = new Address { Postcode = "CANDIDATE POSTCODE" } } }; CandidateServiceProvider .Setup(p => p.GetCandidate(candidateId)).Returns(candidate); var indexViewModel = Mediator.Index(candidateId, ApprenticeshipSearchMode.SavedSearches, false).ViewModel; // Act. var view = @partial.RenderAsHtml(indexViewModel); // Assert. var list = view.GetElementbyId("saved-searches-list"); var prompt = view.GetElementbyId("saved-searches-prompt"); list.Should().BeNull(); prompt.Should().NotBeNull(); }
public void SearchMode_SavedSearches_AuthenticatedUserWithNoSavedSearchesTest() { var index = new Index(); var candidateId = Guid.NewGuid(); var mockViewModel = new List <SavedSearchViewModel>(); CandidateServiceProvider.Setup(mock => mock.GetSavedSearches(candidateId)).Returns(mockViewModel); var candidate = new Domain.Entities.Candidates.Candidate { RegistrationDetails = new RegistrationDetails { Address = new Address { Postcode = "CANDIDATE POSTCODE" } } }; CandidateServiceProvider .Setup(p => p.GetCandidate(candidateId)).Returns(candidate); var searchViewModel = Mediator.Index(candidateId, ApprenticeshipSearchMode.SavedSearches, false).ViewModel; var view = index.RenderAsHtml(CreateMockHttpContext(true), searchViewModel); var link = view.GetElementbyId("saved-searches-tab-control"); link.Should().NotBeNull(); link.Attributes["class"].Value.Should().Contain(" active"); view.GetElementbyId("run-saved-search-button").Should().BeNull(); view.GetElementbyId("saved-searches-settings-link").Should().BeNull(); }
public void ShouldRenderTabAsActiveWhenSearchModeIsSavedSearches(int savedSearchCount) { // Arrange. var @partial = new savedSearches(); var candidateId = Guid.NewGuid(); var mockViewModel = new Fixture().Build <SavedSearchViewModel>().CreateMany(savedSearchCount); CandidateServiceProvider.Setup(mock => mock.GetSavedSearches(candidateId)).Returns(mockViewModel); var candidate = new Domain.Entities.Candidates.Candidate { RegistrationDetails = new RegistrationDetails { Address = new Address { Postcode = "CANDIDATE POSTCODE" } } }; CandidateServiceProvider .Setup(p => p.GetCandidate(candidateId)).Returns(candidate); var viewModel = Mediator.Index(candidateId, ApprenticeshipSearchMode.SavedSearches, false).ViewModel; // Act. var view = @partial.RenderAsHtml(viewModel); // Assert. view.GetElementbyId("saved-searches").Attributes["class"].Value.Contains(" active").Should().BeTrue(); }
public void ShouldRenderSavedSearchesList(int savedSearchCount) { // Arrange. var @partial = new savedSearches(); var candidateId = Guid.NewGuid(); var mockViewModel = new Fixture().Build <SavedSearchViewModel>().CreateMany(savedSearchCount).ToList(); CandidateServiceProvider.Setup(mock => mock.GetSavedSearches(candidateId)).Returns(mockViewModel); var candidate = new Domain.Entities.Candidates.Candidate { RegistrationDetails = new RegistrationDetails { Address = new Address { Postcode = "CANDIDATE POSTCODE" } } }; CandidateServiceProvider .Setup(p => p.GetCandidate(candidateId)).Returns(candidate); var indexViewModel = Mediator.Index(candidateId, ApprenticeshipSearchMode.SavedSearches, false).ViewModel; // Act. var view = @partial.RenderAsHtml(indexViewModel); // Assert. var list = view.GetElementbyId("saved-searches-list"); list.Should().NotBeNull(); list.ChildNodes.Count(node => node.Name == "li").Should().Be(savedSearchCount); foreach (var savedSearchViewModel in mockViewModel) { var listItemId = string.Format("{0}-{1}", "saved-search", savedSearchViewModel.Id); var listItemLabelId = string.Format("{0}-{1}", "saved-search-label", savedSearchViewModel.Id); var listItem = view.GetElementbyId(listItemId); listItem.Should().NotBeNull(); listItem.GetAttributeValue("value", null).Should().Be(savedSearchViewModel.Id.ToString()); var listItemLabel = view.GetElementbyId(listItemLabelId); listItemLabel.Should().NotBeNull(); listItemLabel.InnerText.Should().Be(savedSearchViewModel.Name); } }
public void ShouldNotRenderSubcategoriesFilter(int savedSearchCount) { // Arrange. var @partial = new savedSearches(); var candidateId = Guid.NewGuid(); var mockViewModel = new Fixture() .Build <SavedSearchViewModel>() .With(each => each.SubCategoriesFullNames, null) .CreateMany(savedSearchCount).ToList(); CandidateServiceProvider.Setup(mock => mock.GetSavedSearches(candidateId)).Returns(mockViewModel); var candidate = new Domain.Entities.Candidates.Candidate { RegistrationDetails = new RegistrationDetails { Address = new Address { Postcode = "CANDIDATE POSTCODE" } } }; CandidateServiceProvider .Setup(p => p.GetCandidate(candidateId)).Returns(candidate); var indexViewModel = Mediator.Index(candidateId, ApprenticeshipSearchMode.SavedSearches, false).ViewModel; // Act. var view = @partial.RenderAsHtml(indexViewModel); // Assert. var list = view.GetElementbyId("saved-searches-list"); list.Should().NotBeNull(); list.ChildNodes.Count(node => node.Name == "li").Should().Be(savedSearchCount); foreach (var savedSearchViewModel in mockViewModel) { var id = string.Format("{0}-{1}", "saved-search-subcategories", savedSearchViewModel.Id); var element = view.GetElementbyId(id); element.Should().BeNull(); } }
public void Ok_AllApprenticeshipSearchModes(ApprenticeshipSearchMode searchMode) { var candidateId = searchMode == ApprenticeshipSearchMode.SavedSearches ? Guid.NewGuid() : default(Guid?); var candidate = new Candidate { RegistrationDetails = new RegistrationDetails { Address = new Address { Postcode = "CANDIDATE POSTCODE" } } }; CandidateServiceProvider.Setup(x => x.GetCandidate(It.IsAny <Guid>())).Returns(candidate); var response = Mediator.Index(candidateId, searchMode, false); response.AssertCode(ApprenticeshipSearchMediatorCodes.Index.Ok, true); var viewModel = response.ViewModel; viewModel.WithinDistance.Should().Be(5); viewModel.LocationType.Should().Be(ApprenticeshipLocationType.NonNational); viewModel.ResultsPerPage.Should().Be(5); viewModel.Distances.SelectedValue.Should().Be(null); viewModel.ApprenticeshipLevels.Should().NotBeNull(); viewModel.ApprenticeshipLevel.Should().Be("All"); viewModel.SearchMode.Should().Be(searchMode); if (searchMode == ApprenticeshipSearchMode.SavedSearches) { viewModel.SavedSearches.Should().NotBeNull(); } else { viewModel.SavedSearches.Should().BeNull(); } }
public void PoputlateLocationWithUsersPostcode() { var candidate = new Candidate { RegistrationDetails = new RegistrationDetails { Address = new Address { Postcode = "CANDIDATE POSTCODE" } } }; CandidateServiceProvider.Setup(x => x.GetCandidate(It.IsAny <Guid>())).Returns(candidate); var response = Mediator.Index(Guid.NewGuid(), ApprenticeshipSearchMode.Keyword, true); response.AssertCode(ApprenticeshipSearchMediatorCodes.Index.Ok, true); response.ViewModel.Location.Should().Be("CANDIDATE POSTCODE"); UserDataProvider.Verify(x => x.Push(UserDataItemNames.LastSearchedLocation, "CANDIDATE POSTCODE"), Times.Once); CandidateServiceProvider.Verify(x => x.GetCandidate(It.IsAny <Guid>()), Times.Once); }