public async Task AsyncRegionThrowsDoesNotDisposeAsyncRegion() { await AsyncTestDelegates.Delay(100); Assert.ThrowsAsync <ArgumentException>(async() => await AsyncTestDelegates.ThrowsArgumentExceptionAsync()); Assert.That(async() => await AsyncTestDelegates.ThrowsArgumentExceptionAsync(), Throws.ArgumentException); }
public void CorrectExceptionIsReturnedToMethodAsync() { ArgumentException ex = Assert.ThrowsAsync(typeof(ArgumentException), new AsyncTestDelegate(AsyncTestDelegates.ThrowsArgumentExceptionAsync)) as ArgumentException; Assert.IsNotNull(ex, "No ArgumentException thrown"); Assert.That(ex.Message, Does.StartWith("myMessage")); Assert.That(ex.ParamName, Is.EqualTo("myParam")); ex = Assert.ThrowsAsync <ArgumentException>( delegate { return(AsyncTestDelegates.Delay(5).ContinueWith(t => { throw new ArgumentException("myMessage", "myParam"); }, TaskScheduler.Default)); }); Assert.IsNotNull(ex, "No ArgumentException thrown"); Assert.That(ex.Message, Does.StartWith("myMessage")); Assert.That(ex.ParamName, Is.EqualTo("myParam")); ex = Assert.ThrowsAsync(typeof(ArgumentException), delegate { return(AsyncTestDelegates.Delay(5).ContinueWith(t => { throw new ArgumentException("myMessage", "myParam"); }, TaskScheduler.Default)); }) as ArgumentException; Assert.IsNotNull(ex, "No ArgumentException thrown"); Assert.That(ex.Message, Does.StartWith("myMessage")); Assert.That(ex.ParamName, Is.EqualTo("myParam")); ex = Assert.ThrowsAsync <ArgumentException>(AsyncTestDelegates.ThrowsArgumentExceptionAsync); Assert.IsNotNull(ex, "No ArgumentException thrown"); Assert.That(ex.Message, Does.StartWith("myMessage")); Assert.That(ex.ParamName, Is.EqualTo("myParam")); }
public void GenericThrowsAsyncReturnsCorrectException() { Assert.ThrowsAsync <ArgumentException>( delegate { return(AsyncTestDelegates.Delay(5).ContinueWith(t => { throw new ArgumentException(); }, TaskScheduler.Default)); }); Assert.ThrowsAsync <ArgumentException>(AsyncTestDelegates.ThrowsArgumentExceptionAsync); CheckForSpuriousAssertionResults(); }
public static void CatchesAsyncTaskOfTException() { Assert.That <Task <int> >(async() => { await AsyncTestDelegates.Delay(5); throw new Exception(); }, Throws.Exception); }
public void ThrowsConstraintReturnsCorrectException() { // Without cast, delegate is ambiguous before C# 3.0. Assert.That( (AsyncTestDelegate) delegate { return(AsyncTestDelegates.Delay(5).ContinueWith(t => { throw new ArgumentException(); }, TaskScheduler.Default)); }, Throws.Exception.TypeOf <ArgumentException>()); CheckForSpuriousAssertionResults(); }
public void CorrectExceptionThrownAsync() { Assert.ThrowsAsync(typeof(ArgumentException), AsyncTestDelegates.ThrowsArgumentExceptionAsync); Assert.ThrowsAsync(typeof(ArgumentException), delegate { return(AsyncTestDelegates.Delay(5).ContinueWith(t => { throw new ArgumentException(); }, TaskScheduler.Default)); }); Assert.ThrowsAsync <ArgumentException>( delegate { return(AsyncTestDelegates.Delay(5).ContinueWith(t => { throw new ArgumentException(); }, TaskScheduler.Default)); }); Assert.ThrowsAsync <ArgumentException>(AsyncTestDelegates.ThrowsArgumentExceptionAsync); // Without cast, delegate is ambiguous before C# 3.0. Assert.That( (AsyncTestDelegate) delegate { return(AsyncTestDelegates.Delay(5).ContinueWith(t => { throw new ArgumentException(); }, TaskScheduler.Default)); }, Throws.Exception.TypeOf <ArgumentException>()); }