示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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));
            }
        }