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