Beispiel #1
0
        public void ResetResetsCompletely()
        {
            // Arrange
            var tested = new TestedProgressReporter();

            // Act
            tested.Restart(2);
            tested.ReportProgress();
            tested.ReportProgress();
            tested.Reset();

            Assert.True(tested.IsIdle);
            Assert.False(tested.IsRunning);
            Assert.False(tested.UsedAtLestOnce);
            Assert.Equal(default(TimeSpan), tested.AverageCycleDuration);
            Assert.Equal(0, tested.AverageCycleStep);
            Assert.Equal(0, tested.CompletedPercent);
            Assert.Equal(0, tested.CompletedRawValue);
            Assert.Equal(0, tested.CurrentCycle);
            Assert.Equal(0, tested.CurrentRawValue);
            Assert.Equal(0, tested.LastCycleStep);
            Assert.Equal(0, tested.PreviousRawValue);
            Assert.Equal(0, tested.RemainingCyclesEstimate);
            Assert.Equal(100, tested.RemainingPercent);
            Assert.Equal(0, tested.RemainingRawValue);
            Assert.Equal(default(TimeSpan), tested.RemainingTimeEstimate);
            Assert.Equal(default(TimeSpan), tested.Elapsed);
            Assert.Equal(0, tested.TargetCycleEstimate);
            Assert.Equal(0, tested.TargetRawValue);
        }
Beispiel #2
0
        public void ReportingProgressRaisesPropertyChangedEvents()
        {
            var tested = new TestedProgressReporter();

            tested.Start(2);

            var receivedEvents = new HashSet <string>();

            tested.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            tested.ReportProgress();

            Assert.Contains(nameof(tested.AverageCycleDuration), receivedEvents);
            Assert.Contains(nameof(tested.AverageCycleStep), receivedEvents);
            Assert.Contains(nameof(tested.CompletedPercent), receivedEvents);
            Assert.Contains(nameof(tested.CompletedRawValue), receivedEvents);
            Assert.Contains(nameof(tested.CurrentCycle), receivedEvents);
            Assert.Contains(nameof(tested.CurrentRawValue), receivedEvents);
            Assert.Contains(nameof(tested.Elapsed), receivedEvents);
            Assert.Contains(nameof(tested.IsIdle), receivedEvents);
            Assert.Contains(nameof(tested.IsRunning), receivedEvents);
            Assert.Contains(nameof(tested.LastCycleStep), receivedEvents);
            Assert.Contains(nameof(tested.PreviousRawValue), receivedEvents);
            Assert.Contains(nameof(tested.RemainingCyclesEstimate), receivedEvents);
            Assert.Contains(nameof(tested.RemainingPercent), receivedEvents);
            Assert.Contains(nameof(tested.RemainingRawValue), receivedEvents);
            Assert.Contains(nameof(tested.RemainingTimeEstimate), receivedEvents);
            Assert.Contains(nameof(tested.UsedAtLestOnce), receivedEvents);
            Assert.Contains(nameof(tested.LastCycleTotalMillisecondsElapsed), receivedEvents);
            Assert.Contains(nameof(tested.CurrentCycleDuration), receivedEvents);
            Assert.Contains(nameof(tested.LastCycleDurationMs), receivedEvents);
        }
Beispiel #3
0
        public void ReportProgressTest2()
        {
            const int numberOfIterations = 10;
            var       tested             = new TestedProgressReporter();

            Thread.Sleep(1);
            Assert.Equal(0L, tested.Elapsed.TotalMilliseconds);
            Assert.False(tested.IsRunning);
            tested.Restart(numberOfIterations);
            const long remainingMsPrevious = long.MaxValue;
            var        elapsedMs           = 0.0;

            for (var i = 0; i < numberOfIterations; ++i)
            {
                Assert.True(tested.IsRunning);
                var from = i;
                var to   = i + 1;
                Thread.Sleep(1);
                var remainingMs = tested.RemainingTimeEstimate.TotalMilliseconds;
                tested.ReportProgress();
                elapsedMs = tested.Elapsed.TotalMilliseconds;
                Assert.True(remainingMsPrevious > remainingMs);
            }

            Assert.False(tested.IsRunning);
            Assert.Equal(elapsedMs, tested.Elapsed.TotalMilliseconds);
        }
Beispiel #4
0
        public void CurrentCycleCannotBeGreaterThanTargetValue()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);
            Assert.Throws <ArgumentOutOfRangeException>(() => tested.ReportProgress(201));
        }
