public void LoadParts(string sku) { try { IProductCatalogRepository productCatalogRepository = SharePointServiceLocator.Current.GetInstance <IProductCatalogRepository>(); IEnumerable <Part> parts = productCatalogRepository.GetPartsByProductSku(sku); if (parts != null && parts.Any()) { view.Parts = parts; } else { // Show an errormessage in the view. Note, we couldn't use the ErrorVisualizer here, because // the errorVisualizer is outside of the updatepanel. Only things inside the update panel of // the view will be refreshed when the LoadParts button is clicked. view.ErrorMessage = Resources.NoPartsFoundError; } view.DataBind(); } catch (Exception ex) { // If an unhandled exception occurs in the view, then instruct the ErrorVisualizer to replace // the view with an errormessage. ViewExceptionHandler viewExceptionHandler = new ViewExceptionHandler(); viewExceptionHandler.HandleViewException(ex, ErrorVisualizer); } }
public void LoadDiscounts(string productSku) { try { if (string.IsNullOrEmpty(productSku)) { this.viewExceptionHandler.ShowFunctionalErrorMessage(TheProductSKUWasNotDefined, this.ErrorVisualizer); return; } IPricingRepository pricingRepository = SharePointServiceLocator.Current.GetInstance <IPricingRepository>(); IEnumerable <Discount> discounts = pricingRepository.GetDiscountsBySku(productSku); if (!discounts.Any()) { ShowSkuNotFoundError(productSku); return; } this.discountsView.Discounts = discounts; this.discountsView.DataBind(); } catch (Exception exception) { // An unhandled exception has occurred. Make sure the exception is logged and // a technical error message is displayed to the user. Because no message is specified here // the default message is used. viewExceptionHandler.HandleViewException(exception, this.ErrorVisualizer); } }
public void HandlingExceptionIsRobust() { MockErrorVisualizerThatThrowsError errorVisualizer = new MockErrorVisualizerThatThrowsError(); var exceptionHandler = new ViewExceptionHandler(); exceptionHandler.HandleViewException(new Exception("OriginalMessage"), errorVisualizer); }
public void HandleViewException_ThrowsExceptionHandlingException_WhenErrorVisualizaerHasProblems() { // Arrange var errorVisualizer = new MockErrorVisualizerThatThrowsError(); var exceptionHandler = new ViewExceptionHandler(); // Act exceptionHandler.HandleViewException(new Exception("OriginalMessage"), errorVisualizer); // Assert - throw }
public void HandleViewExceptionCanSwapMessage() { var exceptionHandler = new ViewExceptionHandler(); Exception exception = new Exception("Unhandled exception"); MockErrorVisualizingView mockErrorVisualizingView = new MockErrorVisualizingView(); exceptionHandler.HandleViewException(exception, mockErrorVisualizingView, "Something went wrong"); Assert.AreEqual("Something went wrong", mockErrorVisualizingView.ErrorMessage); MockLogger logger = SharePointServiceLocator.Current.GetInstance <ILogger>() as MockLogger; Assert.AreEqual("Unhandled exception", logger.ErrorMessage); }
public void HandleViewExceptionShouldLogAndShowDefaultExceptionMessage() { var exceptionHandler = new ViewExceptionHandler(); Exception exception = new Exception("Unhandled exception"); MockErrorVisualizingView mockErrorVisualizingView = new MockErrorVisualizingView(); exceptionHandler.HandleViewException(exception, mockErrorVisualizingView); Assert.IsTrue(mockErrorVisualizingView.DefaultErrorMessageShown); MockLogger logger = SharePointServiceLocator.Current.GetInstance <ILogger>() as MockLogger; Assert.AreEqual("Unhandled exception", logger.ErrorMessage); }
public void SetSiteData() { try { view.SetSiteData = estimatesService.GetSiteData(); } catch (Exception ex) { // If an unhandled exception occurs in the view, then instruct the ErrorVisualizer to replace // the view with an errormessage. ViewExceptionHandler viewExceptionHandler = this.ExceptionHandler ?? new ViewExceptionHandler(); viewExceptionHandler.HandleViewException(ex, this.ErrorVisualizer); } }
public void SetVendorDataWithTransactionCount() { try { view.VendorDataWithTransactionCount = VendorService.GetAllVendorsWithTransactionCount(); } catch (Exception ex) { // If an unhandled exception occurs in the view, then instruct the ErrorVisualizer to replace // the view with an errormessage. ViewExceptionHandler viewExceptionHandler = this.ExceptionHandler ?? new ViewExceptionHandler(); viewExceptionHandler.HandleViewException(ex, this.ErrorVisualizer); } }
public void HandleViewException_SwapsMessage() { // Arrange var exceptionHandler = new ViewExceptionHandler(); var exception = new Exception("Unhandled exception"); var mockErrorVisualizingView = new MockErrorVisualizingView(); // Act exceptionHandler.HandleViewException(exception, mockErrorVisualizingView, "Something went wrong"); // Assert Assert.AreEqual("Something went wrong", mockErrorVisualizingView.ErrorMessage); MockLogger logger = SharePointServiceLocator.GetCurrent().GetInstance <ILogger>() as MockLogger; Assert.AreEqual("Unhandled exception", logger.ErrorMessage); }
public void SetVendorDetails() { try { AccountsPayableProxyArgs proxyArgs = new AccountsPayableProxyArgs(); proxyArgs.VendorName = vendorName; string assemblyName = proxyArgs.ProxyOpsAssemblyName; view.AccountsPayable = vendorService.GetVendorAccountsPayable(proxyArgs, assemblyName); } catch (Exception ex) { // If an unhandled exception occurs in the view, then instruct the ErrorVisualizer to replace // the view with an errormessage. ViewExceptionHandler viewExceptionHandler = new ViewExceptionHandler(); viewExceptionHandler.HandleViewException(ex, this.ErrorVisualizer); } }
public void SetVendorDetails() { try { if (!string.IsNullOrEmpty(vendorId) && int.Parse(vendorId) > 0) { view.VendorTransaction = VendorService.GetTransactionByVendor(int.Parse(vendorId)); } else { throw new Exception("Vendor ID Must be Set before access Vendor Details"); } } catch (Exception ex) { // If an unhandled exception occurs in the view, then instruct the ErrorVisualizer to replace // the view with an errormessage. ViewExceptionHandler viewExceptionHandler = new ViewExceptionHandler(); viewExceptionHandler.HandleViewException(ex, this.ErrorVisualizer); } }
public void ShowPricing(string productSku) { try { if (!string.IsNullOrEmpty(productSku)) { IPricingRepository pricingRepository = SharePointServiceLocator.Current.GetInstance <IPricingRepository>(); Price price = pricingRepository.GetPriceBySku(productSku); if (price == null) { this.PriceText = "There is no price available for this product."; } else { this.PriceText = price.Value.ToString("C", CultureInfo.CurrentUICulture); } } else { PriceText = "The product has not been specified."; } this.DataBind(); } catch (Exception ex) { // If an unknown exception occurs we want to: // 1. Log the error // 2. Display a friendly (Non technical) error message. // The ViewExceptionHandler will do that for us: ViewExceptionHandler viewExceptionHandler = new ViewExceptionHandler(); // In this example, we are looking for an error visualizer up in the tree and using that to display the error. // Find the error Visualizer (in this case, the one that was added by the PricingWebPart.cs: IErrorVisualizer errorVisualizer = ViewExceptionHandler.FindErrorVisualizer(this); // Now log the error and display a friendly error message using the error visualizer. viewExceptionHandler.HandleViewException(ex, errorVisualizer, string.Format(CultureInfo.CurrentUICulture, "Due to a technical problem, the pricing information for sku '{0}' could not be retrieved. Please try again later.", productSku)); } }