コード例 #1
0
ファイル: WorkQueueItem.cs プロジェクト: Mavtak/roomie
        public WorkQueueItemResult DoWork()
        {
            WorkQueueItemResult result;

            try
            {
                _work();

                result = new WorkQueueItemResult(true, _tries);
            }
            catch (Exception exception)
            {
                var exceptionType = exception.GetType();

                _tries--;

                if (_retryExceptions.Any(x => x.IsAssignableFrom(exceptionType)))
                {
                    result = new WorkQueueItemResult(false, _tries, exception);
                }
                else
                {
                    result = new WorkQueueItemResult(false, 0, exception);
                }
            }

            if (!result.ShouldRetry)
            {
                _result = result;
                _event.Set();
            }

            return result;
        }
コード例 #2
0
        public WorkQueueItemResult DoWork()
        {
            WorkQueueItemResult result;

            try
            {
                _work();

                result = new WorkQueueItemResult(true, _tries);
            }
            catch (Exception exception)
            {
                var exceptionType = exception.GetType();

                _tries--;

                if (_retryExceptions.Any(x => x.IsAssignableFrom(exceptionType)))
                {
                    result = new WorkQueueItemResult(false, _tries, exception);
                }
                else
                {
                    result = new WorkQueueItemResult(false, 0, exception);
                }
            }

            if (!result.ShouldRetry)
            {
                _result = result;
                _event.Set();
            }

            return(result);
        }
コード例 #3
0
        public void ItSavesTheException()
        {
            var exception = new Exception();

            var result = new WorkQueueItemResult(false, 0, exception);

            Assert.That(result.Exception, Is.EqualTo(exception));
        }
コード例 #4
0
        public void ShouldRetryReturnsTheCorrectValue(bool success, uint tries, bool expected)
        {
            var result = new WorkQueueItemResult(success, tries);

            Assert.That(result.ShouldRetry, Is.EqualTo(expected));
        }
コード例 #5
0
        public void ItSavesTries(uint tries)
        {
            var result = new WorkQueueItemResult(true, tries);

            Assert.That(result.Tries, Is.EqualTo(tries));
        }
コード例 #6
0
        public void ItSavesSuccess(bool success)
        {
            var result = new WorkQueueItemResult(success, 0);

            Assert.That(result.Success, Is.EqualTo(success));
        }