public void should_raise_SearchCompleted_only_once_regardless_of_threads_number()
        {
            searcher = new UsersByKeywordsSearcher(twitterWrapper, executor);

            for (int i = 0; i < NUMBER_OF_SEARCHES; i++)
            {
                wait = new ManualResetEvent(false);
                PerformSearch();
            }
        }
        public void should_redirect_search_request_to_twitter_service()
        {
            var searcher = new UsersByKeywordsSearcher(twitterWrapper, null);

            const string keywords = "keywords";
            var usersFound = new List<int> {1, 2};

            twitterWrapper.Stub(x => x.FindByKeywords(keywords)).Return(usersFound);

            var result = searcher.Find(keywords);

            Assert.AreEqual(usersFound, result);
        }
        public void should_search_for_multiple_keywords_via_search_executor()
        {
            searchExecutor = new SynchronousExecutor();
            var searcher = new UsersByKeywordsSearcher(twitterWrapper, searchExecutor);

            twitterWrapper.Stub(x => x.FindByKeywords(keyword1)).Return(users1);
            twitterWrapper.Stub(x => x.FindByKeywords(keyword2)).Return(users2);

            bool isSearchCompletedRaised = false;

            searcher.SearchCompleted += (sender, args) =>
            {
                CollectionAssert.AreEqual(new[] { 1, 2, 3 }, args.Users.ToArray());
                isSearchCompletedRaised = true;
            };

            searcher.Find(keyword1, keyword2);
            searchExecutor.ExecuteUntilIdle();

            Assert.IsTrue(isSearchCompletedRaised);
        }