private static void TestProvider(AsyncSearchProvider provider) { var session = new AsyncSearchSession(); var ctx = SearchContext.Empty; var items = new List <SearchItem>(); var enumerable = provider.fetchItems(ctx, items, provider); Assert.IsEmpty(items); session.Reset(enumerable); // Test fetching all objects var total = AsyncSearchProvider.NumberNullItems + AsyncSearchProvider.NumberSearchItems; session.FetchSome(items, total, false); Assert.AreEqual(AsyncSearchProvider.NumberSearchItems, items.Count); items = new List <SearchItem>(); session.FetchSome(items, total, false); Assert.AreEqual(0, items.Count); // Should be empty since enumerator is at the end enumerable = provider.fetchItems(ctx, items, provider); session.Reset(enumerable); session.FetchSome(items, AsyncSearchProvider.NumberSearchItems, false); Assert.AreEqual(AsyncSearchProvider.NumberSearchItems - AsyncSearchProvider.NumberNullItems, items.Count); // Test fetching non-null objects enumerable = provider.fetchItems(ctx, items, provider); session.Reset(enumerable); session.FetchSome(items, total, true); Assert.AreEqual(AsyncSearchProvider.NumberSearchItems, items.Count); items = new List <SearchItem>(); session.FetchSome(items, total, false); Assert.AreEqual(0, items.Count); // Should be empty since enumerator is at the end enumerable = provider.fetchItems(ctx, items, provider); session.Reset(enumerable); session.FetchSome(items, AsyncSearchProvider.NumberSearchItems, true); Assert.AreEqual(AsyncSearchProvider.NumberSearchItems, items.Count); // Fetch items time constrained var maxFetchTimeMs = 1; items = new List <SearchItem>(); provider.UseSleep = true; provider.SleepTimeMS = 5; session.Reset(enumerable); session.FetchSome(items, maxFetchTimeMs); Assert.AreEqual(0, items.Count); // Fetch items with time and size constraints items = new List <SearchItem>(); enumerable = provider.fetchItems(ctx, items, provider); session.Reset(enumerable); provider.SleepTimeMS = 1; maxFetchTimeMs = provider.SleepTimeMS * AsyncSearchProvider.NumberNullItems; session.FetchSome(items, AsyncSearchProvider.NumberSearchItems, true, maxFetchTimeMs); Assert.Less(items.Count, AsyncSearchProvider.NumberSearchItems); }
public void FetchSomeIEnumerable() { var provider = new AsyncSearchProvider(Guid.NewGuid().ToString()); TestProvider(provider); }
public void EnableService() { SearchService.Enable(SearchContext.Empty); SearchService.Filter.ResetFilter(true); m_Provider = new AsyncSearchProvider(Guid.NewGuid().ToString()); }