public void Test_Construct_WithAddExceptionHandlingFalse_ShouldNotActivateExceptionHandling()
 {
     //---------------Set up test pack-------------------
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     var unhandledExceptionHelper = new UnhandledExceptionHelperWin(false);
     //---------------Test Result -----------------------
     Assert.IsFalse(unhandledExceptionHelper.IsExceptionHandlingActive);
 }
        public void Test_Construct_WithAddExceptionHandlingFalse_ShouldNotActivateExceptionHandling()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var unhandledExceptionHelper = new UnhandledExceptionHelperWin(false);

            //---------------Test Result -----------------------
            Assert.IsFalse(unhandledExceptionHelper.IsExceptionHandlingActive);
        }
 public void Test_AddExceptionHandling_ShouldAddExceptionHandling()
 {
     //---------------Set up test pack-------------------
     var unhandledExceptionHelper = new UnhandledExceptionHelperWin(false);
     //---------------Assert Precondition----------------
     Assert.IsFalse(unhandledExceptionHelper.IsExceptionHandlingActive);
     //---------------Execute Test ----------------------
     unhandledExceptionHelper.AddExceptionHandling();
     //---------------Test Result -----------------------
     Assert.IsTrue(unhandledExceptionHelper.IsExceptionHandlingActive);
 }
        public void Test_AddExceptionHandling_ShouldAddExceptionHandling()
        {
            //---------------Set up test pack-------------------
            var unhandledExceptionHelper = new UnhandledExceptionHelperWin(false);

            //---------------Assert Precondition----------------
            Assert.IsFalse(unhandledExceptionHelper.IsExceptionHandlingActive);
            //---------------Execute Test ----------------------
            unhandledExceptionHelper.AddExceptionHandling();
            //---------------Test Result -----------------------
            Assert.IsTrue(unhandledExceptionHelper.IsExceptionHandlingActive);
        }
        public void Test_WhenHandlerNotActive_ShouldNotHandleUnhandledUIFormException()
        {
            UnhandledExceptionEventArgs unhandledExceptionEventArgs = null;

            using (var unhandledExceptionHelper = new UnhandledExceptionHelperWin((sender, args) => unhandledExceptionEventArgs = args, false))
            {
                //---------------Set up test pack-------------------
                //---------------Assert Precondition----------------
                Assert.IsFalse(unhandledExceptionHelper.IsExceptionHandlingActive);
                //---------------Execute Test ----------------------
                var exception = Assert.Throws <Win32Exception>(CauseUnhandledException, "Expected to throw an Win32Exception");
                //---------------Test Result -----------------------
                Assert.IsNull(unhandledExceptionEventArgs, "The error would have popped up an exception dialog box instead.");
                StringAssert.Contains("Error creating window handle", exception.Message);
            }
        }
        public void Test_WhenHandlerActive_ShouldHandleUnhandledUIFormException()
        {
            UnhandledExceptionEventArgs unhandledExceptionEventArgs = null;

            using (var unhandledExceptionHelper = new UnhandledExceptionHelperWin((sender, args) => unhandledExceptionEventArgs = args))
            {
                //---------------Set up test pack-------------------
                //---------------Assert Precondition----------------
                Assert.IsTrue(unhandledExceptionHelper.IsExceptionHandlingActive);
                //---------------Execute Test ----------------------
                var exception = Assert.Throws <Win32Exception>(CauseUnhandledException, "Expected to throw an Win32Exception");
                //---------------Test Result -----------------------
                Assert.IsNotNull(unhandledExceptionEventArgs, "Should have thrown an unhandled exception");
                Assert.IsInstanceOf <Win32Exception>(unhandledExceptionEventArgs.ExceptionObject);
                var unhandledExceptionObject = (Win32Exception)unhandledExceptionEventArgs.ExceptionObject;
                StringAssert.Contains("Error creating window handle", exception.Message);
                Assert.AreEqual(exception.Message, unhandledExceptionObject.Message, "Message was expected to be the same as the exception");
            }
        }
 public void Test_WhenHandlerActive_ShouldHandleUnhandledUIFormException()
 {
     UnhandledExceptionEventArgs unhandledExceptionEventArgs = null;
     using (var unhandledExceptionHelper = new UnhandledExceptionHelperWin((sender, args) => unhandledExceptionEventArgs = args))
     {
         //---------------Set up test pack-------------------
         //---------------Assert Precondition----------------
         Assert.IsTrue(unhandledExceptionHelper.IsExceptionHandlingActive);
         //---------------Execute Test ----------------------
         var exception = Assert.Throws<Win32Exception>(CauseUnhandledException, "Expected to throw an Win32Exception");
         //---------------Test Result -----------------------
         Assert.IsNotNull(unhandledExceptionEventArgs, "Should have thrown an unhandled exception");
         Assert.IsInstanceOf<Win32Exception>(unhandledExceptionEventArgs.ExceptionObject);
         var unhandledExceptionObject = (Win32Exception)unhandledExceptionEventArgs.ExceptionObject;
         StringAssert.Contains("Error creating window handle", exception.Message);
         Assert.AreEqual(exception.Message, unhandledExceptionObject.Message, "Message was expected to be the same as the exception");
     }
 }
 public void Test_WhenHandlerNotActive_ShouldNotHandleUnhandledUIFormException()
 {
     UnhandledExceptionEventArgs unhandledExceptionEventArgs = null;
     using (var unhandledExceptionHelper = new UnhandledExceptionHelperWin((sender, args) => unhandledExceptionEventArgs = args, false))
     {
         //---------------Set up test pack-------------------
         //---------------Assert Precondition----------------
         Assert.IsFalse(unhandledExceptionHelper.IsExceptionHandlingActive);
         //---------------Execute Test ----------------------
         var exception = Assert.Throws<Win32Exception>(CauseUnhandledException, "Expected to throw an Win32Exception");
         //---------------Test Result -----------------------
         Assert.IsNull(unhandledExceptionEventArgs, "The error would have popped up an exception dialog box instead.");
         StringAssert.Contains("Error creating window handle", exception.Message);
     }
 }