Ejemplo n.º 1
0
        public void TestTryDoIntermittent()
        {
            int i = 0;

            TryDo.Try(new Action(() =>
            {
                i++;
                if (i < 3)
                {
                    throw new TimeoutException();
                }
            }), 5);
        }
Ejemplo n.º 2
0
        public void TestTryDoInstantThrow()
        {
            int i = 0;

            Assert.ThrowsException <TaskCanceledException>(new Action(() =>
            {
                TryDo.Try(new Action(() =>
                {
                    i++;
                    throw new TaskCanceledException();
                }), 5, TimeSpan.FromMilliseconds(100));
            }));
            Assert.AreEqual(1, i);
        }
Ejemplo n.º 3
0
        public void TestTryDoExceed()
        {
            int i = 0;

            Assert.ThrowsException <TimeoutException>(new Action(() =>
            {
                TryDo.Try(new Action(() =>
                {
                    i++;
                    throw new TimeoutException();
                }), 5, TimeSpan.FromMilliseconds(10));
            }));
            Assert.AreEqual(5, i);
        }
Ejemplo n.º 4
0
        public void TestTryDoWait()
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            int i = 0;

            TryDo.Try(new Action(() =>
            {
                i++;
                if (i < 4)
                {
                    throw new TimeoutException();
                }
            }), 5, TimeSpan.FromMilliseconds(100));
            sw.Stop();
            Assert.IsTrue(sw.ElapsedMilliseconds > 200 && sw.ElapsedMilliseconds < 600);
        }
Ejemplo n.º 5
0
 public void TestTryDoSucceed()
 {
     TryDo.Try(new Action(() => { }), 1);
     TryDo.Try(new Action(() => { }), 3);
     TryDo.Try(new Action(() => { }), 3, TimeSpan.FromSeconds(1));
 }