예제 #1
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);
        }
예제 #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 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);
        }
예제 #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 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);
        }