Beispiel #5
0
        public void TestedProgressReporterCompletedPercentNeverGoesAbove100()
        {
            var tested = new TestedProgressReporter();

            tested.Start(1);
            tested.ReportProgress();
            try { tested.ReportProgress(); } catch { }
            Assert.Equal(100, tested.CompletedPercent);
        }
Beispiel #6
0
        public void ProgressReporterCompletedPercentIsCorrect()
        {
            var tested = new TestedProgressReporter();

            tested.Start(1);
            Assert.Equal(0, tested.CompletedPercent);
            tested.ReportProgress();
            Assert.Equal(100, tested.CompletedPercent);
        }
Beispiel #7
0
        public void ProgressCannotRegress()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);

            tested.ReportProgress(100);
            Assert.Throws <ArgumentException>(() => tested.ReportProgress(99));
        }
Beispiel #8
0
        public void PauseDoesNothingWhenNotRunning()
        {
            var tested = new TestedProgressReporter();

            Assert.False(tested.IsRunning);
            Assert.True(tested.IsIdle);
            tested.Pause();
            Assert.False(tested.IsRunning);
            Assert.True(tested.IsIdle);
        }
Beispiel #9
0
        public void ProgressReporterIsIdleIsCorrect()
        {
            var tested = new TestedProgressReporter();

            tested.Start(1);
            Assert.False(tested.IsIdle);
            tested.ReportProgress();
            Assert.True(tested.IsIdle);
            try { tested.ReportProgress(); } catch { }
            Assert.True(tested.IsIdle);
        }
Beispiel #10
0
        public void TargetCycleEstimateIsZeroWhenFinished()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);

            Assert.Equal(200, tested.TargetCycleEstimate);

            tested.ReportProgress(100);
            tested.ReportProgress(200);

            Assert.Equal(2, tested.TargetCycleEstimate, 1);
        }
Beispiel #11
0
        public void CurrentCycleStopsIncrementingAfterCompletion()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);
            tested.ReportProgress(200);
            try { tested.ReportProgress(200); } catch { }
            try { tested.ReportProgress(200); } catch { }
            try { tested.ReportProgress(200); } catch { }
            try { tested.ReportProgress(200); } catch { }

            Assert.Equal(1, tested.CurrentCycle);
        }
Beispiel #12
0
        public void ProgressReportProgressIsThreadSafe()
        {
            var tested = new TestedProgressReporter();

            tested.Start(100);

            Parallel.For(0, 100, (i) =>
            {
                tested.ReportProgress();
            });

            Assert.Equal(100, tested.CurrentRawValue);
            Assert.False(tested.IsRunning);
            Assert.True(tested.IsIdle);
        }
Beispiel #13
0
        public void ReportingProgressProperlyUpdatesRemaingPercent(int iterations)
        {
            var tested = new TestedProgressReporter();

            tested.Start(iterations);
            var step = 100 / iterations;

            for (int i = 0; i < iterations; ++i)
            {
                tested.ReportProgress();
                var expectedCompletedPercent = step * (i + 1);
                var expectedRemaingPercent   = 100 - expectedCompletedPercent;
                Assert.Equal(expectedRemaingPercent, tested.RemainingPercent, 1);
            }
        }
Beispiel #14
0
        public void UnpauseUnpauses()
        {
            var tested = new TestedProgressReporter();

            tested.Start(2);

            tested.ReportProgress();
            tested.Pause();

            tested.UnPause();
            var elapsed = tested.Elapsed;

            Thread.Sleep(1);
            Assert.True(tested.Elapsed > elapsed);
        }
Beispiel #15
0
        public void ReportingProgressWithArgumentProperlyUpdatesCurrentCycle()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);

            Assert.Equal(0, tested.CurrentCycle);

            tested.ReportProgress(100);

            Assert.Equal(1, tested.CurrentCycle);

            tested.ReportProgress(200);

            Assert.Equal(2, tested.CurrentCycle);
        }
Beispiel #16
0
        public void ReportingProgressWithArgumentProperlyUpdatesRemainingRawValue()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);

            Assert.Equal(200, tested.RemainingRawValue, 1);

            tested.ReportProgress(100);

            Assert.Equal(100, tested.RemainingRawValue, 1);

            tested.ReportProgress(200);

            Assert.Equal(0, tested.RemainingRawValue, 1);
        }
Beispiel #17
0
        public void PausePauses()
        {
            var tested = new TestedProgressReporter();

            tested.Start(2);

            tested.ReportProgress();
            tested.Pause();

            var elapsed = tested.Elapsed;

            Thread.Sleep(1);

            Assert.Equal(elapsed, tested.Elapsed);
            Assert.False(tested.IsRunning);
            Assert.True(tested.IsIdle);
        }
