public void TransferProgressIsIdleIsCorrect()
        {
            var tested = new TransferProgress();

            tested.Start(1);
            Assert.False(tested.IsIdle);
            tested.ReportProgress();
            Assert.True(tested.IsIdle);
            try { tested.ReportProgress(); } catch { }
            Assert.True(tested.IsIdle);
        }
        public void TransferProgressCompletedPercentIsCorrect2()
        {
            var tested = new TransferProgress();

            tested.Restart(2);

            Assert.Equal(0, tested.CompletedPercent);
            tested.ReportProgress();
            Assert.Equal(50.0, tested.CompletedPercent);
            tested.ReportProgress();
            Assert.Equal(100.0, tested.CompletedPercent);
        }
        public void ReportingProgressWithArguementProperlyUpdatesRemainingPercent()
        {
            var tested = new TransferProgress();

            tested.Start(200);

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

            tested.ReportProgress(100);

            Assert.Equal(50.0, tested.RemainingPercent, 1);

            tested.ReportProgress(200);

            Assert.Equal(0, tested.RemainingPercent, 1);
        }
        public void Integration()
        {
            const int bytesToTransfer = 10000;
            var       tested          = new TransferProgress();

            tested.Start(bytesToTransfer);

            tested.ReportProgress(9999);
            tested.Pause();
            Assert.True(tested.BitrateBps > 0);
            Assert.False(tested.IsRunning);
            Assert.True(tested.Elapsed.TotalMilliseconds < 1000);
            Assert.True(tested.RemainingTimeEstimate.TotalMilliseconds < 1000);

            tested.UnPause();
            Thread.Sleep(1000);

            tested.ReportProgress(10000);
            Assert.False(tested.IsRunning);
            Assert.True(tested.Elapsed.TotalMilliseconds >= 1000);
            Assert.True(tested.RemainingTimeEstimate.TotalMilliseconds < 10);
            Assert.True(tested.BitrateBps < bytesToTransfer / 4 && tested.BitrateBps > 0);
        }
        public void ReportingProgressProperlyUpdatesCompletedPercent(int iterations)
        {
            var tested = new TransferProgress();

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

            for (int i = 0; i < iterations; ++i)
            {
                tested.ReportProgress();
                var expectedCompletedPercent = step * (i + 1);
                Assert.Equal(expectedCompletedPercent, tested.CompletedPercent, 1);
            }
        }