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);
            }
        }
예제 #2
0
        public void HandlingExceptionIsRobust()
        {
            MockErrorVisualizerThatThrowsError errorVisualizer = new MockErrorVisualizerThatThrowsError();

            var exceptionHandler = new ViewExceptionHandler();

            exceptionHandler.HandleViewException(new Exception("OriginalMessage"), errorVisualizer);
        }
예제 #3
0
        public void HandleViewException_ThrowsExceptionHandlingException_WhenErrorVisualizaerHasProblems()
        {
            // Arrange
            var errorVisualizer  = new MockErrorVisualizerThatThrowsError();
            var exceptionHandler = new ViewExceptionHandler();

            // Act
            exceptionHandler.HandleViewException(new Exception("OriginalMessage"), errorVisualizer);

            // Assert - throw
        }
예제 #4
0
        public void FindIViewErrorWillREturnNullWhenNoViewErrorIsFound()
        {
            Control child            = new Control();
            Control parent           = new Control();
            Control controlNotToFind = new Control();

            controlNotToFind.Controls.Add(parent);
            parent.Controls.Add(child);

            var foundControl = ViewExceptionHandler.FindErrorVisualizer(child);

            Assert.IsNull(foundControl);
        }
예제 #5
0
        public void CanFindIViewErrorMessageInParents()
        {
            Control child  = new Control();
            Control parent = new Control();
            MockErrorVisualizingView controlToFind = new MockErrorVisualizingView();

            controlToFind.Controls.Add(parent);
            parent.Controls.Add(child);

            var foundControl = ViewExceptionHandler.FindErrorVisualizer(child);

            Assert.AreSame(controlToFind, foundControl);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
 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);
     }
 }
예제 #10
0
        public void FindErrorVisualizer_ReturnsNull_WhenNoViewErrorIsFound()
        {
            // Arrange
            var child            = new Control();
            var parent           = new Control();
            var controlNotToFind = new Control();

            // Act
            controlNotToFind.Controls.Add(parent);
            parent.Controls.Add(child);
            var foundControl = ViewExceptionHandler.FindErrorVisualizer(child);

            // Assert
            Assert.IsNull(foundControl);
        }
예제 #11
0
        public void FindErrorVisualizer_FindsIErrorVisualizerInParents()
        {
            // Arrange
            var child         = new Control();
            var parent        = new Control();
            var controlToFind = new MockErrorVisualizingView();

            // Act
            controlToFind.Controls.Add(parent);
            parent.Controls.Add(child);
            var foundControl = ViewExceptionHandler.FindErrorVisualizer(child);

            // Assert
            Assert.AreSame(controlToFind, foundControl);
        }
예제 #12
0
        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);
            }
        }
예제 #14
0
 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);
     }
 }
예제 #15
0
        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));
            }
        }
 /// <summary>
 /// Create a DiscountPresenter.
 /// </summary>
 /// <param name="discountsView"></param>
 public DiscountsPresenter(IDiscountsView discountsView)
 {
     this.discountsView   = discountsView;
     viewExceptionHandler = new ViewExceptionHandler();
 }