예제 #1
0
        public void LifeCycle()
        {
            // Arrange
            var progressHandler = new StatusBarDownloadProgressHandler(dummyStatusBar, dummyInstaller, logger);

            // 1. Initial request
            dummyInstaller.SimulateProgressChanged(new InstallationProgressChangedEventArgs(0, 1000));
            dummyStatusBar.CheckLastCallWasSetupCall(0, 1000);

            // 2. Progress updates
            dummyInstaller.SimulateProgressChanged(new InstallationProgressChangedEventArgs(100, 1000));
            dummyStatusBar.CheckLastCallWasInProgressCall(100, 1000);


            // 3. Cleanup - reset the statusbar
            dummyInstaller.SimulateInstallFinished(new System.ComponentModel.AsyncCompletedEventArgs(null, false, null));
            dummyStatusBar.CheckLastCallWasCleanup();

            dummyStatusBar.ProgressCallCount.Should().Be(3);
            dummyInstaller.AssertNoEventHandlersRegistered();

            // 4. Dispose
            progressHandler.Dispose();
            dummyStatusBar.ProgressCallCount.Should().Be(3); // progress should not be called since already cleaned up
            dummyInstaller.AssertNoEventHandlersRegistered();
        }
예제 #2
0
        public void LifeCycle_ProgressChanged_CriticalException_NotSuppressed()
        {
            // Arrange
            dummyStatusBar.ProgressOperation = () => throw new StackOverflowException("xxx");

            var progressHandler = new StatusBarDownloadProgressHandler(dummyStatusBar, dummyInstaller, logger);

            // Act and Assert: exception should be suppressed
            Action act = () => dummyInstaller.SimulateProgressChanged(new InstallationProgressChangedEventArgs(0, 1000));

            act.Should().Throw <StackOverflowException>().And.Message.Should().Be("xxx");
            logger.AssertPartialOutputStringDoesNotExist("xxx");
        }
예제 #3
0
        public void LifeCycle_InstallationCompleted_CriticalException_NotSuppressed()
        {
            // Arrange
            var progressHandler = new StatusBarDownloadProgressHandler(dummyStatusBar, dummyInstaller, logger);

            // Initialize the status bar
            dummyInstaller.SimulateProgressChanged(new InstallationProgressChangedEventArgs(0, 100));

            // Throw an exception next time the progress operation is called
            dummyStatusBar.ProgressOperation = () => throw new StackOverflowException("xxx");

            // Act and Assert: exception should be suppressed
            Action act = () => dummyInstaller.SimulateInstallFinished(new System.ComponentModel.AsyncCompletedEventArgs(null, true, null));

            act.Should().Throw <StackOverflowException>().And.Message.Should().Be("xxx");
            logger.AssertPartialOutputStringDoesNotExist("xxx");
        }
예제 #4
0
        public void LifeCycle_ProgressChanged_NonCriticalException_Suppressed()
        {
            // Arrange
            bool opExecuted = false;

            dummyStatusBar.ProgressOperation = () =>
            {
                opExecuted = true;
                throw new InvalidOperationException("xxx");
            };

            var progressHandler = new StatusBarDownloadProgressHandler(dummyStatusBar, dummyInstaller, logger);

            // Act and Assert: exception should be suppressed
            dummyInstaller.SimulateProgressChanged(new InstallationProgressChangedEventArgs(0, 1000));
            opExecuted.Should().BeTrue();

            logger.AssertPartialOutputStringExists("xxx");
        }
예제 #5
0
        public void LifeCycle_Dispose_UnhooksEventHandlers()
        {
            // Arrange
            var progressHandler = new StatusBarDownloadProgressHandler(dummyStatusBar, dummyInstaller, logger);

            // 1. Initial request
            dummyInstaller.SimulateProgressChanged(new InstallationProgressChangedEventArgs(0, 1000));
            dummyStatusBar.CheckLastCallWasSetupCall(0, 1000);

            // 2. Progress updates
            dummyInstaller.SimulateProgressChanged(new InstallationProgressChangedEventArgs(100, 1000));
            dummyStatusBar.CheckLastCallWasInProgressCall(100, 1000);

            dummyStatusBar.ProgressCallCount.Should().Be(2);

            // 3. Dispose - unhook event handlers, then simulate more events
            progressHandler.Dispose();

            dummyInstaller.AssertNoEventHandlersRegistered();
            dummyStatusBar.CheckLastCallWasCleanup();
            dummyStatusBar.ProgressCallCount.Should().Be(3);
        }
예제 #6
0
        public void LifeCycle_InstallationCompleted_NonCriticalException_Suppressed()
        {
            // Arrange
            bool opExecuted = false;

            var progressHandler = new StatusBarDownloadProgressHandler(dummyStatusBar, dummyInstaller, logger);

            // Initialize the status bar
            dummyInstaller.SimulateProgressChanged(new InstallationProgressChangedEventArgs(0, 100));

            dummyStatusBar.ProgressOperation = () =>
            {
                opExecuted = true;
                throw new InvalidOperationException("xxx");
            };

            // Sanity check
            opExecuted.Should().BeFalse();

            // Act and Assert: exception should be suppressed
            dummyInstaller.SimulateInstallFinished(new System.ComponentModel.AsyncCompletedEventArgs(null, false, null));
            opExecuted.Should().BeTrue();
            logger.AssertPartialOutputStringExists("xxx");
        }