public void When_a_search_is_cancelled_it_calls_back_with_a_cancelled_result()
        {
            ProductSearchResult results = null;

            // Arrange
            var mockRepo = MockRepository.GenerateMock<IProductSearchRepository<Product>>();
            var searchResult = new Product(string.Empty, string.Empty);

            mockRepo.Stub(x => x.Search("product")).Do((Func<string, Product>) delegate
            {
                Thread.Sleep(2000);
                return searchResult;
            });

            // Act
            var searchWorker = new ProductSearchWorker(mockRepo, (cb, worker) =>
            {
                results = cb;
            }, "product");
            searchWorker.CancelSearch();

            Thread.Sleep(5000);

            // Assert
            Assert.IsTrue(results.IsCancelled);
        }
        public void DoSearch(string productName, IProductSearchRepository <Product> repo)
        {
            if (_productSearchWorker != null)
            {
                _productSearchWorker.CancelSearch();
            }

            _productSearchWorker = new ProductSearchWorker(repo, ProcessSearchResult, productName);
        }