public void Search_BackendTokensParserHandlesDoubleQuotes([Values(SearchBackendType.Properties, SearchBackendType.QuickSearch)] SearchBackendType type) { SearchBackend <string> backend = null; switch (type) { case SearchBackendType.Properties: backend = new PropertiesSearchBackend <string>(); break; case SearchBackendType.QuickSearch: #if QUICKSEARCH_2_1_0_OR_NEWER backend = new QuickSearchBackend <string>(); #else Assert.Pass("QuickSearchBackend needs to be available for this test"); #endif break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } var query = backend.Parse("filter:\"Hello World\" \"Hello\" World filter:\" Hello filter:\"World"); Assert.That(query.Tokens, Is.EquivalentTo(new [] { "filter:\"Hello World\"", "\"Hello\"", "World", "filter:\" Hello filter:\"", "World" })); }
static ISearchBackend <TData> CreateSearchBackend <TData>(SearchBackendType type) { switch (type) { case SearchBackendType.Properties: return(new PropertiesSearchBackend <TData>()); case SearchBackendType.QuickSearch: #if QUICKSEARCH_2_1_0_OR_NEWER return(new QuickSearchBackend <TData>()); #endif throw new InvalidOperationException("QuickSearch needs to be installed to tests this backend"); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
public void Search_TokensShouldBeEmptyOnEmptySearchString(SearchBackendType backendType) { var searchElement = new SearchElement(); searchElement.RegisterSearchBackend(CreateSearchBackend <TestData>(backendType)); searchElement.RegisterSearchQueryHandler <TestData>(q => { Assert.DoesNotThrow(() => { var i = q.Tokens.Count; }); }); searchElement.AddSearchDataProperty(new PropertyPath(nameof(TestData.Name))); searchElement.Search(string.Empty); searchElement.Search(null); searchElement.Search(" "); }