public void OnNavigatingTo_Search_Results_Page_With_Search_Term() { var repository = new MockProductCatalogRepository(); repository.GetFilteredProductsAsyncDelegate = (queryString, maxResults) => { Collection <Product> products; if (queryString == "bike") { products = new Collection <Product>(new List <Product> { new Product() { Title = "bike1", ProductNumber = "1", ImageUri = new Uri("http://image") }, new Product() { Title = "bike2", ProductNumber = "2", ImageUri = new Uri("http://image") } }); } else { products = new Collection <Product>(new List <Product> { new Product() { Title = "bike1", ProductNumber = "1", ImageUri = new Uri("http://image") }, new Product() { Title = "bike2", ProductNumber = "2", ImageUri = new Uri("http://image") }, new Product() { Title = "product3", ProductNumber = "3", ImageUri = new Uri("http://image") } }); } return(Task.FromResult(new SearchResult(3, products))); }; var target = new SearchResultsPageViewModel(repository, new MockResourceLoader(), new MockAlertMessageService()); const string searchTerm = "bike"; target.OnNavigatedTo(new NavigatedToEventArgs { Parameter = searchTerm, NavigationMode = NavigationMode.New }, null); Assert.AreEqual("bike", target.SearchTerm); Assert.IsNotNull(target.Results); Assert.AreEqual(2, target.Results.Count); var resultsThatDontMatch = target.Results.Any(p => !p.Title.Contains(searchTerm)); Assert.IsFalse(resultsThatDontMatch); }
public SearchResultsPageViewModel MapFrom( IList <Assertion> assertions, IList <Tag> tags) { var result = new SearchResultsPageViewModel { MatchingAssertions = assertions.MapAllUsing(this.assertionViewModelMapper), PopularTags = tags.MapAllUsing(this.tagViewModelMapper) }; return(this.pageViewModelBuilder.UpdateSiteProperties(result)); }
public SearchResultsPageViewModel MapFrom( IList<Assertion> assertions, IList<Tag> tags) { var result = new SearchResultsPageViewModel { MatchingAssertions = assertions.MapAllUsing(this.assertionViewModelMapper), PopularTags = tags.MapAllUsing(this.tagViewModelMapper) }; return this.pageViewModelBuilder.UpdateSiteProperties(result); }
public void OnNavigatingTo_Search_Results_Page_Without_Search_Term() { var repository = new MockProductCatalogRepository(); repository.GetFilteredProductsAsyncDelegate = (queryString, maxResults) => { ReadOnlyCollection <Product> products; if (queryString == "bike") { products = new ReadOnlyCollection <Product>(new List <Product> { new Product() { Title = "bike1", ProductNumber = "1", ImageUri = new Uri("http://image") }, new Product() { Title = "bike2", ProductNumber = "2", ImageUri = new Uri("http://image") } }); } else { products = new ReadOnlyCollection <Product>(new List <Product> { new Product() { Title = "bike1", ProductNumber = "1", ImageUri = new Uri("http://image") }, new Product() { Title = "bike2", ProductNumber = "2", ImageUri = new Uri("http://image") }, new Product() { Title = "product3", ProductNumber = "3", ImageUri = new Uri("http://image") } }); } return(Task.FromResult(new SearchResult(3, products))); }; var target = new SearchResultsPageViewModel(repository, new MockResourceLoader(), new MockAlertMessageService()); var searchTerm = string.Empty; target.OnNavigatedTo(searchTerm, NavigationMode.New, null); Assert.AreEqual(string.Empty, target.SearchTerm); Assert.IsNotNull(target.Results); Assert.AreEqual(3, target.Results.Count); }
public SearchResultsPageViewModelScenario() { var testInstance = new SearchInstance() { Query = "Search1", Images = new List <ImageResult>() { new ImageResult() { MediaUrl = "http://example.com" } } }; ApplicationSettings.Searches.Add(testInstance); ApplicationSettings.SelectedInstance = testInstance; _imageSearchService = new MockImageSearchService(); _accelerometer = new MockAccelerometer(); _sharePump = new MockShareDataRequestedPump(); ViewModel = new SearchResultsPageViewModel(ApplicationSettings, NavigationService, _imageSearchService, MessageHub, _accelerometer, new MockStatusService(), _sharePump); }
public async Task <IActionResult> SearchResults(string query) { // Redirect to Jump Routes if the query syntax matches if (!String.IsNullOrWhiteSpace(query)) { Regex rgx = new Regex(@"(.*) > (.*)"); List <Match> rgxMatches = rgx.Matches(query).ToList(); if (rgxMatches != null && rgxMatches.Count > 0 && rgxMatches[0].Groups.Count == 3) { string fromQuery = rgxMatches[0].Groups[1].Value; string toQuery = rgxMatches[0].Groups[2].Value; return(RedirectToAction("JumpRoutes", "Universe", new { fromQuery = fromQuery, toQuery = toQuery })); } } int count = -1; // -1 at the end implies that the query was not provided List <Region_V_Row> regions = new List <Region_V_Row>(); List <Constellation_V_Row> constellations = new List <Constellation_V_Row>(); List <SolarSystem_V_Row> solarSystems = new List <SolarSystem_V_Row>(); List <Station_V_Row> stations = new List <Station_V_Row>(); List <ItemType_V_Row> itemTypes = new List <ItemType_V_Row>(); List <CharacterDataModel> characters = new List <CharacterDataModel>(); if (!String.IsNullOrWhiteSpace(query)) { // Attempt to parse as int to check for specific id searches that are not broad int id = 0; Int32.TryParse(query, out id); if (id > 0) { try { Character_Row character = _DBService.GetCharacterPublicInfo(id); //var characterApi = await _ESIClient.Character.GetCharacterPublicInfoV4Async(id); characters.Add(new CharacterDataModel() { Id = id, Character = character }); } catch (Exception e) { // Do nothing. Character isn't valid } regions = new List <Region_V_Row>() { _DBService.GetRegion(id) }; constellations = new List <Constellation_V_Row>() { _DBService.GetConstellation(id) }; solarSystems = new List <SolarSystem_V_Row>() { _DBService.GetSolarSystem(id) }; stations = new List <Station_V_Row>() { _DBService.GetStation(id) }; } else // For services that do not support id search { // Search Universe regions = _DBService.SearchRegions(query); constellations = _DBService.SearchConstellations(query); solarSystems = _DBService.SearchSolarSystems(query); stations = _DBService.SearchStations(query); // Search Item Types itemTypes = _DBService.SearchItemTypes(query); // Search API try { AuthDTO auth = GetAuth(_ESIClient); _Log.LogDebug(String.Format("Logged in to retrieve Character Info for Character Id: {0}", auth.CharacterId)); // TODO: Support all available search categories (agent, alliance, character, constellation, corporation, faction, inventory_type, region, solar_system, station, structure) //https://esi.evetech.net/ui#/Search/get_characters_character_id_search var searchApi = await _ESIClient.Search.SearchCharacterV3Async(auth, new List <string>() { "character" }, query); var searchApiModel = searchApi.Model; // Process Characters List <int> characterIds = searchApiModel.Character; for (int x = 0; x < characterIds.Count; x++) { if (x == 5) { break; // Only do the first 5 } int characterId = characterIds[x]; Character_Row characterFromSearch = _DBService.GetCharacterPublicInfo(characterId); //var characterIdSearch = await _ESIClient.Character.GetCharacterPublicInfoV4Async(characterId); characters.Add(new CharacterDataModel() { Id = characterId, Character = characterFromSearch }); } } catch (Exception e) { // Not logged in, won't bother searching } } count = regions.Count() + constellations.Count() + solarSystems.Count() + stations.Count() + itemTypes.Count() + characters.Count(); } var model = new SearchResultsPageViewModel { Query = query, ResultCount = count, Regions = regions, Constellations = constellations, SolarSystems = solarSystems, Stations = stations, ItemTypes = itemTypes, Characters = characters }; return(View(model)); }