Пример #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);
        }
Пример #2
0
        public void ProgressCannotRegress()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);

            tested.ReportProgress(100);
            Assert.Throws <ArgumentException>(() => tested.ReportProgress(99));
        }
Пример #3
0
        public void TestedProgressReporterCompletedPercentNeverGoesAbove100()
        {
            var tested = new TestedProgressReporter();

            tested.Start(1);
            tested.ReportProgress();
            try { tested.ReportProgress(); } catch { }
            Assert.Equal(100, tested.CompletedPercent);
        }
Пример #4
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);
        }
Пример #5
0
        public void ProgressReporterCompletedPercentIsCorrect2()
        {
            var tested = new TestedProgressReporter();

            tested.Restart(2);

            Assert.Equal(0, tested.CompletedPercent);
            tested.ReportProgress();
            Assert.Equal(50.0, tested.CompletedPercent);
            tested.ReportProgress();
            Assert.Equal(100.0, tested.CompletedPercent);
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
0
        public void CurrentCycleCannotBeGreaterThanTargetValue()
        {
            var tested = new TestedProgressReporter();

            tested.Start(200);
            Assert.Throws <ArgumentOutOfRangeException>(() => tested.ReportProgress(201));
        }
Пример #9
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);
        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
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);
        }
Пример #16
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);
        }
Пример #17
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);
        }
Пример #18
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);
            }
        }
Пример #19
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);
        }
Пример #20
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);
        }
Пример #21
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);
        }
Пример #22
0
        public void ThrowsExceptionWhenNotStarted()
        {
            var tested = new TestedProgressReporter();

            Assert.Throws <InvalidOperationException>(() => { tested.ReportProgress(100); });
        }
Пример #23
0
        public void ReportProgressTest()
        {
            var tested = new TestedProgressReporter();

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