Beispiel #18
0
        public void FinishTest()
        {
            const int numberOfIterations = 5;
            var       tested             = new TestedProgressReporter();

            Assert.False(tested.IsRunning);
            tested.Restart(numberOfIterations * 2);
            for (var i = 0; i < numberOfIterations; ++i)
            {
                Assert.True(tested.IsRunning);
                tested.ReportProgress();
            }
            Assert.False(tested.IsIdle);
            Assert.True(tested.IsRunning);
            tested.Pause();

            Assert.False(tested.IsRunning);
            Assert.True(tested.IsIdle);
        }
Beispiel #19
0
        public void LastCycleStepIsCorrect()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);

            Assert.Equal(0, tested.LastCycleStep);

            tested.ReportProgress(100);

            Assert.Equal(100, tested.LastCycleStep);

            tested.ReportProgress(150);

            Assert.Equal(50, tested.LastCycleStep);

            tested.ReportProgress(200);

            Assert.Equal(50, tested.LastCycleStep);
        }
Beispiel #20
0
        public void AverageCycleStepIsCorrect()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);

            Assert.Equal(0, tested.AverageCycleStep);

            tested.ReportProgress(100);

            Assert.Equal(100, tested.AverageCycleStep);

            tested.ReportProgress(150);

            Assert.Equal(75.0, tested.AverageCycleStep, 1);

            tested.ReportProgress(200);

            Assert.Equal(66.7, tested.AverageCycleStep, 1);
        }
Beispiel #21
0
        public void TargetCycleEstimateIsCorrectEnough()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);

            Assert.Equal(200, tested.TargetCycleEstimate);

            tested.ReportProgress(100);

            Assert.Equal(2, tested.TargetCycleEstimate, 1);

            tested.ReportProgress(100);

            Assert.Equal(4, tested.TargetCycleEstimate, 1);

            tested.ReportProgress(200);

            Assert.Equal(3, tested.TargetCycleEstimate, 1);
        }
Beispiel #22
0
        public void ProgressReporterHasValidStateAfterCreation()
        {
            var tested = new TestedProgressReporter();

            Assert.True(tested.IsIdle);
            Assert.False(tested.IsRunning);
            Assert.False(tested.UsedAtLestOnce);
            Assert.Equal(default(TimeSpan), tested.AverageCycleDuration);
            Assert.Equal(0, tested.AverageCycleStep);
            Assert.Equal(0, tested.CompletedPercent);
            Assert.Equal(0, tested.CompletedRawValue);
            Assert.Equal(0, tested.CurrentCycle);
            Assert.Equal(0, tested.CurrentRawValue);
            Assert.Equal(0, tested.LastCycleStep);
            Assert.Equal(0, tested.PreviousRawValue);
            Assert.Equal(0, tested.RemainingCyclesEstimate);
            Assert.Equal(100, tested.RemainingPercent);
            Assert.Equal(0, tested.RemainingRawValue);
            Assert.Equal(default(TimeSpan), tested.RemainingTimeEstimate);
            Assert.Equal(default(TimeSpan), tested.Elapsed);
            Assert.Equal(0, tested.TargetCycleEstimate);
            Assert.Equal(0, tested.TargetRawValue);
        }
Beispiel #23
0
        public void RemainingCyclesEstimateIsCorrectEnough()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);

            Assert.Equal(200, tested.RemainingCyclesEstimate);

            tested.ReportProgress(99);

            Assert.Equal(1, tested.RemainingCyclesEstimate, 1);

            tested.ReportProgress(100);

            Assert.Equal(2, tested.RemainingCyclesEstimate, 1);

            tested.ReportProgress(101);

            Assert.Equal(2.9, tested.RemainingCyclesEstimate, 1);

            tested.ReportProgress(200);

            Assert.Equal(0, tested.RemainingCyclesEstimate, 1);
        }
Beispiel #24
0
        public void ThrowsExceptionWhenNotStarted()
        {
            var tested = new TestedProgressReporter();

            Assert.Throws <InvalidOperationException>(() => { tested.ReportProgress(100); });
        }
Beispiel #25
0
        public void ThrowsExceptionWhenTargetValueInvalid()
        {
            var tested = new TestedProgressReporter();

            Assert.Throws <ArgumentOutOfRangeException>(() => { tested.Start(-100); });
        }
Beispiel #26
0
        public void ReportProgressTest()
        {
            var tested = new TestedProgressReporter();

            Assert.Throws <InvalidOperationException>(() => { tested.ReportProgress(); });
        }