Example #1
0
        public async Task ExecAttempts_FuncTaskCalls()
        {
            var must = new Must(0, source.Token);

            var res = await must.ExecAttempts(async() =>
            {
                await Task.Delay(1);
                return(Value);
            }, 10);

            Assert.AreEqual(res, Value);
        }
Example #2
0
 public void ExecAttempts_ActionToken()
 {
     Assert.Throws <TaskCanceledException>(() =>
     {
         var must = new Must(0, source.Token);
         var t    = must.ExecAttempts(token =>
         {
             throw new Exception();
         }, int.MaxValue);
         Task.Run(() => source.Cancel());
         try
         {
             t.Wait();
         }
         catch (AggregateException e)
         {
             throw (TaskCanceledException)e.InnerException;
         }
     });
 }
Example #3
0
        public async Task ExecAttempts_Action()
        {
            var watch      = new Stopwatch();
            int sleep      = 60;
            int sleepCount = 5;
            int value      = 1;
            var must       = new Must(sleep);
            await must.ExecAttempts(token =>
            {
                if (!watch.IsRunning)
                {
                    watch.Start();
                }
                if (step++ < sleepCount)
                {
                    throw new Exception();
                }
                watch.Stop();
            }, 100, sleep);

            Assert.IsTrue(watch.ElapsedMilliseconds >= sleep * sleepCount);
        }
Example #4
0
        public async Task ExecAttempts_Func()
        {
            var watch      = new Stopwatch();
            int sleep      = 60;
            int sleepCount = 5;
            var must       = new Must(sleep);
            int res        = await must.ExecAttempts(token =>
            {
                if (!watch.IsRunning)
                {
                    watch.Start();
                }
                if (step++ < sleepCount)
                {
                    throw new Exception();
                }
                watch.Stop();
                return(Value);
            }, 100, sleep);

            Assert.AreEqual(Value, res);
            Assert.IsTrue(watch.ElapsedMilliseconds >= sleep * sleepCount);
        }
Example #5
0
 public Task ExecAttempts_ActionThrowsAttemptsOverException()
 {
     Assert.Throws <AttemptsOverException>(() =>
     {
         int sleep      = 60;
         int sleepCount = 5;
         var must       = new Must(sleep);
         try
         {
             must.ExecAttempts(token =>
             {
                 if (step++ < sleepCount)
                 {
                     throw new Exception();
                 }
             }, sleepCount - 1, sleep).Wait();
         }
         catch (AggregateException e)
         {
             throw (AttemptsOverException)e.InnerException;
         }
     });
     return(Task.CompletedTask);
 }
Example #6
0
 public async Task ExecAttempts_FuncThrowsAttemptsOverException()
 {
     Assert.Throws <AttemptsOverException>(() =>
     {
         int sleep      = 60;
         int sleepCount = 5;
         var must       = new Must(sleep);
         try
         {
             int res = must.ExecAttempts(token =>
             {
                 if (step++ < sleepCount)
                 {
                     throw new Exception();
                 }
                 return(Value);
             }, sleepCount - 1, sleep).Result;
         }
         catch (AggregateException e)
         {
             throw (AttemptsOverException)e.InnerException;
         }
     });
 }
Example #7
0
 public async Task ExecAttempts_ActionTaskCalls()
 {
     var must = new Must(0, source.Token);
     await must.ExecAttempts(async() => await Task.Delay(1), 10);
 }