Exemplo n.º 1
0
        public void TimeToCompletionTest()
        {
            var test = new TimeToCompletion();

            Assert.IsNotNull(test);
            test.TargetValue = 20;
            Assert.AreEqual(20, test.TargetValue);
            Assert.AreEqual(string.Empty, test.EstimatedTimeRemainingDisplaySeperator);
            Assert.AreEqual(string.Empty, test.EstimatedTimeRemainingDisplay);

            test.Value = 1;
            Assert.AreEqual(1, test.Value);
            Assert.AreEqual(5, test.Percent);
            Thread.Sleep(100);
            test.Value = 2;
            Assert.AreEqual(2, test.Value);
            Assert.AreEqual(10, test.Percent);
            Thread.Sleep(100);
            test.Value = 3;
            Assert.AreEqual("15%", test.PercentDisplay);
            Thread.Sleep(100);
            test.Value = 4;
            Thread.Sleep(100);
            test.Value = 5;
            Assert.AreEqual(5, test.Value);
            Assert.AreEqual(25, test.Percent);

            Assert.IsTrue(test.EstimatedTimeRemaining.TotalSeconds > 0.0);
            Assert.IsTrue(test.EstimatedTimeRemaining.TotalSeconds < 5.0);
            Assert.AreNotEqual(string.Empty, test.EstimatedTimeRemainingDisplaySeperator);
            Assert.AreNotEqual(string.Empty, test.EstimatedTimeRemainingDisplay);
        }
Exemplo n.º 2
0
        public void TimeToCompletionTest()
        {
            var test = new TimeToCompletion();

            Assert.IsNotNull(test);
            test.TargetValue = 150;
            Assert.AreEqual(150, test.TargetValue);
            Assert.AreEqual(string.Empty, test.EstimatedTimeRemainingDisplaySeparator);
            Assert.AreEqual(string.Empty, test.EstimatedTimeRemainingDisplay);

            test.Value = 1;
            Assert.AreEqual(1, test.Value);
            Thread.Sleep(100);
            test.Value = 2;
            Assert.AreEqual(2, test.Value);
            Thread.Sleep(100);
            test.Value = 3;
            Assert.AreEqual(2, test.Percent);
            Assert.AreEqual(0.02.ToString("0.0%"), test.PercentDisplay);
            Thread.Sleep(100);
            test.Value = 4;
            Thread.Sleep(100);
            test.Value = 5;
            Assert.AreEqual(5, test.Value);
            for (var counter = 6; counter < 60; counter++)
            {
                test.Value = counter;
                Thread.Sleep(200);
            }

            Assert.IsTrue(test.EstimatedTimeRemaining.TotalSeconds > 0.0);
            Assert.IsTrue(test.EstimatedTimeRemaining.TotalSeconds < 20.0);
            Assert.AreNotEqual(string.Empty, test.EstimatedTimeRemainingDisplaySeparator);
            Assert.AreNotEqual(string.Empty, test.EstimatedTimeRemainingDisplay);
        }
Exemplo n.º 3
0
        public void DisplayTimespan()
        {
            Assert.AreEqual("0.10 sec",
                            TimeToCompletion.DisplayTimespan(TimeSpan.FromSeconds(0.1), false).ReplaceDefaults(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, ".", "", ""));

            Assert.AreEqual("20 sec",
                            TimeToCompletion.DisplayTimespan(TimeSpan.FromSeconds(20), false).ReplaceDefaults(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, ".", "", ""));

            Assert.AreEqual("20:30",
                            TimeToCompletion.DisplayTimespan(TimeSpan.FromMinutes(20.5), false).ReplaceDefaults(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, ".", "", ""));

            Assert.AreEqual("", TimeToCompletion.DisplayTimespan(TimeSpan.FromSeconds(0.1), true));
        }