public void TryInvoke_ThrowsWithTimeout() { Action action = () => Thread.Sleep(500); var timeout = TimeSpan.FromMilliseconds(100); Assert.Throws <TimeoutException>(() => TryWithTimeout.TryInvoke(action, timeout)); }
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)); }
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)); }