public static void TestAddRemoveProgressingEvent()
        {
            CancelProgressContext progress = new CancelProgressContext(new ProgressContext(TimeSpan.Zero));
            int percent = -1;

            EventHandler <ProgressEventArgs> handler = (object sender, ProgressEventArgs e) =>
            {
                percent = e.Percent;
            };

            progress.Progressing += handler;
            progress.AddTotal(200);
            progress.AddCount(100);
            Assert.That(percent, Is.EqualTo(50), "When halfway, the percent should be 50.");

            FakeRuntimeEnvironment.Instance.CurrentTiming.CurrentTiming = TimeSpan.FromSeconds(1);
            progress.AddCount(50);
            Assert.That(percent, Is.EqualTo(75), "150 of 200 is 75%.");

            progress.Progressing -= handler;

            FakeRuntimeEnvironment.Instance.CurrentTiming.CurrentTiming = TimeSpan.FromSeconds(1);
            progress.AddCount(50);
            Assert.That(percent, Is.EqualTo(75), "Since the event handler was removed, percent should stay the same.");
        }
        public static void TestCancelAddCount()
        {
            IProgressContext progress = new ProgressContext();

            progress.NotifyLevelStart();
            progress.AddTotal(100);
            progress.AddCount(10);
            progress = new CancelProgressContext(progress);
            Assert.DoesNotThrow(() => { progress.NotifyLevelStart(); });
            Assert.DoesNotThrow(() => { progress.AddTotal(50); });
            progress.Cancel = true;
            Assert.Throws <OperationCanceledException>(() => { progress.AddCount(10); });
            Assert.DoesNotThrow(() => { progress.NotifyLevelFinished(); });
        }
        public static void TestRemoveCount()
        {
            ProgressContext       progressContext = new ProgressContext(TimeSpan.Zero);
            CancelProgressContext cancelContext   = new CancelProgressContext(progressContext);
            int percent = 0;

            cancelContext.Progressing += (sender, e) =>
            {
                percent = e.Percent;
            };

            cancelContext.AddTotal(100);
            cancelContext.AddCount(10);
            Assert.That(percent, Is.EqualTo(10), "10 of 100 is 10%.");

            cancelContext.RemoveCount(50, 10);
            FakeRuntimeEnvironment.Instance.CurrentTiming.CurrentTiming = TimeSpan.FromMilliseconds(1000);
            cancelContext.AddCount(10);
            Assert.That(percent, Is.EqualTo(20), "10 of 50 is 20%.");
        }