示例#1
0
        public void TryInvoke_ThrowsWithTimeout()
        {
            Action action  = () => Thread.Sleep(500);
            var    timeout = TimeSpan.FromMilliseconds(100);

            Assert.Throws <TimeoutException>(() => TryWithTimeout.TryInvoke(action, timeout));
        }
示例#2
0
        public void TryInvoke_ExceptionContainableOnTimeout()
        {
            Action    action          = () => Thread.Sleep(500);
            var       timeout         = TimeSpan.FromMilliseconds(100);
            Exception exceptionCaught = null;

            try
            {
                TryWithTimeout.TryInvoke(action, timeout);
            }
            catch (Exception e)
            {
                exceptionCaught = e;
            }
            Assert.NotNull(exceptionCaught);
            Assert.That(exceptionCaught.GetType() == typeof(TimeoutException));
        }
示例#3
0
        public void TryInvoke_ExceptionBeforeTimeout()
        {
            Action action = () => { throw new NotImplementedException(); };

            var       timeout         = TimeSpan.FromMilliseconds(1000);
            Exception exceptionCaught = null;

            try
            {
                TryWithTimeout.TryInvoke(action, timeout);
            }
            catch (Exception e)
            {
                exceptionCaught = e;
            }
            Assert.NotNull(exceptionCaught);
            Assert.That(exceptionCaught.GetType() == typeof(NotImplementedException));
        }