diff --git a/NuciSearch.UnitTests/Services/SearchServiceTests.cs b/NuciSearch.UnitTests/Services/SearchServiceTests.cs index ac9bf9b..8c2ba6e 100644 --- a/NuciSearch.UnitTests/Services/SearchServiceTests.cs +++ b/NuciSearch.UnitTests/Services/SearchServiceTests.cs @@ -22,1174 +22,902 @@ public void SetUp() [Test] public void GivenEmptyQuery_WhenGettingSearchUrl_ThenReturnsEmptyString() - { - string result = searchService.GetSearchUrl(string.Empty, "auto"); - - Assert.That(result, Is.EqualTo(string.Empty)); - } + => Assert.That( + searchService.GetSearchUrl(string.Empty, "auto"), + Is.Empty); [Test] public void GivenWhitespaceOnlyQuery_WhenGettingSearchUrl_ThenReturnsEmptyString() - { - string result = searchService.GetSearchUrl(" ", "auto"); - - Assert.That(result, Is.EqualTo(string.Empty)); - } + => Assert.That( + searchService.GetSearchUrl(" ", "auto"), + Is.Empty); // ── Search types ────────────────────────────────────────────────────── [Test] public void GivenImagesSearchType_WhenGettingSearchUrl_ThenReturnsDuckDuckGoImagesUrl() - { - string result = searchService.GetSearchUrl("cats", "images"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?iax=images&ia=images&q=cats")); - } + => Assert.That( + searchService.GetSearchUrl("cats", "images"), + Is.EqualTo("https://duckduckgo.com/?iax=images&ia=images&q=cats")); [Test] public void GivenImagesSearchTypeUpperCase_WhenGettingSearchUrl_ThenReturnsDuckDuckGoImagesUrl() - { - string result = searchService.GetSearchUrl("cats", "IMAGES"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?iax=images&ia=images&q=cats")); - } + => Assert.That( + searchService.GetSearchUrl("cats", "IMAGES"), + Is.EqualTo("https://duckduckgo.com/?iax=images&ia=images&q=cats")); [Test] [SetUICulture("ro-RO")] public void GivenMapsSearchType_WhenGettingSearchUrl_ThenReturnsGoogleRoMapsUrl() - { - string result = searchService.GetSearchUrl("london", "maps"); - - Assert.That(result, Is.EqualTo("https://google.ro/maps/search/london")); - } + => Assert.That( + searchService.GetSearchUrl("london", "maps"), + Is.EqualTo("https://google.ro/maps/search/london")); [Test] [SetUICulture("en-GB")] public void GivenMapsSearchType_WhenGettingSearchUrl_ThenReturnsGoogleCoUkMapsUrl() - { - string result = searchService.GetSearchUrl("london", "maps"); - - Assert.That(result, Is.EqualTo("https://google.co.uk/maps/search/london")); - } + => Assert.That( + searchService.GetSearchUrl("london", "maps"), + Is.EqualTo("https://google.co.uk/maps/search/london")); [Test] public void GivenTorrentsSearchType_WhenGettingSearchUrl_ThenReturnsYandexTorrentsUrl() - { - string result = searchService.GetSearchUrl("ubuntu", "torrents"); - - Assert.That(result, Is.EqualTo("https://yandex.com/search/?text=ubuntu%20Torrent")); - } + => Assert.That( + searchService.GetSearchUrl("ubuntu", "torrents"), + Is.EqualTo("https://yandex.com/search/?text=ubuntu%20Torrent")); [Test] public void GivenVideosSearchType_WhenGettingSearchUrl_ThenReturnsYewtubeUrl() - { - string result = searchService.GetSearchUrl("cats", "videos"); - - Assert.That(result, Is.EqualTo("https://yewtu.be/search?q=cats")); - } + => Assert.That( + searchService.GetSearchUrl("cats", "videos"), + Is.EqualTo("https://yewtu.be/search?q=cats")); [Test] public void GivenTextSearchType_WhenGettingSearchUrl_ThenReturnsBraveOrDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("cats", "text"); - - Assert.That(result.StartsWith("https://search.brave.com/search?q=") - || result.StartsWith("https://duckduckgo.com/?q=")); - } + => Assert.That( + searchService.GetSearchUrl("cats", "text"), + Does.StartWith("https://search.brave.com/search?q=") + .Or.StartWith("https://duckduckgo.com/?q=")); [Test] public void GivenSingleWordQuery_WhenGettingSearchUrl_ThenReturnsTextSearchUrl() - { - string result = searchService.GetSearchUrl("cats", "auto"); - - Assert.That(result.StartsWith("https://search.brave.com/search?q=") - || result.StartsWith("https://duckduckgo.com/?q=")); - } + => Assert.That( + searchService.GetSearchUrl("cats", "auto"), + Does.StartWith("https://search.brave.com/search?q=") + .Or.StartWith("https://duckduckgo.com/?q=")); // ── WikiData ────────────────────────────────────────────────────────── [Test] public void GivenWikiDataQuery_WhenGettingSearchUrl_ThenReturnsWikiDataUrl() - { - string result = searchService.GetSearchUrl("Q20717572", "auto"); - - Assert.That(result, Is.EqualTo("https://wikidata.org/wiki/Q20717572")); - } + => Assert.That( + searchService.GetSearchUrl("Q20717572", "auto"), + Is.EqualTo("https://wikidata.org/wiki/Q20717572")); [Test] public void GivenWikiDataQuerySingleDigit_WhenGettingSearchUrl_ThenReturnsWikiDataUrl() - { - string result = searchService.GetSearchUrl("Q1", "auto"); - - Assert.That(result, Is.EqualTo("https://wikidata.org/wiki/Q1")); - } + => Assert.That( + searchService.GetSearchUrl("Q1", "auto"), + Is.EqualTo("https://wikidata.org/wiki/Q1")); [Test] public void GivenLowercaseWikiDataQuery_WhenGettingSearchUrl_ThenReturnsWikiDataUrlUppercased() - { - string result = searchService.GetSearchUrl("q42", "auto"); - - Assert.That(result, Is.EqualTo("https://wikidata.org/wiki/Q42")); - } + => Assert.That( + searchService.GetSearchUrl("q42", "auto"), + Is.EqualTo("https://wikidata.org/wiki/Q42")); [Test] public void GivenWikiDataKeyword_WhenGettingSearchUrl_ThenReturnsWikiDataSearchUrl() - { - string result = searchService.GetSearchUrl("wikidata Douglas Adams", "auto"); - - Assert.That(result, Is.EqualTo("https://wikidata.org/w/index.php?search=Douglas%20Adams")); - } + => Assert.That( + searchService.GetSearchUrl("wikidata Douglas Adams", "auto"), + Is.EqualTo("https://wikidata.org/w/index.php?search=Douglas%20Adams")); [Test] public void GivenWikiDataKeywordUpperCase_WhenGettingSearchUrl_ThenReturnsWikiDataSearchUrl() - { - string result = searchService.GetSearchUrl("WIKIDATA Douglas Adams", "auto"); - - Assert.That(result, Is.EqualTo("https://wikidata.org/w/index.php?search=Douglas%20Adams")); - } + => Assert.That( + searchService.GetSearchUrl("WIKIDATA Douglas Adams", "auto"), + Is.EqualTo("https://wikidata.org/w/index.php?search=Douglas%20Adams")); // ── Jira ────────────────────────────────────────────────────────────── [Test] public void GivenJiraAapQuery_WhenGettingSearchUrl_ThenReturnsJiraUrl() - { - string result = searchService.GetSearchUrl("AAP-123", "auto"); - - Assert.That(result, Is.EqualTo("https://worldpay.atlassian.net/browse/AAP-123")); - } + => Assert.That( + searchService.GetSearchUrl("AAP-123", "auto"), + Is.EqualTo("https://worldpay.atlassian.net/browse/AAP-123")); [Test] public void GivenJiraAvQuery_WhenGettingSearchUrl_ThenReturnsJiraUrl() - { - string result = searchService.GetSearchUrl("AV-456", "auto"); - - Assert.That(result, Is.EqualTo("https://worldpay.atlassian.net/browse/AV-456")); - } + => Assert.That( + searchService.GetSearchUrl("AV-456", "auto"), + Is.EqualTo("https://worldpay.atlassian.net/browse/AV-456")); [Test] public void GivenJiraAndQuery_WhenGettingSearchUrl_ThenReturnsJiraUrl() - { - string result = searchService.GetSearchUrl("AND-789", "auto"); - - Assert.That(result, Is.EqualTo("https://worldpay.atlassian.net/browse/AND-789")); - } + => Assert.That( + searchService.GetSearchUrl("AND-789", "auto"), + Is.EqualTo("https://worldpay.atlassian.net/browse/AND-789")); [Test] public void GivenJiraCpQuery_WhenGettingSearchUrl_ThenReturnsJiraUrl() - { - string result = searchService.GetSearchUrl("CP-1", "auto"); - - Assert.That(result, Is.EqualTo("https://worldpay.atlassian.net/browse/CP-1")); - } + => Assert.That( + searchService.GetSearchUrl("CP-1", "auto"), + Is.EqualTo("https://worldpay.atlassian.net/browse/CP-1")); [Test] public void GivenLowercaseJiraQuery_WhenGettingSearchUrl_ThenReturnsJiraUrlUppercased() - { - string result = searchService.GetSearchUrl("aap-123", "auto"); - - Assert.That(result, Is.EqualTo("https://worldpay.atlassian.net/browse/AAP-123")); - } + => Assert.That( + searchService.GetSearchUrl("aap-123", "auto"), + Is.EqualTo("https://worldpay.atlassian.net/browse/AAP-123")); // ── Rally ───────────────────────────────────────────────────────────── [Test] public void GivenRallyDeQuery_WhenGettingSearchUrl_ThenReturnsRallyUrl() - { - string result = searchService.GetSearchUrl("DE123456", "auto"); - - Assert.That(result, Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=DE123456")); - } + => Assert.That( + searchService.GetSearchUrl("DE123456", "auto"), + Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=DE123456")); [Test] public void GivenRallyFQuery_WhenGettingSearchUrl_ThenReturnsRallyUrl() - { - string result = searchService.GetSearchUrl("F1234567", "auto"); - - Assert.That(result, Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=F1234567")); - } + => Assert.That( + searchService.GetSearchUrl("F1234567", "auto"), + Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=F1234567")); [Test] public void GivenRallyUsQuery_WhenGettingSearchUrl_ThenReturnsRallyUrl() - { - string result = searchService.GetSearchUrl("US12345678", "auto"); - - Assert.That(result, Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=US12345678")); - } + => Assert.That( + searchService.GetSearchUrl("US12345678", "auto"), + Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=US12345678")); [Test] public void GivenRallyDeQueryWith8Digits_WhenGettingSearchUrl_ThenReturnsRallyUrl() - { - string result = searchService.GetSearchUrl("DE12345678", "auto"); - - Assert.That(result, Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=DE12345678")); - } + => Assert.That( + searchService.GetSearchUrl("DE12345678", "auto"), + Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=DE12345678")); [Test] public void GivenRallyFQueryWith6Digits_WhenGettingSearchUrl_ThenReturnsRallyUrl() - { - string result = searchService.GetSearchUrl("F123456", "auto"); - - Assert.That(result, Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=F123456")); - } + => Assert.That( + searchService.GetSearchUrl("F123456", "auto"), + Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=F123456")); [Test] public void GivenRallyUsQueryWith6Digits_WhenGettingSearchUrl_ThenReturnsRallyUrl() - { - string result = searchService.GetSearchUrl("US123456", "auto"); - - Assert.That(result, Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=US123456")); - } + => Assert.That( + searchService.GetSearchUrl("US123456", "auto"), + Is.EqualTo("https://rally1.rallydev.com/#/search?keywords=US123456")); // ── Currency conversion ─────────────────────────────────────────────── [Test] public void GivenCurrencyQuery_WhenGettingSearchUrl_ThenReturnsDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("100 USD in EUR", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=100%20USD%20in%20EUR")); - } + => Assert.That( + searchService.GetSearchUrl("100 USD in EUR", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=100%20USD%20in%20EUR")); [Test] public void GivenCurrencyQueryWithToKeyword_WhenGettingSearchUrl_ThenReturnsDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("200 USD to RON", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=200%20USD%20to%20RON")); - } + => Assert.That( + searchService.GetSearchUrl("200 USD to RON", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=200%20USD%20to%20RON")); [Test] public void GivenCurrencyQueryWithLei_WhenGettingSearchUrl_ThenNormalisesLeiToRon() - { - string result = searchService.GetSearchUrl("100 lei in euro", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=100%20RON%20in%20EUR")); - } + => Assert.That( + searchService.GetSearchUrl("100 lei in euro", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=100%20RON%20in%20EUR")); [Test] public void GivenCurrencyQueryWithDollars_WhenGettingSearchUrl_ThenNormalisesToUsd() - { - string result = searchService.GetSearchUrl("50 dollars in EUR", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=50%20USD%20in%20EUR")); - } + => Assert.That( + searchService.GetSearchUrl("50 dollars in EUR", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=50%20USD%20in%20EUR")); [Test] public void GivenCurrencyQueryWithRomanianInPreposition_WhenGettingSearchUrl_ThenNormalisesIn() - { - string result = searchService.GetSearchUrl("100 RON în EUR", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=100%20RON%20in%20EUR")); - } + => Assert.That( + searchService.GetSearchUrl("100 RON \u00een EUR", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=100%20RON%20in%20EUR")); [Test] public void GivenCurrencyQueryWithEuros_WhenGettingSearchUrl_ThenNormalisesToEur() - { - string result = searchService.GetSearchUrl("50 euros in USD", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=50%20EUR%20in%20USD")); - } + => Assert.That( + searchService.GetSearchUrl("50 euros in USD", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=50%20EUR%20in%20USD")); [Test] public void GivenCurrencyQueryWithEuro_WhenGettingSearchUrl_ThenNormalisesToEur() - { - string result = searchService.GetSearchUrl("200 euro in RON", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=200%20EUR%20in%20RON")); - } + => Assert.That( + searchService.GetSearchUrl("200 euro in RON", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=200%20EUR%20in%20RON")); [Test] public void GivenCurrencyQueryWithLira_WhenGettingSearchUrl_ThenNormalisesToGbp() - { - string result = searchService.GetSearchUrl("100 lira in RON", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=100%20GBP%20in%20RON")); - } + => Assert.That( + searchService.GetSearchUrl("100 lira in RON", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=100%20GBP%20in%20RON")); [Test] public void GivenCurrencyQueryWithDolari_WhenGettingSearchUrl_ThenNormalisesToUsd() - { - string result = searchService.GetSearchUrl("100 dolari in EUR", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=100%20USD%20in%20EUR")); - } + => Assert.That( + searchService.GetSearchUrl("100 dolari in EUR", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=100%20USD%20in%20EUR")); [Test] public void GivenCurrencyQueryWithDecimalAmount_WhenGettingSearchUrl_ThenReturnsDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("61.3 USD in EUR", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=61.3%20USD%20in%20EUR")); - } + => Assert.That( + searchService.GetSearchUrl("61.3 USD in EUR", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=61.3%20USD%20in%20EUR")); [Test] public void GivenCurrencyQueryWithThousandsSeparator_WhenGettingSearchUrl_ThenReturnsDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("1,000 USD in EUR", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=1%2C000%20USD%20in%20EUR")); - } + => Assert.That( + searchService.GetSearchUrl("1,000 USD in EUR", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=1%2C000%20USD%20in%20EUR")); // ── IP address ──────────────────────────────────────────────────────── [Test] public void GivenMyIpAddressQuery_WhenGettingSearchUrl_ThenReturnsDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("my ip address", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=my%20ip%20address")); - } + => Assert.That( + searchService.GetSearchUrl("my ip address", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=my%20ip%20address")); [Test] public void GivenMyIpQuery_WhenGettingSearchUrl_ThenReturnsDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("my ip", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=my%20ip")); - } + => Assert.That( + searchService.GetSearchUrl("my ip", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=my%20ip")); [Test] public void GivenCurrentIpQuery_WhenGettingSearchUrl_ThenReturnsDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("current ip", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=current%20ip")); - } + => Assert.That( + searchService.GetSearchUrl("current ip", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=current%20ip")); [Test] public void GivenCurrentIpAddressQuery_WhenGettingSearchUrl_ThenReturnsDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("current ip address", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=current%20ip%20address")); - } + => Assert.That( + searchService.GetSearchUrl("current ip address", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=current%20ip%20address")); [Test] public void GivenUppercaseMyIpQuery_WhenGettingSearchUrl_ThenReturnsDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("MY IP", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=MY%20IP")); - } + => Assert.That( + searchService.GetSearchUrl("MY IP", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=MY%20IP")); [Test] public void GivenUppercaseCurrentIpQuery_WhenGettingSearchUrl_ThenReturnsDuckDuckGoUrl() - { - string result = searchService.GetSearchUrl("CURRENT IP", "auto"); - - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?q=CURRENT%20IP")); - } + => Assert.That( + searchService.GetSearchUrl("CURRENT IP", "auto"), + Is.EqualTo("https://duckduckgo.com/?q=CURRENT%20IP")); // ── Keyword redirects ───────────────────────────────────────────────── [Test] public void GivenAliExpressKeyword_WhenGettingSearchUrl_ThenReturnsAliExpressUrl() - { - string result = searchService.GetSearchUrl("aliexpress blue shoes", "auto"); - - Assert.That(result, Is.EqualTo("https://www.aliexpress.com/w/wholesale-blue-shoes.html?spm=a2g0o.detail.search.0")); - } + => Assert.That( + searchService.GetSearchUrl("aliexpress blue shoes", "auto"), + Is.EqualTo( + "https://www.aliexpress.com/w/wholesale-blue-shoes.html" + + "?spm=a2g0o.detail.search.0")); [Test] public void GivenAltexKeyword_WhenGettingSearchUrl_ThenReturnsAltexUrl() - { - string result = searchService.GetSearchUrl("altex laptop", "auto"); - - Assert.That(result, Is.EqualTo("https://altex.ro/cauta/?q=laptop")); - } + => Assert.That( + searchService.GetSearchUrl("altex laptop", "auto"), + Is.EqualTo("https://altex.ro/cauta/?q=laptop")); [Test] public void GivenAppstoreKeyword_WhenGettingSearchUrl_ThenReturnsAppStoreUrl() - { - string result = searchService.GetSearchUrl("appstore spotify", "auto"); - - Assert.That(result, Is.EqualTo("https://apple.com/uk/search/spotify?src=globalnav")); - } + => Assert.That( + searchService.GetSearchUrl("appstore spotify", "auto"), + Is.EqualTo("https://apple.com/uk/search/spotify?src=globalnav")); [Test] public void GivenArchWikiKeyword_WhenGettingSearchUrl_ThenReturnsArchWikiUrl() - { - string result = searchService.GetSearchUrl("arch wiki bluetooth", "auto"); - - Assert.That(result, Is.EqualTo("https://wiki.archlinux.org/index.php?search=bluetooth")); - } + => Assert.That( + searchService.GetSearchUrl("arch wiki bluetooth", "auto"), + Is.EqualTo("https://wiki.archlinux.org/index.php?search=bluetooth")); [Test] public void GivenAuchanKeyword_WhenGettingSearchUrl_ThenReturnsAuchanUrl() - { - string result = searchService.GetSearchUrl("auchan lapte", "auto"); - - Assert.That(result, Is.EqualTo("https://auchan.ro/lapte")); - } + => Assert.That( + searchService.GetSearchUrl("auchan lapte", "auto"), + Is.EqualTo("https://auchan.ro/lapte")); [Test] public void GivenAudibleKeyword_WhenGettingSearchUrl_ThenReturnsAudibleUrl() - { - string result = searchService.GetSearchUrl("audible dune", "auto"); - - Assert.That(result, Is.EqualTo("https://audible.com/search?advsearchKeywords=dune")); - } + => Assert.That( + searchService.GetSearchUrl("audible dune", "auto"), + Is.EqualTo("https://audible.com/search?advsearchKeywords=dune")); [Test] public void GivenCarturestiKeyword_WhenGettingSearchUrl_ThenReturnsCarturestiUrl() - { - string result = searchService.GetSearchUrl("carturesti dune", "auto"); - - Assert.That(result, Is.EqualTo("https://carturesti.ro/product/search/dune")); - } + => Assert.That( + searchService.GetSearchUrl("carturesti dune", "auto"), + Is.EqualTo("https://carturesti.ro/product/search/dune")); [Test] public void GivenDecathlonKeyword_WhenGettingSearchUrl_ThenReturnsDecathlonUrl() - { - string result = searchService.GetSearchUrl("decathlon bike", "auto"); - - Assert.That(result, Is.EqualTo("https://decathlon.ro/search?Ntt=bike")); - } + => Assert.That( + searchService.GetSearchUrl("decathlon bike", "auto"), + Is.EqualTo("https://decathlon.ro/search?Ntt=bike")); [Test] public void GivenDedemanKeyword_WhenGettingSearchUrl_ThenReturnsDedemanUrl() - { - string result = searchService.GetSearchUrl("dedeman vopsea", "auto"); - - Assert.That(result, Is.EqualTo("https://dedeman.ro/ro/catalogsearch/result/v2?q=vopsea")); - } + => Assert.That( + searchService.GetSearchUrl("dedeman vopsea", "auto"), + Is.EqualTo("https://dedeman.ro/ro/catalogsearch/result/v2?q=vopsea")); [Test] public void GivenDexKeyword_WhenGettingSearchUrl_ThenReturnsDexOnlineUrl() - { - string result = searchService.GetSearchUrl("dex pisica", "auto"); - - Assert.That(result, Is.EqualTo("https://dexonline.ro/definitie/pisica")); - } + => Assert.That( + searchService.GetSearchUrl("dex pisica", "auto"), + Is.EqualTo("https://dexonline.ro/definitie/pisica")); [Test] public void GivenDigi24Keyword_WhenGettingSearchUrl_ThenReturnsDigi24Url() - { - string result = searchService.GetSearchUrl("digi24 alegeri", "auto"); - - Assert.That(result, Is.EqualTo("https://digi24.ro/cautare?q=alegeri")); - } + => Assert.That( + searchService.GetSearchUrl("digi24 alegeri", "auto"), + Is.EqualTo("https://digi24.ro/cautare?q=alegeri")); [Test] public void GivenEbayKeyword_WhenGettingSearchUrl_ThenReturnsEbayUrl() - { - string result = searchService.GetSearchUrl("ebay laptop", "auto"); - - Assert.That(result, Is.EqualTo("https://ebay.com/sch/i.html?_nkw=laptop")); - } + => Assert.That( + searchService.GetSearchUrl("ebay laptop", "auto"), + Is.EqualTo("https://ebay.com/sch/i.html?_nkw=laptop")); [Test] public void GivenEmagKeyword_WhenGettingSearchUrl_ThenReturnsEmagUrl() - { - string result = searchService.GetSearchUrl("emag laptop", "auto"); - - Assert.That(result, Is.EqualTo("https://emag.ro/search/laptop")); - } + => Assert.That( + searchService.GetSearchUrl("emag laptop", "auto"), + Is.EqualTo("https://emag.ro/search/laptop")); [Test] public void GivenEvomagKeyword_WhenGettingSearchUrl_ThenReturnsEvomagUrl() - { - string result = searchService.GetSearchUrl("evomag ssd", "auto"); - - Assert.That(result, Is.EqualTo("https://evomag.ro/?sn.q=ssd")); - } + => Assert.That( + searchService.GetSearchUrl("evomag ssd", "auto"), + Is.EqualTo("https://evomag.ro/?sn.q=ssd")); [Test] public void GivenFacebookKeyword_WhenGettingSearchUrl_ThenReturnsTextSearchWithFacebookSite() - { - string result = searchService.GetSearchUrl("facebook cats", "auto"); - - Assert.That(result.Contains("site%3Afacebook.com%20cats")); - } + => Assert.That( + searchService.GetSearchUrl("facebook cats", "auto"), + Does.Contain("site%3Afacebook.com%20cats")); [Test] public void GivenFdroidKeyword_WhenGettingSearchUrl_ThenReturnsFdroidUrl() - { - string result = searchService.GetSearchUrl("fdroid vlc", "auto"); - - Assert.That(result, Is.EqualTo("https://search.f-droid.org/?q=vlc")); - } + => Assert.That( + searchService.GetSearchUrl("fdroid vlc", "auto"), + Is.EqualTo("https://search.f-droid.org/?q=vlc")); [Test] public void GivenFDroidHyphenatedKeyword_WhenGettingSearchUrl_ThenReturnsFdroidUrl() - { - string result = searchService.GetSearchUrl("f-droid vlc", "auto"); - - Assert.That(result, Is.EqualTo("https://search.f-droid.org/?q=vlc")); - } + => Assert.That( + searchService.GetSearchUrl("f-droid vlc", "auto"), + Is.EqualTo("https://search.f-droid.org/?q=vlc")); [Test] [SetUICulture("en-GB")] public void GivenFirefoxExtensionKeyword_WhenGettingSearchUrl_ThenReturnsFirefoxExtensionsEnGbUrl() - { - string result = searchService.GetSearchUrl("firefox extension ublock", "auto"); - - Assert.That(result, Is.EqualTo("https://addons.mozilla.org/en-GB/firefox/search/?q=ublock")); - } + => Assert.That( + searchService.GetSearchUrl("firefox extension ublock", "auto"), + Is.EqualTo("https://addons.mozilla.org/en-GB/firefox/search/?q=ublock")); [Test] [SetUICulture("ro-RO")] public void GivenFirefoxExtensionKeyword_WhenGettingSearchUrl_ThenReturnsFirefoxExtensionsRoUrl() - { - string result = searchService.GetSearchUrl("firefox extension ublock", "auto"); - - Assert.That(result, Is.EqualTo("https://addons.mozilla.org/ro/firefox/search/?q=ublock")); - } + => Assert.That( + searchService.GetSearchUrl("firefox extension ublock", "auto"), + Is.EqualTo("https://addons.mozilla.org/ro/firefox/search/?q=ublock")); [Test] public void GivenFlancoKeyword_WhenGettingSearchUrl_ThenReturnsFlancoUrl() - { - string result = searchService.GetSearchUrl("flanco tv", "auto"); - - Assert.That(result, Is.EqualTo("https://flanco.ro/catalogsearch/result/?q=tv")); - } + => Assert.That( + searchService.GetSearchUrl("flanco tv", "auto"), + Is.EqualTo("https://flanco.ro/catalogsearch/result/?q=tv")); [Test] public void GivenFlathubKeyword_WhenGettingSearchUrl_ThenReturnsFlathubUrl() - { - string result = searchService.GetSearchUrl("flathub vlc", "auto"); - - Assert.That(result, Is.EqualTo("https://flathub.org/apps/search/vlc")); - } + => Assert.That( + searchService.GetSearchUrl("flathub vlc", "auto"), + Is.EqualTo("https://flathub.org/apps/search/vlc")); [Test] public void GivenFlipRoKeyword_WhenGettingSearchUrl_ThenReturnsFlipRoUrl() - { - string result = searchService.GetSearchUrl("flip.ro laptop", "auto"); - - Assert.That(result, Is.EqualTo("https://flip.ro/magazin/?search=laptop")); - } + => Assert.That( + searchService.GetSearchUrl("flip.ro laptop", "auto"), + Is.EqualTo("https://flip.ro/magazin/?search=laptop")); [Test] public void GivenG2aKeyword_WhenGettingSearchUrl_ThenReturnsG2aUrl() - { - string result = searchService.GetSearchUrl("g2a cyberpunk", "auto"); - - Assert.That(result, Is.EqualTo("https://g2a.com/search?query=cyberpunk")); - } + => Assert.That( + searchService.GetSearchUrl("g2a cyberpunk", "auto"), + Is.EqualTo("https://g2a.com/search?query=cyberpunk")); [Test] public void GivenGitHubKeyword_WhenGettingSearchUrl_ThenReturnsTextSearchWithGitHubSite() - { - string result = searchService.GetSearchUrl("github dotnet runtime", "auto"); - - Assert.That(result.Contains("site%3Agithub.com%20dotnet%20runtime")); - } + => Assert.That( + searchService.GetSearchUrl("github dotnet runtime", "auto"), + Does.Contain("site%3Agithub.com%20dotnet%20runtime")); [Test] public void GivenGogKeyword_WhenGettingSearchUrl_ThenReturnsGogUrl() - { - string result = searchService.GetSearchUrl("gog witcher", "auto"); - - Assert.That(result, Is.EqualTo("https://gog.com/en/games?query=witcher")); - } + => Assert.That( + searchService.GetSearchUrl("gog witcher", "auto"), + Is.EqualTo("https://gog.com/en/games?query=witcher")); [Test] public void GivenHornbachKeyword_WhenGettingSearchUrl_ThenReturnsHornbachUrl() - { - string result = searchService.GetSearchUrl("hornbach vopsea", "auto"); - - Assert.That(result, Is.EqualTo("https://hornbach.ro/s/vopsea")); - } + => Assert.That( + searchService.GetSearchUrl("hornbach vopsea", "auto"), + Is.EqualTo("https://hornbach.ro/s/vopsea")); [Test] [SetUICulture("ro-RO")] public void GivenIkeaKeyword_WhenGettingSearchUrl_ThenReturnsIkeaRoUrl() - { - string result = searchService.GetSearchUrl("ikea scaun", "auto"); - - Assert.That(result, Is.EqualTo("https://ikea.com/ro/ro/search/?q=scaun")); - } + => Assert.That( + searchService.GetSearchUrl("ikea scaun", "auto"), + Is.EqualTo("https://ikea.com/ro/ro/search/?q=scaun")); [Test] [SetUICulture("en-GB")] public void GivenIkeaKeyword_WhenGettingSearchUrl_ThenReturnsIkeaGbUrl() - { - string result = searchService.GetSearchUrl("ikea chair", "auto"); - - Assert.That(result, Is.EqualTo("https://ikea.com/gb/en/search/?q=chair")); - } + => Assert.That( + searchService.GetSearchUrl("ikea chair", "auto"), + Is.EqualTo("https://ikea.com/gb/en/search/?q=chair")); [Test] public void GivenImdbKeyword_WhenGettingSearchUrl_ThenReturnsImdbUrl() - { - string result = searchService.GetSearchUrl("imdb inception", "auto"); - - Assert.That(result, Is.EqualTo("https://libremdb.iket.me/find?q=inception")); - } + => Assert.That( + searchService.GetSearchUrl("imdb inception", "auto"), + Is.EqualTo("https://libremdb.iket.me/find?q=inception")); [Test] public void GivenInstagramKeyword_WhenGettingSearchUrl_ThenReturnsInstagramUrl() - { - string result = searchService.GetSearchUrl("instagram cats", "auto"); - - Assert.That(result, Is.EqualTo("https://instagram.com/popular/cats")); - } + => Assert.That( + searchService.GetSearchUrl("instagram cats", "auto"), + Is.EqualTo("https://instagram.com/popular/cats")); [Test] public void GivenJyskKeyword_WhenGettingSearchUrl_ThenReturnsJyskUrl() - { - string result = searchService.GetSearchUrl("jysk scaun", "auto"); - - Assert.That(result, Is.EqualTo("https://jysk.ro/search?query=scaun")); - } + => Assert.That( + searchService.GetSearchUrl("jysk scaun", "auto"), + Is.EqualTo("https://jysk.ro/search?query=scaun")); [Test] public void GivenLeroyMerlinKeyword_WhenGettingSearchUrl_ThenReturnsLeroyMerlinUrl() - { - string result = searchService.GetSearchUrl("leroy merlin vopsea", "auto"); - - Assert.That(result, Is.EqualTo("https://leroymerlin.ro/produse/search/vopsea")); - } + => Assert.That( + searchService.GetSearchUrl("leroy merlin vopsea", "auto"), + Is.EqualTo("https://leroymerlin.ro/produse/search/vopsea")); [Test] public void GivenLidlKeyword_WhenGettingSearchUrl_ThenReturnsLidlUrl() - { - string result = searchService.GetSearchUrl("lidl cafea", "auto"); - - Assert.That(result, Is.EqualTo("https://lidl.ro/q/search?q=cafea")); - } + => Assert.That( + searchService.GetSearchUrl("lidl cafea", "auto"), + Is.EqualTo("https://lidl.ro/q/search?q=cafea")); [Test] public void GivenLinkedinKeyword_WhenGettingSearchUrl_ThenReturnsLinkedinUrl() - { - string result = searchService.GetSearchUrl("linkedin developer", "auto"); - - Assert.That(result, Is.EqualTo("https://linkedin.com/search/results/all/?keywords=developer")); - } + => Assert.That( + searchService.GetSearchUrl("linkedin developer", "auto"), + Is.EqualTo("https://linkedin.com/search/results/all/?keywords=developer")); [Test] public void GivenModDbKeyword_WhenGettingSearchUrl_ThenReturnsModDbUrl() - { - string result = searchService.GetSearchUrl("moddb half-life", "auto"); - - Assert.That(result, Is.EqualTo("https://moddb.com/search?q=half-life")); - } + => Assert.That( + searchService.GetSearchUrl("moddb half-life", "auto"), + Is.EqualTo("https://moddb.com/search?q=half-life")); [Test] public void GivenMcWikiKeyword_WhenGettingSearchUrl_ThenReturnsMinecraftWikiUrl() - { - string result = searchService.GetSearchUrl("mc wiki creeper", "auto"); - - Assert.That(result, Is.EqualTo("https://minecraft.wiki/?search=creeper")); - } + => Assert.That( + searchService.GetSearchUrl("mc wiki creeper", "auto"), + Is.EqualTo("https://minecraft.wiki/?search=creeper")); [Test] public void GivenMinecraftWikiKeyword_WhenGettingSearchUrl_ThenReturnsMinecraftWikiUrl() - { - string result = searchService.GetSearchUrl("minecraft wiki creeper", "auto"); - - Assert.That(result, Is.EqualTo("https://minecraft.wiki/?search=creeper")); - } + => Assert.That( + searchService.GetSearchUrl("minecraft wiki creeper", "auto"), + Is.EqualTo("https://minecraft.wiki/?search=creeper")); [Test] public void GivenMcHeadKeyword_WhenGettingSearchUrl_ThenReturnsMinecraftHeadsUrl() - { - string result = searchService.GetSearchUrl("mc head dragon", "auto"); - - Assert.That(result, Is.EqualTo("https://minecraft-heads.com/custom-heads/search?searchterm=dragon")); - } + => Assert.That( + searchService.GetSearchUrl("mc head dragon", "auto"), + Is.EqualTo( + "https://minecraft-heads.com/custom-heads/search?searchterm=dragon")); [Test] public void GivenMinecraftHeadKeyword_WhenGettingSearchUrl_ThenReturnsMinecraftHeadsUrl() - { - string result = searchService.GetSearchUrl("minecraft head dragon", "auto"); - - Assert.That(result, Is.EqualTo("https://minecraft-heads.com/custom-heads/search?searchterm=dragon")); - } + => Assert.That( + searchService.GetSearchUrl("minecraft head dragon", "auto"), + Is.EqualTo( + "https://minecraft-heads.com/custom-heads/search?searchterm=dragon")); [Test] public void GivenMcSchematicKeyword_WhenGettingSearchUrl_ThenReturnsPlanetMinecraftSchematicsUrl() - { - string result = searchService.GetSearchUrl("mc schematic castle", "auto"); - - Assert.That(result, Is.EqualTo("https://planetminecraft.com/projects/?keywords=castle")); - } + => Assert.That( + searchService.GetSearchUrl("mc schematic castle", "auto"), + Is.EqualTo("https://planetminecraft.com/projects/?keywords=castle")); [Test] public void GivenMinecraftSchematicKeyword_WhenGettingSearchUrl_ThenReturnsPlanetMinecraftSchematicsUrl() - { - string result = searchService.GetSearchUrl("minecraft schematic castle", "auto"); - - Assert.That(result, Is.EqualTo("https://planetminecraft.com/projects/?keywords=castle")); - } + => Assert.That( + searchService.GetSearchUrl("minecraft schematic castle", "auto"), + Is.EqualTo("https://planetminecraft.com/projects/?keywords=castle")); [Test] public void GivenNameMcKeyword_WhenGettingSearchUrl_ThenReturnsNameMcUrl() - { - string result = searchService.GetSearchUrl("namemc Notch", "auto"); - - Assert.That(result, Is.EqualTo("https://namemc.com/search?q=Notch")); - } + => Assert.That( + searchService.GetSearchUrl("namemc Notch", "auto"), + Is.EqualTo("https://namemc.com/search?q=Notch")); [Test] public void GivenNetflixKeyword_WhenGettingSearchUrl_ThenReturnsNetflixUrl() - { - string result = searchService.GetSearchUrl("netflix stranger things", "auto"); - - Assert.That(result, Is.EqualTo("https://netflix.com/search?q=stranger%20things")); - } + => Assert.That( + searchService.GetSearchUrl("netflix stranger things", "auto"), + Is.EqualTo("https://netflix.com/search?q=stranger%20things")); [Test] public void GivenNexusModsKeyword_WhenGettingSearchUrl_ThenReturnsNexusModsUrl() - { - string result = searchService.GetSearchUrl("nexusmods skyrim", "auto"); - - Assert.That(result, Is.EqualTo("https://nexusmods.com/search?keyword=skyrim")); - } + => Assert.That( + searchService.GetSearchUrl("nexusmods skyrim", "auto"), + Is.EqualTo("https://nexusmods.com/search?keyword=skyrim")); [Test] public void GivenOdyseeKeyword_WhenGettingSearchUrl_ThenReturnsOdyseeUrl() - { - string result = searchService.GetSearchUrl("odysee cooking", "auto"); - - Assert.That(result, Is.EqualTo("https://odysee.com/$/search?q=cooking")); - } + => Assert.That( + searchService.GetSearchUrl("odysee cooking", "auto"), + Is.EqualTo("https://odysee.com/$/search?q=cooking")); [Test] public void GivenOlxKeyword_WhenGettingSearchUrl_ThenReturnsOlxUrl() - { - string result = searchService.GetSearchUrl("olx laptop", "auto"); - - Assert.That(result, Is.EqualTo("https://olx.ro/d/oferte/q-laptop")); - } + => Assert.That( + searchService.GetSearchUrl("olx laptop", "auto"), + Is.EqualTo("https://olx.ro/d/oferte/q-laptop")); [Test] public void GivenPcGarageKeyword_WhenGettingSearchUrl_ThenReturnsPcGarageUrl() - { - string result = searchService.GetSearchUrl("pcgarage ssd", "auto"); - - Assert.That(result, Is.EqualTo("https://pcgarage.ro/cauta/ssd")); - } + => Assert.That( + searchService.GetSearchUrl("pcgarage ssd", "auto"), + Is.EqualTo("https://pcgarage.ro/cauta/ssd")); [Test] public void GivenPinterestKeyword_WhenGettingSearchUrl_ThenReturnsPinterestUrl() - { - string result = searchService.GetSearchUrl("pinterest cats", "auto"); - - Assert.That(result, Is.EqualTo("https://pinterest.com/search/pins/?q=cats")); - } + => Assert.That( + searchService.GetSearchUrl("pinterest cats", "auto"), + Is.EqualTo("https://pinterest.com/search/pins/?q=cats")); [Test] public void GivenPlanetMinecraftKeyword_WhenGettingSearchUrl_ThenReturnsPlanetMinecraftUrl() - { - string result = searchService.GetSearchUrl("planet minecraft castle", "auto"); - - Assert.That(result, Is.EqualTo("https://planetminecraft.com/resources/?keywords=castle")); - } + => Assert.That( + searchService.GetSearchUrl("planet minecraft castle", "auto"), + Is.EqualTo("https://planetminecraft.com/resources/?keywords=castle")); [Test] public void GivenPlayStoreKeyword_WhenGettingSearchUrl_ThenReturnsPlayStoreUrl() - { - string result = searchService.GetSearchUrl("play store spotify", "auto"); - - Assert.That(result, Is.EqualTo("https://play.google.com/store/search?q=spotify")); - } + => Assert.That( + searchService.GetSearchUrl("play store spotify", "auto"), + Is.EqualTo("https://play.google.com/store/search?q=spotify")); [Test] public void GivenPlaystoreKeyword_WhenGettingSearchUrl_ThenReturnsPlayStoreUrl() - { - string result = searchService.GetSearchUrl("playstore spotify", "auto"); - - Assert.That(result, Is.EqualTo("https://play.google.com/store/search?q=spotify")); - } + => Assert.That( + searchService.GetSearchUrl("playstore spotify", "auto"), + Is.EqualTo("https://play.google.com/store/search?q=spotify")); [Test] public void GivenPlexKeyword_WhenGettingSearchUrl_ThenReturnsPlexUrl() - { - string result = searchService.GetSearchUrl("plex inception", "auto"); - - Assert.That(result, Is.EqualTo("https://app.plex.tv/desktop/#!/search?pivot=top&query=inception")); - } + => Assert.That( + searchService.GetSearchUrl("plex inception", "auto"), + Is.EqualTo( + "https://app.plex.tv/desktop/#!/search?pivot=top&query=inception")); [Test] public void GivenProtonDbKeyword_WhenGettingSearchUrl_ThenReturnsProtonDbUrl() - { - string result = searchService.GetSearchUrl("protondb cyberpunk", "auto"); - - Assert.That(result, Is.EqualTo("https://protondb.com/search?q=cyberpunk")); - } + => Assert.That( + searchService.GetSearchUrl("protondb cyberpunk", "auto"), + Is.EqualTo("https://protondb.com/search?q=cyberpunk")); [Test] public void GivenRedditKeyword_WhenGettingSearchUrl_ThenReturnsRedlibUrl() - { - string result = searchService.GetSearchUrl("reddit cats", "auto"); - - Assert.That(result.Contains("search?q=cats")); - } + => Assert.That( + searchService.GetSearchUrl("reddit cats", "auto"), + Does.Contain("search?q=cats")); [Test] public void GivenRtingsKeyword_WhenGettingSearchUrl_ThenReturnsRtingsUrl() - { - string result = searchService.GetSearchUrl("rtings tv", "auto"); - - Assert.That(result, Is.EqualTo("https://rtings.com/search?q=tv")); - } + => Assert.That( + searchService.GetSearchUrl("rtings tv", "auto"), + Is.EqualTo("https://rtings.com/search?q=tv")); [Test] public void GivenSinsayKeyword_WhenGettingSearchUrl_ThenReturnsSinsayUrl() - { - string result = searchService.GetSearchUrl("sinsay dress", "auto"); - - Assert.That(result, Is.EqualTo("https://sinsay.com/ro/ro/?query=dress")); - } + => Assert.That( + searchService.GetSearchUrl("sinsay dress", "auto"), + Is.EqualTo("https://sinsay.com/ro/ro/?query=dress")); [Test] public void GivenSpigotKeyword_WhenGettingSearchUrl_ThenReturnsSpigotUrl() - { - string result = searchService.GetSearchUrl("spigot worldedit", "auto"); - - Assert.That(result, Is.EqualTo("https://spigotmc.org/search/294718421/?q=worldedit&o=relevance")); - } + => Assert.That( + searchService.GetSearchUrl("spigot worldedit", "auto"), + Is.EqualTo( + "https://spigotmc.org/search/294718421/?q=worldedit&o=relevance")); [Test] public void GivenSpyshopKeyword_WhenGettingSearchUrl_ThenReturnsSpyShopUrl() - { - string result = searchService.GetSearchUrl("spyshop camera", "auto"); - - Assert.That(result, Is.EqualTo("https://spy-shop.ro/catalogsearch/result/?q=camera&o=relevance")); - } + => Assert.That( + searchService.GetSearchUrl("spyshop camera", "auto"), + Is.EqualTo( + "https://spy-shop.ro/catalogsearch/result/?q=camera&o=relevance")); [Test] public void GivenSpyShopHyphenatedKeyword_WhenGettingSearchUrl_ThenReturnsSpyShopUrl() - { - string result = searchService.GetSearchUrl("spy-shop camera", "auto"); - - Assert.That(result, Is.EqualTo("https://spy-shop.ro/catalogsearch/result/?q=camera&o=relevance")); - } + => Assert.That( + searchService.GetSearchUrl("spy-shop camera", "auto"), + Is.EqualTo( + "https://spy-shop.ro/catalogsearch/result/?q=camera&o=relevance")); [Test] public void GivenSteamDbKeyword_WhenGettingSearchUrl_ThenReturnsSteamDbUrl() - { - string result = searchService.GetSearchUrl("steamdb half-life", "auto"); - - Assert.That(result, Is.EqualTo("https://steamdb.info/search/?a=all&q=half-life")); - } + => Assert.That( + searchService.GetSearchUrl("steamdb half-life", "auto"), + Is.EqualTo("https://steamdb.info/search/?a=all&q=half-life")); [Test] public void GivenTripadvisorKeyword_WhenGettingSearchUrl_ThenReturnsTripadvisorUrl() - { - string result = searchService.GetSearchUrl("tripadvisor paris", "auto"); - - Assert.That(result, Is.EqualTo("https://tripadvisor.com/Search?q=paris")); - } + => Assert.That( + searchService.GetSearchUrl("tripadvisor paris", "auto"), + Is.EqualTo("https://tripadvisor.com/Search?q=paris")); [Test] public void GivenTvDbKeyword_WhenGettingSearchUrl_ThenReturnsTvDbUrl() - { - string result = searchService.GetSearchUrl("tvdb breaking bad", "auto"); - - Assert.That(result, Is.EqualTo("https://thetvdb.com/search?query=breaking%20bad")); - } + => Assert.That( + searchService.GetSearchUrl("tvdb breaking bad", "auto"), + Is.EqualTo("https://thetvdb.com/search?query=breaking%20bad")); [Test] public void GivenTheTvDbKeyword_WhenGettingSearchUrl_ThenReturnsTvDbUrl() - { - string result = searchService.GetSearchUrl("thetvdb breaking bad", "auto"); - - Assert.That(result, Is.EqualTo("https://thetvdb.com/search?query=breaking%20bad")); - } + => Assert.That( + searchService.GetSearchUrl("thetvdb breaking bad", "auto"), + Is.EqualTo("https://thetvdb.com/search?query=breaking%20bad")); [Test] public void GivenUespKeyword_WhenGettingSearchUrl_ThenReturnsUespUrl() - { - string result = searchService.GetSearchUrl("uesp dragonborn", "auto"); - - Assert.That(result, Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=dragonborn")); - } + => Assert.That( + searchService.GetSearchUrl("uesp dragonborn", "auto"), + Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=dragonborn")); [Test] public void GivenSkyrimWikiKeyword_WhenGettingSearchUrl_ThenReturnsUespUrl() - { - string result = searchService.GetSearchUrl("skyrim wiki dragonborn", "auto"); - - Assert.That(result, Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=dragonborn")); - } + => Assert.That( + searchService.GetSearchUrl("skyrim wiki dragonborn", "auto"), + Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=dragonborn")); [Test] public void GivenEsoWikiKeyword_WhenGettingSearchUrl_ThenReturnsUespUrl() - { - string result = searchService.GetSearchUrl("eso wiki lorebook", "auto"); - - Assert.That(result, Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=lorebook")); - } + => Assert.That( + searchService.GetSearchUrl("eso wiki lorebook", "auto"), + Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=lorebook")); [Test] public void GivenElderScrollsWikiKeyword_WhenGettingSearchUrl_ThenReturnsUespUrl() - { - string result = searchService.GetSearchUrl("elder scrolls wiki dwemer", "auto"); - - Assert.That(result, Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=dwemer")); - } + => Assert.That( + searchService.GetSearchUrl("elder scrolls wiki dwemer", "auto"), + Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=dwemer")); [Test] public void GivenVintedKeyword_WhenGettingSearchUrl_ThenReturnsVintedUrl() - { - string result = searchService.GetSearchUrl("vinted jacket", "auto"); - - Assert.That(result, Is.EqualTo("https://vinted.com/catalog?search_text=jacket")); - } + => Assert.That( + searchService.GetSearchUrl("vinted jacket", "auto"), + Is.EqualTo("https://vinted.com/catalog?search_text=jacket")); [Test] public void GivenWikipediaKeyword_WhenGettingSearchUrl_ThenReturnsWikipediaInstanceUrl() - { - string result = searchService.GetSearchUrl("wikipedia cats", "auto"); - - Assert.That(result.Contains("wikipedia.org") || result.Contains("wikiless")); - } + => Assert.That( + searchService.GetSearchUrl("wikipedia cats", "auto"), + Does.Contain("wikipedia.org").Or.Contain("wikiless")); [Test] [SetUICulture("ro-RO")] public void GivenWikipediaKeywordAndRoRoCulture_WhenGettingSearchUrl_ThenReturnsRomanianWikipediaUrl() - { - string result = searchService.GetSearchUrl("wikipedia pisica", "auto"); - - Assert.That(result.Contains("ro.wikipedia.org") || result.Contains("wikiless")); - } + => Assert.That( + searchService.GetSearchUrl("wikipedia pisica", "auto"), + Does.Contain("ro.wikipedia.org").Or.Contain("wikiless")); [Test] [SetUICulture("en-GB")] public void GivenWikipediaKeywordAndEnGbCulture_WhenGettingSearchUrl_ThenReturnsEnglishWikipediaUrl() - { - string result = searchService.GetSearchUrl("wikipedia cats", "auto"); - - Assert.That(result.Contains("en.wikipedia.org") || result.Contains("wikiless")); - } + => Assert.That( + searchService.GetSearchUrl("wikipedia cats", "auto"), + Does.Contain("en.wikipedia.org").Or.Contain("wikiless")); [Test] public void GivenYoutubeKeyword_WhenGettingSearchUrl_ThenReturnsYewtubeUrl() - { - string result = searchService.GetSearchUrl("youtube cats", "auto"); - - Assert.That(result, Is.EqualTo("https://yewtu.be/search?q=cats")); - } + => Assert.That( + searchService.GetSearchUrl("youtube cats", "auto"), + Is.EqualTo("https://yewtu.be/search?q=cats")); [Test] public void GivenBoobpediaKeyword_WhenGettingSearchUrl_ThenReturnsBoobpediaUrl() - { - string result = searchService.GetSearchUrl("boobpedia elodia", "auto"); - - Assert.That(result, Is.EqualTo("https://boobpedia.com/wiki/index.php?title=Special%3ASearch&search=elodia&go=Go")); - } + => Assert.That( + searchService.GetSearchUrl("boobpedia elodia", "auto"), + Is.EqualTo( + "https://boobpedia.com/wiki/index.php?title=Special%3ASearch" + + "&search=elodia&go=Go")); [Test] [SetUICulture("en-GB")] public void GivenFirefoxExtensionsPluralKeyword_WhenGettingSearchUrl_ThenReturnsFirefoxExtensionsUrl() - { - string result = searchService.GetSearchUrl("firefox extensions ublock", "auto"); - - Assert.That(result, Is.EqualTo("https://addons.mozilla.org/en-GB/firefox/search/?q=ublock")); - } + => Assert.That( + searchService.GetSearchUrl("firefox extensions ublock", "auto"), + Is.EqualTo("https://addons.mozilla.org/en-GB/firefox/search/?q=ublock")); [Test] public void GivenMcHeadsPluralKeyword_WhenGettingSearchUrl_ThenReturnsMinecraftHeadsUrl() - { - string result = searchService.GetSearchUrl("mc heads dragon", "auto"); - - Assert.That(result, Is.EqualTo("https://minecraft-heads.com/custom-heads/search?searchterm=dragon")); - } + => Assert.That( + searchService.GetSearchUrl("mc heads dragon", "auto"), + Is.EqualTo( + "https://minecraft-heads.com/custom-heads/search?searchterm=dragon")); [Test] public void GivenMinecraftHeadsPluralKeyword_WhenGettingSearchUrl_ThenReturnsMinecraftHeadsUrl() - { - string result = searchService.GetSearchUrl("minecraft heads dragon", "auto"); - - Assert.That(result, Is.EqualTo("https://minecraft-heads.com/custom-heads/search?searchterm=dragon")); - } + => Assert.That( + searchService.GetSearchUrl("minecraft heads dragon", "auto"), + Is.EqualTo( + "https://minecraft-heads.com/custom-heads/search?searchterm=dragon")); [Test] public void GivenMcSchematicsPluralKeyword_WhenGettingSearchUrl_ThenReturnsPlanetMinecraftSchematicsUrl() - { - string result = searchService.GetSearchUrl("mc schematics castle", "auto"); - - Assert.That(result, Is.EqualTo("https://planetminecraft.com/projects/?keywords=castle")); - } + => Assert.That( + searchService.GetSearchUrl("mc schematics castle", "auto"), + Is.EqualTo("https://planetminecraft.com/projects/?keywords=castle")); [Test] public void GivenMinecraftSchematicsPluralKeyword_WhenGettingSearchUrl_ThenReturnsPlanetMinecraftSchematicsUrl() - { - string result = searchService.GetSearchUrl("minecraft schematics castle", "auto"); - - Assert.That(result, Is.EqualTo("https://planetminecraft.com/projects/?keywords=castle")); - } + => Assert.That( + searchService.GetSearchUrl("minecraft schematics castle", "auto"), + Is.EqualTo("https://planetminecraft.com/projects/?keywords=castle")); [Test] public void GivenMorrowindWikiKeyword_WhenGettingSearchUrl_ThenReturnsUespUrl() - { - string result = searchService.GetSearchUrl("morrowind wiki dunmer", "auto"); - - Assert.That(result, Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=dunmer")); - } + => Assert.That( + searchService.GetSearchUrl("morrowind wiki dunmer", "auto"), + Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=dunmer")); [Test] public void GivenOblivionWikiKeyword_WhenGettingSearchUrl_ThenReturnsUespUrl() - { - string result = searchService.GetSearchUrl("oblivion wiki daedra", "auto"); - - Assert.That(result, Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=daedra")); - } + => Assert.That( + searchService.GetSearchUrl("oblivion wiki daedra", "auto"), + Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=daedra")); [Test] public void GivenTesWikiKeyword_WhenGettingSearchUrl_ThenReturnsUespUrl() - { - string result = searchService.GetSearchUrl("tes wiki shouts", "auto"); - - Assert.That(result, Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=shouts")); - } + => Assert.That( + searchService.GetSearchUrl("tes wiki shouts", "auto"), + Is.EqualTo("https://en.uesp.net/wiki/Special:Search?search=shouts")); [Test] public void GivenSpyShopRoKeyword_WhenGettingSearchUrl_ThenReturnsSpyShopUrl() - { - string result = searchService.GetSearchUrl("spy-shop.ro camera", "auto"); - - Assert.That(result, Is.EqualTo("https://spy-shop.ro/catalogsearch/result/?q=camera&o=relevance")); - } + => Assert.That( + searchService.GetSearchUrl("spy-shop.ro camera", "auto"), + Is.EqualTo( + "https://spy-shop.ro/catalogsearch/result/?q=camera&o=relevance")); [Test] public void GivenSpyshopRoKeyword_WhenGettingSearchUrl_ThenReturnsSpyShopUrl() - { - string result = searchService.GetSearchUrl("spyshop.ro camera", "auto"); - - Assert.That(result, Is.EqualTo("https://spy-shop.ro/catalogsearch/result/?q=camera&o=relevance")); - } + => Assert.That( + searchService.GetSearchUrl("spyshop.ro camera", "auto"), + Is.EqualTo( + "https://spy-shop.ro/catalogsearch/result/?q=camera&o=relevance")); // ── Domain blacklists ───────────────────────────────────────────────── [Test] public void GivenMinecraftQuery_WhenGettingTextSearchUrl_ThenIncludesFandomBlacklist() - { - string result = searchService.GetSearchUrl("minecraft building", "text"); - - Assert.That(result.Contains("fandom")); - } + => Assert.That( + searchService.GetSearchUrl("minecraft building", "text"), + Does.Contain("fandom")); [Test] public void GivenTerrariaQuery_WhenGettingTextSearchUrl_ThenIncludesArcenservFandomAndNeoseekerBlacklists() - { - string result = searchService.GetSearchUrl("terraria boss", "text"); - - Assert.That(result.Contains("arcenserv") && result.Contains("fandom") && result.Contains("neoseeker")); - } + => Assert.That( + searchService.GetSearchUrl("terraria boss", "text"), + Does.Contain("arcenserv").And.Contain("fandom").And.Contain("neoseeker")); [Test] public void GivenBg3Query_WhenGettingTextSearchUrl_ThenIncludesFextralifeBlacklist() - { - string result = searchService.GetSearchUrl("bg3 build", "text"); - - Assert.That(result.Contains("fextralife")); - } + => Assert.That( + searchService.GetSearchUrl("bg3 build", "text"), + Does.Contain("fextralife")); [Test] public void GivenBg3Query_WhenGettingTextSearchUrl_ThenIncludesFandomBlacklist() - { - string result = searchService.GetSearchUrl("bg3 build", "text"); - - Assert.That(result.Contains("fandom")); - } + => Assert.That( + searchService.GetSearchUrl("bg3 build", "text"), + Does.Contain("fandom")); [Test] public void GivenBorderlandsQuery_WhenGettingTextSearchUrl_ThenIncludesFextralifeBlacklist() - { - string result = searchService.GetSearchUrl("borderlands guns", "text"); - - Assert.That(result.Contains("fextralife")); - } + => Assert.That( + searchService.GetSearchUrl("borderlands guns", "text"), + Does.Contain("fextralife")); [Test] public void GivenBorderlandsQuery_WhenGettingTextSearchUrl_ThenIncludesHuijiwikiBlacklist() - { - string result = searchService.GetSearchUrl("borderlands guns", "text"); - - Assert.That(result.Contains("huijiwiki")); - } + => Assert.That( + searchService.GetSearchUrl("borderlands guns", "text"), + Does.Contain("huijiwiki")); [Test] public void GivenOsrsQuery_WhenGettingTextSearchUrl_ThenIncludesFandomBlacklist() - { - string result = searchService.GetSearchUrl("osrs quest guide", "text"); - - Assert.That(result.Contains("fandom")); - } + => Assert.That( + searchService.GetSearchUrl("osrs quest guide", "text"), + Does.Contain("fandom")); [Test] public void GivenOsrsQuery_WhenGettingTextSearchUrl_ThenIncludesNeoseekerBlacklist() - { - string result = searchService.GetSearchUrl("osrs quest guide", "text"); - - Assert.That(result.Contains("neoseeker")); - } + => Assert.That( + searchService.GetSearchUrl("osrs quest guide", "text"), + Does.Contain("neoseeker")); [Test] public void GivenOsrsQuery_WhenGettingTextSearchUrl_ThenIncludesStrategywikiBlacklist() - { - string result = searchService.GetSearchUrl("osrs quest guide", "text"); - - Assert.That(result.Contains("strategywiki")); - } + => Assert.That( + searchService.GetSearchUrl("osrs quest guide", "text"), + Does.Contain("strategywiki")); [Test] public void GivenFactorioQuery_WhenGettingTextSearchUrl_ThenIncludesFandomBlacklist() - { - string result = searchService.GetSearchUrl("factorio base design", "text"); - - Assert.That(result.Contains("fandom")); - } + => Assert.That( + searchService.GetSearchUrl("factorio base design", "text"), + Does.Contain("fandom")); [Test] public void GivenWarhammerQuery_WhenGettingTextSearchUrl_ThenIncludesFandomBlacklist() - { - string result = searchService.GetSearchUrl("warhammer lore", "text"); - - Assert.That(result.Contains("fandom")); - } + => Assert.That( + searchService.GetSearchUrl("warhammer lore", "text"), + Does.Contain("fandom")); [Test] public void GivenWh40kQuery_WhenGettingTextSearchUrl_ThenIncludesFandomBlacklist() - { - string result = searchService.GetSearchUrl("wh40k space marine", "text"); - - Assert.That(result.Contains("fandom")); - } + => Assert.That( + searchService.GetSearchUrl("wh40k space marine", "text"), + Does.Contain("fandom")); [Test] public void Given40kQuery_WhenGettingTextSearchUrl_ThenIncludesFandomBlacklist() - { - string result = searchService.GetSearchUrl("40k tau build", "text"); - - Assert.That(result.Contains("fandom")); - } + => Assert.That( + searchService.GetSearchUrl("40k tau build", "text"), + Does.Contain("fandom")); [Test] public void GivenSkyrimQuery_WhenGettingTextSearchUrl_ThenIncludesFextralifeBlacklist() - { - string result = searchService.GetSearchUrl("skyrim archery build", "text"); - - Assert.That(result.Contains("fextralife")); - } + => Assert.That( + searchService.GetSearchUrl("skyrim archery build", "text"), + Does.Contain("fextralife")); [Test] public void GivenSkyrimQuery_WhenGettingTextSearchUrl_ThenIncludesFandomBlacklist() - { - string result = searchService.GetSearchUrl("skyrim archery build", "text"); - - Assert.That(result.Contains("fandom")); - } + => Assert.That( + searchService.GetSearchUrl("skyrim archery build", "text"), + Does.Contain("fandom")); [Test] public void GivenBaldurQuery_WhenGettingTextSearchUrl_ThenIncludesFextralifeBlacklist() - { - string result = searchService.GetSearchUrl("baldur paladin guide", "text"); - - Assert.That(result.Contains("fextralife")); - } + => Assert.That( + searchService.GetSearchUrl("baldur paladin guide", "text"), + Does.Contain("fextralife")); [Test] public void GivenBaldurQuery_WhenGettingTextSearchUrl_ThenIncludesFandomBlacklist() - { - string result = searchService.GetSearchUrl("baldur paladin guide", "text"); - - Assert.That(result.Contains("fandom")); - } + => Assert.That( + searchService.GetSearchUrl("baldur paladin guide", "text"), + Does.Contain("fandom")); // ── Deobfuscation ───────────────────────────────────────────────────── @@ -1202,8 +930,10 @@ public void GivenObfuscatedQuery_WhenGettingSearchUrl_ThenDeobfuscatesBeforeSear string result = searchService.GetSearchUrl(obfuscatedQuery, "auto"); - Assert.That(result.StartsWith("https://search.brave.com/search?q=") - || result.StartsWith("https://duckduckgo.com/?q=")); + Assert.That( + result, + Does.StartWith("https://search.brave.com/search?q=") + .Or.StartWith("https://duckduckgo.com/?q=")); } [Test] @@ -1239,7 +969,9 @@ public void GivenObfuscatedQueryWithSearchType_WhenGettingSearchUrl_ThenDeobfusc string result = searchService.GetSearchUrl(obfuscatedQuery, "images"); - Assert.That(result, Is.EqualTo("https://duckduckgo.com/?iax=images&ia=images&q=cats")); + Assert.That( + result, + Is.EqualTo("https://duckduckgo.com/?iax=images&ia=images&q=cats")); } // ── Query normalisation ─────────────────────────────────────────────── @@ -1275,11 +1007,9 @@ public void GivenQueryWithZeroWidthCharacters_WhenGettingSearchUrl_ThenStripsZer [Test] public void GivenMultiWordQueryWithNoKeyword_WhenGettingSearchUrl_ThenReturnsTextSearchUrl() - { - string result = searchService.GetSearchUrl("dark souls guide", "auto"); - - Assert.That(result.StartsWith("https://search.brave.com/search?q=") - || result.StartsWith("https://duckduckgo.com/?q=")); - } + => Assert.That( + searchService.GetSearchUrl("dark souls guide", "auto"), + Does.StartWith("https://search.brave.com/search?q=") + .Or.StartWith("https://duckduckgo.com/?q=")); } } diff --git a/NuciSearch/Localisation/IpCultureProvider.cs b/NuciSearch/Localisation/IpCultureProvider.cs index 7243830..cae783a 100644 --- a/NuciSearch/Localisation/IpCultureProvider.cs +++ b/NuciSearch/Localisation/IpCultureProvider.cs @@ -6,9 +6,11 @@ namespace NuciSearch.Localisation { - public sealed class IpCultureProvider(IGeolocationService geolocationService) : IRequestCultureProvider + public sealed class IpCultureProvider( + IGeolocationService geolocationService) : IRequestCultureProvider { - public async Task DetermineProviderCultureResult(HttpContext httpContext) + public async Task DetermineProviderCultureResult( + HttpContext httpContext) { string ipAddress = string.Empty; @@ -17,7 +19,8 @@ public sealed class IpCultureProvider(IGeolocationService geolocationService) : ipAddress = httpContext.Connection.RemoteIpAddress.ToString(); } - if (httpContext.Request.Headers.TryGetValue("X-Forwarded-For", out StringValues forwardedFor)) + if (httpContext.Request.Headers.TryGetValue( + "X-Forwarded-For", out StringValues forwardedFor)) { string firstIp = forwardedFor.ToString().Split(',')[0].Trim(); @@ -30,7 +33,7 @@ public sealed class IpCultureProvider(IGeolocationService geolocationService) : string countryCode = await geolocationService.GetCountryCodeAsync(ipAddress); string culture = "en-GB"; - if (countryCode.Equals("RO")) + if (string.Equals(countryCode, "RO")) { culture = "ro-RO"; } diff --git a/NuciSearch/Logging/NuciSearchOperation.cs b/NuciSearch/Logging/NuciSearchOperation.cs index 3677758..defd2ec 100644 --- a/NuciSearch/Logging/NuciSearchOperation.cs +++ b/NuciSearch/Logging/NuciSearchOperation.cs @@ -4,7 +4,8 @@ namespace NuciSearch.Logging { public sealed class NuciSearchOperation : Operation { - public static Operation GetCountryCode => new NuciSearchOperation(nameof(GetCountryCode)); + public static Operation GetCountryCode + => new NuciSearchOperation(nameof(GetCountryCode)); public static Operation Search => new NuciSearchOperation(nameof(Search)); diff --git a/NuciSearch/Program.cs b/NuciSearch/Program.cs index 4fbf169..aeb6c50 100644 --- a/NuciSearch/Program.cs +++ b/NuciSearch/Program.cs @@ -36,10 +36,12 @@ public static void Main(string[] args) options.DefaultRequestCulture = new RequestCulture("en-GB"); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; - options.RequestCultureProviders = [app.Services.GetRequiredService()]; + options.RequestCultureProviders = + [app.Services.GetRequiredService()]; }); - app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); + app.UseStatusCodePagesWithReExecute( + "/not-found", createScopeForStatusCodePages: true); app.UseAntiforgery(); app.MapGet("/opensearch.xml", (IStringLocalizer L) => @@ -54,7 +56,10 @@ public static void Main(string[] args) """; - return Results.Content(xml, "application/opensearchdescription+xml", System.Text.Encoding.UTF8); + return Results.Content( + xml, + "application/opensearchdescription+xml", + Encoding.UTF8); }); app.MapStaticAssets(); diff --git a/NuciSearch/ServiceCollectionExtensions.cs b/NuciSearch/ServiceCollectionExtensions.cs index 461ebb7..e51e5e4 100644 --- a/NuciSearch/ServiceCollectionExtensions.cs +++ b/NuciSearch/ServiceCollectionExtensions.cs @@ -10,7 +10,8 @@ namespace NuciSearch { internal static class ServiceCollectionExtensions { - internal static IServiceCollection AddNuciSearchServices(this IServiceCollection services, IConfiguration configuration) + internal static IServiceCollection AddNuciSearchServices( + this IServiceCollection services, IConfiguration configuration) { NuciLoggerSettings loggingSettings = new(); configuration.Bind(nameof(NuciLoggerSettings), loggingSettings); diff --git a/NuciSearch/Services/GeolocationService.cs b/NuciSearch/Services/GeolocationService.cs index fa0498d..640ce65 100644 --- a/NuciSearch/Services/GeolocationService.cs +++ b/NuciSearch/Services/GeolocationService.cs @@ -8,7 +8,10 @@ namespace NuciSearch.Services { - public sealed class GeolocationService(IHttpClientFactory httpClientFactory, IMemoryCache cache, ILogger logger) : IGeolocationService + public sealed class GeolocationService( + IHttpClientFactory httpClientFactory, + IMemoryCache cache, + ILogger logger) : IGeolocationService { public async Task GetCountryCodeAsync(string ipAddress) { @@ -43,7 +46,10 @@ public async Task GetCountryCodeAsync(string ipAddress) } catch (Exception exception) { - logger.Error(NuciSearchOperation.GetCountryCode, OperationStatus.Failure, exception, + logger.Error( + NuciSearchOperation.GetCountryCode, + OperationStatus.Failure, + exception, [new(NuciSearchLogInfoKey.IpAddress, ipAddress)]); return "GB"; @@ -57,7 +63,7 @@ private static bool IsPrivateOrLoopback(string ipAddress) return true; } - if (ipAddress.Equals("::1") || ipAddress.Equals("127.0.0.1")) + if (string.Equals(ipAddress, "::1") || string.Equals(ipAddress, "127.0.0.1")) { return true; } diff --git a/NuciSearch/Services/SearchService.cs b/NuciSearch/Services/SearchService.cs index 5819b24..4da3cc6 100644 --- a/NuciSearch/Services/SearchService.cs +++ b/NuciSearch/Services/SearchService.cs @@ -14,19 +14,54 @@ public sealed class SearchService(ILogger logger) : ISearchService { private static readonly INuciTextObfuscator obfuscator = new NuciTextObfuscator(); - private static readonly Regex arcenservKeywordsPattern = new(@"\b(?:terraria)\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex fextralifeKeywordsPattern = new(@"\b(?:baldur|bg3|borderlands|don'*t\s*starve|eso|elder\s*scrolls|skyrim|tes)\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex fandomKeywordsPattern = new(@"\b(?:40k|baldur|bg3|don'*t\s*starve|eso|factorio|mc|minecraft|terraria|elder\s*scrolls|osrs|skyrim|tes|runescape|puzzle\s*pirates|ypp|game\s*of\s*thrones|warhammer|wh40k)\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex huijiwikiKeywordsPattern = new(@"\b(?:borderlands)\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex neoseekerKeywordsPattern = new(@"\b(?:osrs|runescape|terraria)\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex strategywikiKeywordsPattern = new(@"\b(?:osrs|runescape)\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); + private static readonly Regex arcenservKeywordsPattern = new( + @"\b(?:terraria)\b", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + + private static readonly Regex fextralifeKeywordsPattern = new( + @"\b(?:baldur|bg3|borderlands|don'*t\s*starve|eso|elder\s*scrolls|skyrim|tes)\b", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + + private static readonly Regex fandomKeywordsPattern = new( + @"\b(?:40k|baldur|bg3|don'*t\s*starve|eso|factorio|mc|minecraft|terraria" + + @"|elder\s*scrolls|osrs|skyrim|tes|runescape|puzzle\s*pirates|ypp" + + @"|game\s*of\s*thrones|warhammer|wh40k)\b", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + + private static readonly Regex huijiwikiKeywordsPattern = new( + @"\b(?:borderlands)\b", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + + private static readonly Regex neoseekerKeywordsPattern = new( + @"\b(?:osrs|runescape|terraria)\b", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + + private static readonly Regex strategywikiKeywordsPattern = new( + @"\b(?:osrs|runescape)\b", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + private static readonly Regex whitespacePattern = new(@"\s+", RegexOptions.Compiled); - private static readonly Regex zeroWidthCharactersPattern = new(@"[\u200B-\u200D\uFEFF]", RegexOptions.Compiled); - private static readonly Regex jiraPattern = new(@"^(?:AAP|AV|AND|CP)-\d+$", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex rallyPattern = new(@"^(?:DE|F|US)[0-9]{6,8}$", RegexOptions.Compiled); - private static readonly Regex wikiDataPattern = new(@"^Q\d+$", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex currencyPattern = new(@"^\d[\d.,]*\s+\w+\s+(?:in|în|to)\s+\w+$", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex ipAddressQueryPattern = new(@"^(?:my|current)\s+ip(?:\s+address)?$", RegexOptions.IgnoreCase | RegexOptions.Compiled); + + private static readonly Regex zeroWidthCharactersPattern = new( + @"[\u200B-\u200D\uFEFF]", RegexOptions.Compiled); + + private static readonly Regex jiraPattern = new( + @"^(?:AAP|AV|AND|CP)-\d+$", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + + private static readonly Regex rallyPattern = new( + @"^(?:DE|F|US)[0-9]{6,8}$", RegexOptions.Compiled); + + private static readonly Regex wikiDataPattern = new( + @"^Q\d+$", RegexOptions.IgnoreCase | RegexOptions.Compiled); + + private static readonly Regex currencyPattern = new( + @"^\d[\d.,]*\s+\w+\s+(?:in|în|to)\s+\w+$", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + + private static readonly Regex ipAddressQueryPattern = new( + @"^(?:my|current)\s+ip(?:\s+address)?$", + RegexOptions.IgnoreCase | RegexOptions.Compiled); public string GetSearchUrl(string rawQuery, string searchType) { @@ -50,23 +85,25 @@ public string GetSearchUrl(string rawQuery, string searchType) string url; - if (searchType.Equals("images", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(searchType, "images", StringComparison.OrdinalIgnoreCase)) { url = GetDuckDuckGoImagesUrl(query); } - else if (searchType.Equals("maps", StringComparison.OrdinalIgnoreCase)) + else if (string.Equals(searchType, "maps", StringComparison.OrdinalIgnoreCase)) { url = GetGoogleMapsUrl(query); } - else if (searchType.Equals("torrents", StringComparison.OrdinalIgnoreCase)) + else if (string.Equals( + searchType, "torrents", StringComparison.OrdinalIgnoreCase)) { url = GetYandexTorrentsUrl(query); } - else if (searchType.Equals("videos", StringComparison.OrdinalIgnoreCase)) + else if (string.Equals( + searchType, "videos", StringComparison.OrdinalIgnoreCase)) { url = GetYouTubeUrl(query); } - else if (searchType.Equals("text", StringComparison.OrdinalIgnoreCase)) + else if (string.Equals(searchType, "text", StringComparison.OrdinalIgnoreCase)) { url = GetTextSearch(query); } @@ -82,18 +119,29 @@ public string GetSearchUrl(string rawQuery, string searchType) new(NuciSearchLogInfoKey.Url, url) ]; - logger.Info(NuciSearchOperation.Search, OperationStatus.Success, successLogInfos); + logger.Info( + NuciSearchOperation.Search, + OperationStatus.Success, + successLogInfos); + return url; } catch (Exception exception) { - logger.Error(NuciSearchOperation.Search, OperationStatus.Failure, exception, logInfos); + logger.Error( + NuciSearchOperation.Search, + OperationStatus.Failure, + exception, + logInfos); + throw; } } private static string GetAliExpressUrl(string query) - => $"https://www.aliexpress.com/w/wholesale-{whitespacePattern.Replace(query.Trim(), "-")}.html?spm=a2g0o.detail.search.0"; + => "https://www.aliexpress.com/w/wholesale-" + + whitespacePattern.Replace(query.Trim(), "-") + + ".html?spm=a2g0o.detail.search.0"; private static string GetAltexUrl(string query) => $"https://altex.ro/cauta/?q={Uri.EscapeDataString(query)}"; @@ -111,7 +159,9 @@ private static string GetAudibleUrl(string query) => $"https://audible.com/search?advsearchKeywords={Uri.EscapeDataString(query)}"; private static string GetBoobpediaUrl(string query) - => $"https://boobpedia.com/wiki/index.php?title=Special%3ASearch&search={Uri.EscapeDataString(query)}&go=Go"; + => "https://boobpedia.com/wiki/index.php?title=Special%3ASearch&search=" + + Uri.EscapeDataString(query) + + "&go=Go"; private static string GetCarturestiUrl(string query) => $"https://carturesti.ro/product/search/{Uri.EscapeDataString(query)}"; @@ -148,12 +198,14 @@ private static string GetFdroidUrl(string query) private static string GetFirefoxExtensionsUrl(string query) { - if (CultureInfo.CurrentUICulture.Name.Equals("ro-RO")) + if (string.Equals(CultureInfo.CurrentUICulture.Name, "ro-RO")) { - return $"https://addons.mozilla.org/ro/firefox/search/?q={Uri.EscapeDataString(query)}"; + return "https://addons.mozilla.org/ro/firefox/search/?q=" + + Uri.EscapeDataString(query); } - return $"https://addons.mozilla.org/en-GB/firefox/search/?q={Uri.EscapeDataString(query)}"; + return "https://addons.mozilla.org/en-GB/firefox/search/?q=" + + Uri.EscapeDataString(query); } private static string GetFlancoUrl(string query) @@ -176,7 +228,7 @@ private static string GetGogUrl(string query) private static string GetGoogleMapsUrl(string query) { - if (CultureInfo.CurrentUICulture.Name.Equals("ro-RO")) + if (string.Equals(CultureInfo.CurrentUICulture.Name, "ro-RO")) { return $"https://google.ro/maps/search/{Uri.EscapeDataString(query)}"; } @@ -189,7 +241,7 @@ private static string GetHornbachUrl(string query) private static string GetIkeaUrl(string query) { - if (CultureInfo.CurrentUICulture.Name.Equals("ro-RO")) + if (string.Equals(CultureInfo.CurrentUICulture.Name, "ro-RO")) { return $"https://ikea.com/ro/ro/search/?q={Uri.EscapeDataString(query)}"; } @@ -213,10 +265,12 @@ private static string GetLidlUrl(string query) => $"https://lidl.ro/q/search?q={Uri.EscapeDataString(query)}"; private static string GetLinkedinUrl(string query) - => $"https://linkedin.com/search/results/all/?keywords={Uri.EscapeDataString(query)}"; + => "https://linkedin.com/search/results/all/?keywords=" + + Uri.EscapeDataString(query); private static string GetMinecraftHeadsUrl(string query) - => $"https://minecraft-heads.com/custom-heads/search?searchterm={Uri.EscapeDataString(query)}"; + => "https://minecraft-heads.com/custom-heads/search?searchterm=" + + Uri.EscapeDataString(query); private static string GetMinecraftWikiUrl(string query) => $"https://minecraft.wiki/?search={Uri.EscapeDataString(query)}"; @@ -255,7 +309,8 @@ private static string GetPlayStoreUrl(string query) => $"https://play.google.com/store/search?q={Uri.EscapeDataString(query)}"; private static string GetPlexUrl(string query) - => $"https://app.plex.tv/desktop/#!/search?pivot=top&query={Uri.EscapeDataString(query)}"; + => "https://app.plex.tv/desktop/#!/search?pivot=top&query=" + + Uri.EscapeDataString(query); private static string GetProtonDbUrl(string query) => $"https://protondb.com/search?q={Uri.EscapeDataString(query)}"; @@ -264,7 +319,8 @@ private static string GetWikiDataUrl(string query) => $"https://wikidata.org/wiki/{Uri.EscapeDataString(query.ToUpperInvariant())}"; private static string GetJiraUrl(string query) - => $"https://worldpay.atlassian.net/browse/{Uri.EscapeDataString(query.ToUpperInvariant())}"; + => "https://worldpay.atlassian.net/browse/" + + Uri.EscapeDataString(query.ToUpperInvariant()); private static string GetRallyUrl(string query) => $"https://rally1.rallydev.com/#/search?keywords={Uri.EscapeDataString(query)}"; @@ -276,10 +332,14 @@ private static string GetSinsayUrl(string query) => $"https://sinsay.com/ro/ro/?query={Uri.EscapeDataString(query)}"; private static string GetSpigotUrl(string query) - => $"https://spigotmc.org/search/294718421/?q={Uri.EscapeDataString(query)}&o=relevance"; + => "https://spigotmc.org/search/294718421/?q=" + + Uri.EscapeDataString(query) + + "&o=relevance"; private static string GetSpyShopUrl(string query) - => $"https://spy-shop.ro/catalogsearch/result/?q={Uri.EscapeDataString(query)}&o=relevance"; + => "https://spy-shop.ro/catalogsearch/result/?q=" + + Uri.EscapeDataString(query) + + "&o=relevance"; private static string GetSteamDbUrl(string query) => $"https://steamdb.info/search/?a=all&q={Uri.EscapeDataString(query)}"; @@ -326,14 +386,15 @@ private static string GetWikiPediaUrl(string query) string encodedQuery = Uri.EscapeDataString(query); string langCode = "en"; - if (CultureInfo.CurrentUICulture.Name.Equals("ro-RO")) + if (string.Equals(CultureInfo.CurrentUICulture.Name, "ro-RO")) { langCode = "ro"; } string[] instances = [ $"https://{langCode}.wikipedia.org/w/index.php?search={encodedQuery}", - $"https://wikiless.tiekoetter.com/w/index.php?search={encodedQuery}&lang={langCode}", + $"https://wikiless.tiekoetter.com/w/index.php?search={encodedQuery}" + + $"&lang={langCode}", ]; return instances[Random.Shared.Next(instances.Length)]; @@ -405,23 +466,28 @@ private static string GetAutoUrl(string query) { return GetJiraUrl(query); } - else if (rallyPattern.IsMatch(query)) + + if (rallyPattern.IsMatch(query)) { return GetRallyUrl(query); } - else if (wikiDataPattern.IsMatch(query)) + + if (wikiDataPattern.IsMatch(query)) { return GetWikiDataUrl(query); } - else if (currencyPattern.IsMatch(query)) + + if (currencyPattern.IsMatch(query)) { return BuildCurrencySearchUrl(query); } - else if (ipAddressQueryPattern.IsMatch(query)) + + if (ipAddressQueryPattern.IsMatch(query)) { return $"https://duckduckgo.com/?q={Uri.EscapeDataString(query)}"; } - else if (words.Count() >= 2) + + if (words.Count() >= 2) { return GetAutoUrlForMultiWordQuery(query, words); } @@ -432,321 +498,405 @@ private static string GetAutoUrl(string query) private static string BuildCurrencySearchUrl(string query) { string currencyQuery = query; - currencyQuery = Regex.Replace(currencyQuery, @"în", "in", RegexOptions.IgnoreCase); - currencyQuery = Regex.Replace(currencyQuery, @"\b(?:lei|leu)\b", "RON", RegexOptions.IgnoreCase); - currencyQuery = Regex.Replace(currencyQuery, @"\beuros?\b", "EUR", RegexOptions.IgnoreCase); - currencyQuery = Regex.Replace(currencyQuery, @"\b(?:dollars?|dolari?)\b", "USD", RegexOptions.IgnoreCase); - currencyQuery = Regex.Replace(currencyQuery, @"(?:lira|liră|lire)(?=\s|$)", "GBP", RegexOptions.IgnoreCase); - currencyQuery = Regex.Replace(currencyQuery, @"\b[a-zA-Z]{3}\b", match => match.Value.ToUpperInvariant()); + currencyQuery = Regex.Replace( + currencyQuery, @"în", "in", RegexOptions.IgnoreCase); + currencyQuery = Regex.Replace( + currencyQuery, @"\b(?:lei|leu)\b", "RON", RegexOptions.IgnoreCase); + currencyQuery = Regex.Replace( + currencyQuery, @"\beuros?\b", "EUR", RegexOptions.IgnoreCase); + currencyQuery = Regex.Replace( + currencyQuery, + @"\b(?:dollars?|dolari?)\b", + "USD", + RegexOptions.IgnoreCase); + currencyQuery = Regex.Replace( + currencyQuery, + @"(?:lira|liră|lire)(?=\s|$)", + "GBP", + RegexOptions.IgnoreCase); + currencyQuery = Regex.Replace( + currencyQuery, + @"\b[a-zA-Z]{3}\b", + match => match.Value.ToUpperInvariant()); return $"https://duckduckgo.com/?q={Uri.EscapeDataString(currencyQuery)}"; } - private static string GetAutoUrlForMultiWordQuery(string query, IEnumerable words) + private static string GetAutoUrlForMultiWordQuery( + string query, IEnumerable words) { - if (words.Any(word => word.Equals("aliexpress", StringComparison.OrdinalIgnoreCase))) + if (ContainsKeyword(words, "aliexpress")) { - return GetAliExpressUrl(string.Join(" ", words.Where(word => !word.Equals("aliexpress", StringComparison.OrdinalIgnoreCase)))); + return GetAliExpressUrl(StripKeyword(words, "aliexpress")); } else if (query.Contains("altex", StringComparison.OrdinalIgnoreCase)) { - return GetAltexUrl(query.Replace("altex", string.Empty, StringComparison.OrdinalIgnoreCase).Trim()); + return GetAltexUrl(query + .Replace("altex", string.Empty, StringComparison.OrdinalIgnoreCase) + .Trim()); } - else if (words.Any(word => word.Equals("appstore", StringComparison.OrdinalIgnoreCase) - || word.Equals("app store", StringComparison.OrdinalIgnoreCase) - || word.Equals("apple store", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "appstore") || + ContainsKeyword(words, "app store") || + ContainsKeyword(words, "apple store")) { - return GetAppStoreUrl( - string.Join(" ", words.Where(word => !word.Equals("appstore", StringComparison.OrdinalIgnoreCase))) - .Replace("app store", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("apple store", string.Empty, StringComparison.OrdinalIgnoreCase) - .Trim()); + return GetAppStoreUrl(StripKeyword(words, "appstore") + .Replace("app store", string.Empty, StringComparison.OrdinalIgnoreCase) + .Replace("apple store", string.Empty, StringComparison.OrdinalIgnoreCase) + .Trim()); } else if (query.Contains("arch wiki", StringComparison.OrdinalIgnoreCase)) { - return GetArchWikiUrl(query.Replace("arch wiki", string.Empty, StringComparison.OrdinalIgnoreCase).Trim()); + return GetArchWikiUrl(query + .Replace("arch wiki", string.Empty, StringComparison.OrdinalIgnoreCase) + .Trim()); } - else if (words.Any(word => word.Equals("auchan", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "auchan")) { - return GetAuchanUrl(string.Join(" ", words.Where(word => !word.Equals("auchan", StringComparison.OrdinalIgnoreCase)))); + return GetAuchanUrl(StripKeyword(words, "auchan")); } - else if (words.Any(word => word.Equals("audible", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "audible")) { - return GetAudibleUrl(string.Join(" ", words.Where(word => !word.Equals("audible", StringComparison.OrdinalIgnoreCase)))); + return GetAudibleUrl(StripKeyword(words, "audible")); } - else if (words.Any(word => word.Equals("boobpedia", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "boobpedia")) { - return GetBoobpediaUrl(string.Join(" ", words.Where(word => !word.Equals("boobpedia", StringComparison.OrdinalIgnoreCase)))); + return GetBoobpediaUrl(StripKeyword(words, "boobpedia")); } - else if (words.Any(word => word.Equals("carturesti", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "carturesti")) { - return GetCarturestiUrl(string.Join(" ", words.Where(word => !word.Equals("carturesti", StringComparison.OrdinalIgnoreCase)))); + return GetCarturestiUrl(StripKeyword(words, "carturesti")); } - else if (words.Any(word => word.Equals("decathlon", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "decathlon")) { - return GetDecathlonUrl(string.Join(" ", words.Where(word => !word.Equals("decathlon", StringComparison.OrdinalIgnoreCase)))); + return GetDecathlonUrl(StripKeyword(words, "decathlon")); } - else if (words.Any(word => word.Equals("dedeman", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "dedeman")) { - return GetDedemanUrl(string.Join(" ", words.Where(word => !word.Equals("dedeman", StringComparison.OrdinalIgnoreCase)))); + return GetDedemanUrl(StripKeyword(words, "dedeman")); } - else if (words.Any(word => word.Equals("dex", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "dex")) { - return GetDexOnlineUrl(string.Join(" ", words.Where(word => !word.Equals("dex", StringComparison.OrdinalIgnoreCase)))); + return GetDexOnlineUrl(StripKeyword(words, "dex")); } - else if (words.Any(word => word.Equals("digi24", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "digi24")) { - return GetDigi24Url(string.Join(" ", words.Where(word => !word.Equals("digi24", StringComparison.OrdinalIgnoreCase)))); + return GetDigi24Url(StripKeyword(words, "digi24")); } - else if (words.Any(word => word.Equals("ebay", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "ebay")) { - return GetEbayUrl(string.Join(" ", words.Where(word => !word.Equals("ebay", StringComparison.OrdinalIgnoreCase)))); + return GetEbayUrl(StripKeyword(words, "ebay")); } - else if (words.Any(word => word.Equals("emag", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "emag")) { - return GetEmagUrl(string.Join(" ", words.Where(word => !word.Equals("emag", StringComparison.OrdinalIgnoreCase)))); + return GetEmagUrl(StripKeyword(words, "emag")); } - else if (words.Any(word => word.Equals("evomag", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "evomag")) { - return GetEvomagUrl(string.Join(" ", words.Where(word => !word.Equals("evomag", StringComparison.OrdinalIgnoreCase)))); + return GetEvomagUrl(StripKeyword(words, "evomag")); } - else if (words.Any(word => word.Equals("facebook", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "facebook")) { - return GetFacebookUrl(string.Join(" ", words.Where(word => !word.Equals("facebook", StringComparison.OrdinalIgnoreCase)))); + return GetFacebookUrl(StripKeyword(words, "facebook")); } - else if (words.Any(word => word.Equals("fdroid", StringComparison.OrdinalIgnoreCase) - || word.Equals("f-droid", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "fdroid") || ContainsKeyword(words, "f-droid")) { - return GetFdroidUrl(string.Join(" ", words.Where(word => !word.Equals("fdroid", StringComparison.OrdinalIgnoreCase) - && !word.Equals("f-droid", StringComparison.OrdinalIgnoreCase)))); + IEnumerable remainingWords = words.Where(word => + !string.Equals(word, "fdroid", StringComparison.OrdinalIgnoreCase) && + !string.Equals(word, "f-droid", StringComparison.OrdinalIgnoreCase)); + + return GetFdroidUrl(string.Join(" ", remainingWords)); } else if (query.Contains("firefox extension", StringComparison.OrdinalIgnoreCase)) { - return GetFirefoxExtensionsUrl(query - .Replace("firefox extensions", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("firefox extension", string.Empty, StringComparison.OrdinalIgnoreCase) - .Trim()); + string searchQuery = query + .Replace( + "firefox extensions", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Replace( + "firefox extension", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Trim(); + + return GetFirefoxExtensionsUrl(searchQuery); } - else if (words.Any(word => word.Equals("flanco", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "flanco")) { - return GetFlancoUrl(string.Join(" ", words.Where(word => !word.Equals("flanco", StringComparison.OrdinalIgnoreCase)))); + return GetFlancoUrl(StripKeyword(words, "flanco")); } - else if (words.Any(word => word.Equals("flathub", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "flathub")) { - return GetFlatHubUrl(string.Join(" ", words.Where(word => !word.Equals("flathub", StringComparison.OrdinalIgnoreCase)))); + return GetFlatHubUrl(StripKeyword(words, "flathub")); } - else if (words.Any(word => word.Equals("flip.ro", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "flip.ro")) { - return GetFlipRoUrl(string.Join(" ", words.Where(word => !word.Equals("flip.ro", StringComparison.OrdinalIgnoreCase)))); + return GetFlipRoUrl(StripKeyword(words, "flip.ro")); } - else if (words.Any(word => word.Equals("g2a", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "g2a")) { - return GetG2aUrl(string.Join(" ", words.Where(word => !word.Equals("g2a", StringComparison.OrdinalIgnoreCase)))); + return GetG2aUrl(StripKeyword(words, "g2a")); } - else if (words.Any(word => word.Equals("github", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "github")) { - return GetGitHubUrl(string.Join(" ", words.Where(word => !word.Equals("github", StringComparison.OrdinalIgnoreCase)))); + return GetGitHubUrl(StripKeyword(words, "github")); } - else if (words.Any(word => word.Equals("gog", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "gog")) { - return GetGogUrl(string.Join(" ", words.Where(word => !word.Equals("gog", StringComparison.OrdinalIgnoreCase)))); + return GetGogUrl(StripKeyword(words, "gog")); } - else if (words.Any(word => word.Equals("hornbach", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "hornbach")) { - return GetHornbachUrl(string.Join(" ", words.Where(word => !word.Equals("hornbach", StringComparison.OrdinalIgnoreCase)))); + return GetHornbachUrl(StripKeyword(words, "hornbach")); } - else if (words.Any(word => word.Equals("ikea", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "ikea")) { - return GetIkeaUrl(string.Join(" ", words.Where(word => !word.Equals("ikea", StringComparison.OrdinalIgnoreCase)))); + return GetIkeaUrl(StripKeyword(words, "ikea")); } - else if (words.Any(word => word.Equals("imdb", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "imdb")) { - return GetImdbUrl(string.Join(" ", words.Where(word => !word.Equals("imdb", StringComparison.OrdinalIgnoreCase)))); + return GetImdbUrl(StripKeyword(words, "imdb")); } - else if (words.Any(word => word.Equals("instagram", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "instagram")) { - return GetInstagramUrl(string.Join(" ", words.Where(word => !word.Equals("instagram", StringComparison.OrdinalIgnoreCase)))); + return GetInstagramUrl(StripKeyword(words, "instagram")); } - else if (words.Any(word => word.Equals("jysk", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "jysk")) { - return GetJyskUrl(string.Join(" ", words.Where(word => !word.Equals("jysk", StringComparison.OrdinalIgnoreCase)))); + return GetJyskUrl(StripKeyword(words, "jysk")); } else if (query.Contains("leroy merlin", StringComparison.OrdinalIgnoreCase)) { - return GetLeroyMerlinUrl(query.Replace("leroy merlin", string.Empty, StringComparison.OrdinalIgnoreCase).Trim()); + return GetLeroyMerlinUrl(query + .Replace( + "leroy merlin", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Trim()); } - else if (words.Any(word => word.Equals("lidl", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "lidl")) { - return GetLidlUrl(string.Join(" ", words.Where(word => !word.Equals("lidl", StringComparison.OrdinalIgnoreCase)))); + return GetLidlUrl(StripKeyword(words, "lidl")); } - else if (words.Any(word => word.Equals("linkedin", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "linkedin")) { - return GetLinkedinUrl(string.Join(" ", words.Where(word => !word.Equals("linkedin", StringComparison.OrdinalIgnoreCase)))); + return GetLinkedinUrl(StripKeyword(words, "linkedin")); } - else if (words.Any(word => word.Equals("moddb", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "moddb")) { - return GetModDbUrl(string.Join(" ", words.Where(word => !word.Equals("moddb", StringComparison.OrdinalIgnoreCase)))); + return GetModDbUrl(StripKeyword(words, "moddb")); } - else if (query.Contains("mc wiki", StringComparison.OrdinalIgnoreCase) - || query.Contains("minecraft wiki", StringComparison.OrdinalIgnoreCase)) + else if (query.Contains("mc wiki", StringComparison.OrdinalIgnoreCase) || + query.Contains("minecraft wiki", StringComparison.OrdinalIgnoreCase)) { - return GetMinecraftWikiUrl(query + string searchQuery = query .Replace("mc wiki", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("minecraft wiki", string.Empty, StringComparison.OrdinalIgnoreCase) - .Trim()); - } - else if (query.Contains("mc head", StringComparison.OrdinalIgnoreCase) - || query.Contains("minecraft head", StringComparison.OrdinalIgnoreCase)) - { - return GetMinecraftHeadsUrl(query - .Replace("minecraft heads", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("minecraft head", string.Empty, StringComparison.OrdinalIgnoreCase) + .Replace( + "minecraft wiki", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Trim(); + + return GetMinecraftWikiUrl(searchQuery); + } + else if (query.Contains("mc head", StringComparison.OrdinalIgnoreCase) || + query.Contains("minecraft head", StringComparison.OrdinalIgnoreCase)) + { + string searchQuery = query + .Replace( + "minecraft heads", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Replace( + "minecraft head", + string.Empty, + StringComparison.OrdinalIgnoreCase) .Replace("mc heads", string.Empty, StringComparison.OrdinalIgnoreCase) .Replace("mc head", string.Empty, StringComparison.OrdinalIgnoreCase) - .Trim()); - } - else if (query.Contains("mc schematic", StringComparison.OrdinalIgnoreCase) - || query.Contains("minecraft schematic", StringComparison.OrdinalIgnoreCase)) - { - return GetPlanetMinecraftSchematicsUrl(query - .Replace("minecraft schematics", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("minecraft schematic", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("mc schematics", string.Empty, StringComparison.OrdinalIgnoreCase) + .Trim(); + + return GetMinecraftHeadsUrl(searchQuery); + } + else if (query.Contains("mc schematic", StringComparison.OrdinalIgnoreCase) || + query.Contains("minecraft schematic", StringComparison.OrdinalIgnoreCase)) + { + string searchQuery = query + .Replace( + "minecraft schematics", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Replace( + "minecraft schematic", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Replace( + "mc schematics", + string.Empty, + StringComparison.OrdinalIgnoreCase) .Replace("mc schematic", string.Empty, StringComparison.OrdinalIgnoreCase) - .Trim()); + .Trim(); + + return GetPlanetMinecraftSchematicsUrl(searchQuery); } - else if (words.Any(word => word.Equals("namemc", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "namemc")) { - return GetNameMcUrl(string.Join(" ", words.Where(word => !word.Equals("namemc", StringComparison.OrdinalIgnoreCase)))); + return GetNameMcUrl(StripKeyword(words, "namemc")); } - else if (words.Any(word => word.Equals("netflix", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "netflix")) { - return GetNetflixUrl(string.Join(" ", words.Where(word => !word.Equals("netflix", StringComparison.OrdinalIgnoreCase)))); + return GetNetflixUrl(StripKeyword(words, "netflix")); } - else if (words.Any(word => word.Equals("nexusmods", StringComparison.OrdinalIgnoreCase) - || word.Equals("nexus mods", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "nexusmods") || + ContainsKeyword(words, "nexus mods")) { - return GetNexusModsUrl( - string.Join(" ", words.Where(word => !word.Equals("nexusmods", StringComparison.OrdinalIgnoreCase))) - .Replace("nexus mods", string.Empty, StringComparison.OrdinalIgnoreCase) - .Trim()); + return GetNexusModsUrl(StripKeyword(words, "nexusmods") + .Replace("nexus mods", string.Empty, StringComparison.OrdinalIgnoreCase) + .Trim()); } - else if (words.Any(word => word.Equals("odysee", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "odysee")) { - return GetOdyseeUrl(string.Join(" ", words.Where(word => !word.Equals("odysee", StringComparison.OrdinalIgnoreCase)))); + return GetOdyseeUrl(StripKeyword(words, "odysee")); } - else if (words.Any(word => word.Equals("olx", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "olx")) { - return GetOlxUrl(string.Join(" ", words.Where(word => !word.Equals("olx", StringComparison.OrdinalIgnoreCase)))); + return GetOlxUrl(StripKeyword(words, "olx")); } - else if (words.Any(word => word.Equals("pcgarage", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "pcgarage")) { - return GetPcGarageUrl(string.Join(" ", words.Where(word => !word.Equals("pcgarage", StringComparison.OrdinalIgnoreCase)))); + return GetPcGarageUrl(StripKeyword(words, "pcgarage")); } - else if (words.Any(word => word.Equals("pinterest", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "pinterest")) { - return GetPinterestUrl(string.Join(" ", words.Where(word => !word.Equals("pinterest", StringComparison.OrdinalIgnoreCase)))); + return GetPinterestUrl(StripKeyword(words, "pinterest")); } else if (query.Contains("planet minecraft", StringComparison.OrdinalIgnoreCase)) { - return GetPlanetMinecraftUrl(query.Replace("planet minecraft", string.Empty, StringComparison.OrdinalIgnoreCase).Trim()); + return GetPlanetMinecraftUrl(query + .Replace( + "planet minecraft", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Trim()); } - else if (query.Contains("play store", StringComparison.OrdinalIgnoreCase) - || query.Contains("playstore", StringComparison.OrdinalIgnoreCase)) + else if (query.Contains("play store", StringComparison.OrdinalIgnoreCase) || + query.Contains("playstore", StringComparison.OrdinalIgnoreCase)) { return GetPlayStoreUrl(query .Replace("play store", string.Empty, StringComparison.OrdinalIgnoreCase) .Replace("playstore", string.Empty, StringComparison.OrdinalIgnoreCase) .Trim()); } - else if (words.Any(word => word.Equals("plex", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "plex")) { - return GetPlexUrl(string.Join(" ", words.Where(word => !word.Equals("plex", StringComparison.OrdinalIgnoreCase)))); + return GetPlexUrl(StripKeyword(words, "plex")); } - else if (words.Any(word => word.Equals("protondb", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "protondb")) { - return GetProtonDbUrl(string.Join(" ", words.Where(word => !word.Equals("protondb", StringComparison.OrdinalIgnoreCase)))); + return GetProtonDbUrl(StripKeyword(words, "protondb")); } - else if (words.Any(word => word.Equals("reddit", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "reddit")) { - return GetRedditUrl(string.Join(" ", words.Where(word => !word.Equals("reddit", StringComparison.OrdinalIgnoreCase)))); + return GetRedditUrl(StripKeyword(words, "reddit")); } - else if (words.Any(word => word.Equals("rtings", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "rtings")) { - return GetRtingsUrl(string.Join(" ", words.Where(word => !word.Equals("rtings", StringComparison.OrdinalIgnoreCase)))); + return GetRtingsUrl(StripKeyword(words, "rtings")); } - else if (words.Any(word => word.Equals("sinsay", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "sinsay")) { - return GetSinsayUrl(string.Join(" ", words.Where(word => !word.Equals("sinsay", StringComparison.OrdinalIgnoreCase)))); + return GetSinsayUrl(StripKeyword(words, "sinsay")); } - else if (words.Any(word => word.Equals("spigot", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "spigot")) { - return GetSpigotUrl(string.Join(" ", words.Where(word => !word.Equals("spigot", StringComparison.OrdinalIgnoreCase)))); + return GetSpigotUrl(StripKeyword(words, "spigot")); } - else if (words.Any(word => word.Equals("spyshop", StringComparison.OrdinalIgnoreCase) - || word.Equals("spyshop.ro", StringComparison.OrdinalIgnoreCase) - || word.Equals("spy-shop", StringComparison.OrdinalIgnoreCase) - || word.Equals("spy-shop.ro", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "spyshop") || + ContainsKeyword(words, "spyshop.ro") || + ContainsKeyword(words, "spy-shop") || + ContainsKeyword(words, "spy-shop.ro")) { - return GetSpyShopUrl(string.Join(" ", words.Where(word => - !word.Equals("spyshop", StringComparison.OrdinalIgnoreCase) - && !word.Equals("spyshop.ro", StringComparison.OrdinalIgnoreCase) - && !word.Equals("spy-shop", StringComparison.OrdinalIgnoreCase) - && !word.Equals("spy-shop.ro", StringComparison.OrdinalIgnoreCase)))); + IEnumerable remainingWords = words.Where(word => + !string.Equals(word, "spyshop", StringComparison.OrdinalIgnoreCase) && + !string.Equals(word, "spyshop.ro", StringComparison.OrdinalIgnoreCase) && + !string.Equals(word, "spy-shop", StringComparison.OrdinalIgnoreCase) && + !string.Equals(word, "spy-shop.ro", StringComparison.OrdinalIgnoreCase)); + + return GetSpyShopUrl(string.Join(" ", remainingWords)); } - else if (words.Any(word => word.Equals("steamdb", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "steamdb")) { - return GetSteamDbUrl(string.Join(" ", words.Where(word => !word.Equals("steamdb", StringComparison.OrdinalIgnoreCase)))); + return GetSteamDbUrl(StripKeyword(words, "steamdb")); } - else if (words.Any(word => word.Equals("tripadvisor", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "tripadvisor")) { - return GetTripadvisorUrl(string.Join(" ", words.Where(word => !word.Equals("tripadvisor", StringComparison.OrdinalIgnoreCase)))); + return GetTripadvisorUrl(StripKeyword(words, "tripadvisor")); } - else if (words.Any(word => word.Equals("tvdb", StringComparison.OrdinalIgnoreCase) - || word.Equals("thetvdb", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "tvdb") || ContainsKeyword(words, "thetvdb")) { - return GetTvdbUrl(string.Join(" ", words.Where(word => - !word.Equals("tvdb", StringComparison.OrdinalIgnoreCase) - && !word.Equals("thetvdb", StringComparison.OrdinalIgnoreCase)))); + IEnumerable remainingWords = words.Where(word => + !string.Equals(word, "tvdb", StringComparison.OrdinalIgnoreCase) && + !string.Equals(word, "thetvdb", StringComparison.OrdinalIgnoreCase)); + + return GetTvdbUrl(string.Join(" ", remainingWords)); } - else if (query.Contains("uesp", StringComparison.OrdinalIgnoreCase) - || query.Contains("elder scrolls wiki", StringComparison.OrdinalIgnoreCase) - || query.Contains("eso wiki", StringComparison.OrdinalIgnoreCase) - || query.Contains("morrowind wiki", StringComparison.OrdinalIgnoreCase) - || query.Contains("oblivion wiki", StringComparison.OrdinalIgnoreCase) - || query.Contains("skyrim wiki", StringComparison.OrdinalIgnoreCase) - || query.Contains("tes wiki", StringComparison.OrdinalIgnoreCase) - || query.Contains("the elder scrolls wiki", StringComparison.OrdinalIgnoreCase)) + else if (query.Contains("uesp", StringComparison.OrdinalIgnoreCase) || + query.Contains("elder scrolls wiki", StringComparison.OrdinalIgnoreCase) || + query.Contains("eso wiki", StringComparison.OrdinalIgnoreCase) || + query.Contains("morrowind wiki", StringComparison.OrdinalIgnoreCase) || + query.Contains("oblivion wiki", StringComparison.OrdinalIgnoreCase) || + query.Contains("skyrim wiki", StringComparison.OrdinalIgnoreCase) || + query.Contains("tes wiki", StringComparison.OrdinalIgnoreCase) || + query.Contains("the elder scrolls wiki", StringComparison.OrdinalIgnoreCase)) { - return GetUespUrl( - string.Join(" ", words.Where(word => !word.Equals("uesp", StringComparison.OrdinalIgnoreCase))) - .Replace("elder scrolls wiki", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("eso wiki", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("morrowind wiki", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("oblivion wiki", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("skyrim wiki", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("tes wiki", string.Empty, StringComparison.OrdinalIgnoreCase) - .Replace("the elder scrolls wiki", string.Empty, StringComparison.OrdinalIgnoreCase) - .Trim()); + string searchQuery = StripKeyword(words, "uesp") + .Replace( + "elder scrolls wiki", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Replace("eso wiki", string.Empty, StringComparison.OrdinalIgnoreCase) + .Replace( + "morrowind wiki", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Replace("oblivion wiki", string.Empty, StringComparison.OrdinalIgnoreCase) + .Replace("skyrim wiki", string.Empty, StringComparison.OrdinalIgnoreCase) + .Replace("tes wiki", string.Empty, StringComparison.OrdinalIgnoreCase) + .Replace( + "the elder scrolls wiki", + string.Empty, + StringComparison.OrdinalIgnoreCase) + .Trim(); + + return GetUespUrl(searchQuery); } - else if (words.Any(word => word.Equals("vinted", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "vinted")) { - return GetVintedUrl(string.Join(" ", words.Where(word => !word.Equals("vinted", StringComparison.OrdinalIgnoreCase)))); + return GetVintedUrl(StripKeyword(words, "vinted")); } - else if (words.Any(word => word.Equals("wikidata", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "wikidata")) { - return GetWikiDataSearchUrl(string.Join(" ", words.Where(word => !word.Equals("wikidata", StringComparison.OrdinalIgnoreCase)))); + return GetWikiDataSearchUrl(StripKeyword(words, "wikidata")); } - else if (words.Any(word => word.Equals("wikipedia", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "wikipedia")) { - return GetWikiPediaUrl(string.Join(" ", words.Where(word => !word.Equals("wikipedia", StringComparison.OrdinalIgnoreCase)))); + return GetWikiPediaUrl(StripKeyword(words, "wikipedia")); } - else if (words.Any(word => word.Equals("youtube", StringComparison.OrdinalIgnoreCase))) + else if (ContainsKeyword(words, "youtube")) { - return GetYouTubeUrl(string.Join(" ", words.Where(word => !word.Equals("youtube", StringComparison.OrdinalIgnoreCase)))); + return GetYouTubeUrl(StripKeyword(words, "youtube")); } return GetTextSearch(query); } + + private static bool ContainsKeyword(IEnumerable words, string keyword) + => words.Any(word => + string.Equals(word, keyword, StringComparison.OrdinalIgnoreCase)); + + private static string StripKeyword(IEnumerable words, string keyword) + => string.Join( + " ", + words.Where(word => + !string.Equals(word, keyword, StringComparison.OrdinalIgnoreCase))); } }