public async Task RequestsCorrectUrl() { var connection = Substitute.For <IApiConnection>(); var client = new ProductsClient(connection); var filters = new ProductSearchFilters { ExactMatch = true, PageSize = 1, PageCount = 1, StartPage = 0, }; await client.Search("product", filters); Received.InOrder(async() => { await connection.SearchAll <SearchResult <SimpleProduct> >( Arg.Is <Uri>(u => u.ToString() == "products/search"), Arg.Is <Dictionary <string, string> >(d => d.Count == 2 && d["term"] == "product" && d["exact_match"] == "True"), Arg.Is <ApiOptions>(o => o.PageSize == 1 && o.PageCount == 1 && o.StartPage == 0)); }); }
public Task <IReadOnlyList <SearchResult <SimpleProduct> > > Search(string term, ProductSearchFilters filters) { Ensure.ArgumentNotNull(term, nameof(term)); Ensure.ArgumentNotNull(filters, nameof(filters)); if (filters.ExactMatch.HasValue && filters.ExactMatch.Value == true) { if (term.Length < 1) { throw new ArgumentException("The search term must have at least 1 character", nameof(term)); } } else { if (term.Length < 2) { throw new ArgumentException("The search term must have at least 2 characters", nameof(term)); } } var parameters = filters.Parameters; parameters.Add("term", term); var options = new ApiOptions { StartPage = filters.StartPage, PageCount = filters.PageCount, PageSize = filters.PageSize }; return(ApiConnection.SearchAll <SearchResult <SimpleProduct> >(ApiUrls.ProductsSearch(), parameters, options)); }