public void ProgressObserver_StartAndStopObserving_ArgChecks()
        {
            // Can't test the overloaded without IProgressVisualizer since using GlobalService to get various services.

            // StartObserving (IProgressController, IProgressVisualizer)
            Exceptions.Expect <ArgumentNullException>(() => ProgressObserver.StartObserving(this.testController, (IProgressVisualizer)null));
            Exceptions.Expect <ArgumentNullException>(() => ProgressObserver.StartObserving((IProgressController)null, this.testVisualizer));
            Exceptions.Expect <ArgumentNullException>(() => ProgressObserver.StartObserving((IProgressController)null, (IProgressVisualizer)null));

            // StartObserving (IServiceProvider, IProgressEvents,IProgressVisualizer)
            Exceptions.Expect <ArgumentNullException>(() => ProgressObserver.StartObserving((IServiceProvider)null, this.progressEvents, this.testVisualizer));
            Exceptions.Expect <ArgumentNullException>(() => ProgressObserver.StartObserving(this.testServiceProvider, this.progressEvents, null));
            Exceptions.Expect <ArgumentNullException>(() => ProgressObserver.StartObserving(this.testServiceProvider, null, this.testVisualizer));
            Exceptions.Expect <ArgumentNullException>(() => ProgressObserver.StartObserving((IServiceProvider)null, (IProgressEvents)null, (IProgressVisualizer)null));

            // StopObserving
            Exceptions.Expect <ArgumentNullException>(() => ProgressObserver.StopObserving(null));

            // Invalid IProgressController
            this.testController.Events.Steps = null;
            Exceptions.Expect <InvalidOperationException>(() => ProgressObserver.StartObserving(this.testController, this.testVisualizer));
            this.testController.Events = null;
            Exceptions.Expect <InvalidOperationException>(() => ProgressObserver.StartObserving(this.testController, this.testVisualizer));

            // Invalid IProgressEvents
            Exceptions.Expect <InvalidOperationException>(() => ProgressObserver.StartObserving(this.testServiceProvider, this.progressEvents, this.testVisualizer));
        }
        public void ProgressObserver_StopObserving_Twice()
        {
            this.testSubject = ProgressObserver.StartObserving(this.testController, this.testVisualizer);

            ProgressObserver.StopObserving(this.testSubject);
            Assert.IsTrue(this.testSubject.IsDisposed, "Expecting to be disposed");

            ProgressObserver.StopObserving(this.testSubject);
            Assert.IsTrue(this.testSubject.IsDisposed, "Expecting to remain disposed");
        }
        public void ProgressObserver_StartAndStopObserving_OnBackgroundThread()
        {
            this.threadService.SetCurrentThreadIsUIThread(false);

            this.testSubject = ProgressObserver.StartObserving(this.testController, this.testVisualizer);
            Assert.AreSame(this.testVisualizer, this.testSubject.Visualizer, "Unexpected visualizer");
            Assert.IsNotNull(this.testSubject, "Failed to create observer on a background thread");

            Assert.IsFalse(this.testSubject.IsDisposed, "Not expecting to be disposed");
            ProgressObserver.StopObserving(this.testSubject);
            Assert.AreSame(this.testVisualizer, this.testSubject.Visualizer, "Unexpected visualizer");
            Assert.IsTrue(this.testSubject.IsDisposed, "Expecting to be disposed");
        }
        public void ProgressObserver_StartAndStopObserving_OnForegroundThread()
        {
            this.threadService.SetCurrentThreadIsUIThread(true);

            this.testSubject = ProgressObserver.StartObserving(this.testController, this.testVisualizer);
            this.testSubject.Visualizer.Should().Be(this.testVisualizer, "Unexpected visualizer");
            this.testSubject.Should().NotBeNull("Failed to create observer on a foreground thread");

            this.testSubject.IsDisposed.Should().BeFalse("Not expecting to be disposed");
            ProgressObserver.StopObserving(this.testSubject);
            this.testSubject.Visualizer.Should().Be(this.testVisualizer, "Unexpected visualizer");
            this.testSubject.IsDisposed.Should().BeTrue("Expecting to be disposed");
        }
        public void ProgressObserver_StartObserving_StateTransfer()
        {
            var observer = ProgressObserver.StartObserving(this.testController, this.testVisualizer);

            ProgressObserver.StopObserving(observer);
            this.CreateTestSubject(observer.State);

            Assert.AreNotSame(this.testSubject.State, observer, "Test setup error: should be different");
            Assert.AreSame(this.testSubject.State, observer.State, "The state should transfer");
            Assert.IsFalse(this.testSubject.IsDisposed, "Not expecting to be disposed");

            ProgressObserver.StopObserving(this.testSubject);
            Assert.AreSame(this.testVisualizer, this.testSubject.Visualizer, "Unexpected visualizer");
            Assert.IsTrue(this.testSubject.IsDisposed, "Expecting to be disposed");
        }