public ICandidateServiceProvider Build() { CandidateServiceProvider = new CandidateServiceProvider(CandidateService.Object, UserAccountService.Object, UserDataProvider.Object, AuthenticationTicketService.Object, new ApprenticeshipCandidateWebMappers(), ConfigurationService.Object, Logger.Object); return(CandidateServiceProvider); }
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 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 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 PoputlateLocationCookieWithSearchedLocation() { UserDataProvider.Setup(x => x.Get(UserDataItemNames.LastSearchedLocation)).Returns("TEST COOKIE LOCATION"); var response = Mediator.Index(null, ApprenticeshipSearchMode.Keyword, false); response.AssertCode(ApprenticeshipSearchMediatorCodes.Index.Ok, true); response.ViewModel.Location.Should().Be("TEST COOKIE LOCATION"); CandidateServiceProvider.Verify(x => x.GetCandidate(It.IsAny <Guid>()), Times.Never); }
public void SendMessageOk() { var candidateId = Guid.NewGuid(); var candidateServiceProvider = new CandidateServiceProvider(_candidateServiceMock.Object, null, null, null, _mapperMock.Object, null, null); _mapperMock.Setup(m => m.Map <ContactMessageViewModel, ContactMessage>(It.IsAny <ContactMessageViewModel>())) .Returns(new ContactMessage()); var result = candidateServiceProvider.SendContactMessage(candidateId, new ContactMessageViewModel()); result.Should().BeTrue(); _candidateServiceMock.Verify(cs => cs.SubmitContactMessage(It.Is <ContactMessage>(cm => cm.UserId == candidateId))); }
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 SendMessageFail() { var candidateId = Guid.NewGuid(); var candidateServiceProvider = new CandidateServiceProvider(_candidateServiceMock.Object, null, null, null, _mapperMock.Object, null, null); _mapperMock.Setup(m => m.Map <ContactMessageViewModel, ContactMessage>(It.IsAny <ContactMessageViewModel>())) .Returns(new ContactMessage()); _candidateServiceMock.Setup(cs => cs.SubmitContactMessage(It.IsAny <ContactMessage>())) .Throws <ArgumentException>(); var result = candidateServiceProvider.SendContactMessage(candidateId, new ContactMessageViewModel()); result.Should().BeFalse(); }
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); }