public void Search_WhenSearchResponseReturnsANull_ModelShouldContainTheSearchKeyword() { // Arrange var mockSearchService = new Mock <IApprenticeshipSearchService>(); var mockLogger = new Mock <ILog>(); mockSearchService.Setup(x => x.SearchByKeyword(It.IsAny <string>(), 0, 10, 0, null)).Returns(value: null); var mockMappingServices = new Mock <IMappingService>(); mockMappingServices.Setup( x => x.Map <ApprenticeshipSearchResults, ApprenticeshipSearchResultViewModel>(It.IsAny <ApprenticeshipSearchResults>())) .Returns(new ApprenticeshipSearchResultViewModel()); ApprenticeshipController controller = new ApprenticeshipController(mockSearchService.Object, null, null, mockLogger.Object, mockMappingServices.Object, new Mock <IProfileAStep>().Object, null, null); // Act ViewResult result = controller.SearchResults(new ApprenticeshipSearchCriteria { Keywords = "test" }) as ViewResult; // Assert Assert.NotNull(result); Assert.AreEqual(null, ((ApprenticeshipSearchResultViewModel)result.Model).SearchTerm); Assert.IsNotNull(result); }
public async Task ShouldRedirectIfSearchResultsPageTooHigh() { var viewModel = new ApprenticeshipSearchResultViewModel(); _mockMappingService.Setup(x => x.Map <ApprenticeshipSearchResponse, ApprenticeshipSearchResultViewModel>(It.IsAny <ApprenticeshipSearchResponse>())) .Returns(viewModel); _mockMediator.Setup(x => x.Send(It.IsAny <ApprenticeshipSearchQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ApprenticeshipSearchResponse { StatusCode = ApprenticeshipSearchResponse.ResponseCodes.PageNumberOutOfUpperBound }); var urlHelper = new Mock <UrlHelper>(); urlHelper.Setup(x => x.Action(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <RouteValueDictionary>())) .Returns("www.google.co.uk"); _sut.Url = urlHelper.Object; var result = await _sut.SearchResults(new ApprenticeshipSearchQuery()) as RedirectResult; result.Should().NotBeNull(); }
public void Search_WhenCriteriaPage_IsLessOrEqualTo0(int input) { // Arrange var mockSearchService = new Mock <IApprenticeshipSearchService>(); var mockLogger = new Mock <ILog>(); var mockMappingServices = new Mock <IMappingService>(); ApprenticeshipController controller = new ApprenticeshipController(mockSearchService.Object, null, null, mockLogger.Object, mockMappingServices.Object, new Mock <IProfileAStep>().Object, null, null); // Act ViewResult result = controller.SearchResults(new ApprenticeshipSearchCriteria { Keywords = "test", Page = input }) as ViewResult; // Assert mockSearchService.Verify(m => m.SearchByKeyword("test", 1, It.IsAny <int>(), It.IsAny <int>(), It.IsAny <List <int> >())); Assert.IsNotNull(result); }
public void Search_WhenPassedAKeyword_ShouldReturnAViewResult() { // Arrange var mockSearchService = new Mock <IApprenticeshipSearchService>(); var mockLogger = new Mock <ILog>(); mockSearchService.Setup(x => x.SearchByKeyword(It.IsAny <string>(), 0, 10, 0, null)).Returns(new ApprenticeshipSearchResults()); var mockMappingServices = new Mock <IMappingService>(); mockMappingServices.Setup( x => x.Map <ApprenticeshipSearchResults, ApprenticeshipSearchResultItemViewModel>(It.IsAny <ApprenticeshipSearchResults>())) .Returns(new ApprenticeshipSearchResultItemViewModel()); ApprenticeshipController controller = new ApprenticeshipController(mockSearchService.Object, null, null, mockLogger.Object, mockMappingServices.Object, new Mock <IProfileAStep>().Object, null, null); // Act ViewResult result = controller.SearchResults(new ApprenticeshipSearchCriteria { Keywords = "test" }) as ViewResult; // Assert Assert.IsNotNull(result); }