private void SearchWorkerDoWork(object sender, DoWorkEventArgs e) { ProductSearchResult result = null; try { var productName = (string)e.Argument; using (var harness = new ProductRepositoryHarness(_repo)) { result = harness.Search(productName); } } catch (Exception ex) { Log.Error("SearchWorkerDoWork - Error.", ex); result = new ProductSearchResult(false, true, null); } finally { if (((BackgroundWorker)sender).CancellationPending) { e.Cancel = true; } e.Result = result; } }
private void SearchWorkerDoWork(object sender, DoWorkEventArgs e) { ProductSearchResult result = null; try { var productName = (string)e.Argument; using (var harness = new ProductRepositoryHarness(_repo)) { result = harness.Search(productName); } } catch (Exception ex) { Log.Error("SearchWorkerDoWork - Error.", ex); result = new ProductSearchResult(false, true, null); } finally { if (((BackgroundWorker)sender).CancellationPending) e.Cancel = true; e.Result = result; } }
public void Should_return_error_is_true_if_error_has_occurred() { var mockRepo = MockRepository.GenerateMock<IProductSearchRepository<Product>>(); mockRepo.Stub(x => x.Search("product")).Do((Func<string, Product>)delegate { throw new DataAccessException("test", new Exception()); }); var harness = new ProductRepositoryHarness(mockRepo); var result = harness.Search("product"); Assert.IsTrue(result.HasError); }
public void Should_return_error_is_true_if_error_has_occurred() { var mockRepo = MockRepository.GenerateMock <IProductSearchRepository <Product> >(); mockRepo.Stub(x => x.Search("product")).Do((Func <string, Product>) delegate { throw new DataAccessException("test", new Exception()); }); var harness = new ProductRepositoryHarness(mockRepo); var result = harness.Search("product"); Assert.IsTrue(result.HasError); }
public void Should_return_productSearchResult_with_correct_output() { var mockRepo = MockRepository.GenerateMock<IProductSearchRepository<Product>>(); mockRepo.Stub(x => x.Search("product")).Do((Func<string, Product>)delegate { return new Product(string.Empty, "5"); }); var harness = new ProductRepositoryHarness(mockRepo); var result = harness.Search("product"); Assert.AreEqual("5", result.Product.SalePrice); Assert.AreEqual(string.Empty, result.Product.imageUrl); }
public void Should_return_productSearchResult_with_correct_output() { var mockRepo = MockRepository.GenerateMock <IProductSearchRepository <Product> >(); mockRepo.Stub(x => x.Search("product")).Do((Func <string, Product>) delegate { return(new Product(string.Empty, "5")); }); var harness = new ProductRepositoryHarness(mockRepo); var result = harness.Search("product"); Assert.AreEqual("5", result.Product.SalePrice); Assert.AreEqual(string.Empty, result.Product.imageUrl); }