示例#1
0
        public async Task AsyncRegionThrowsDoesNotDisposeAsyncRegion()
        {
            await AsyncTestDelegates.Delay(100);

            Assert.ThrowsAsync <ArgumentException>(async() => await AsyncTestDelegates.ThrowsArgumentExceptionAsync());
            Assert.That(async() => await AsyncTestDelegates.ThrowsArgumentExceptionAsync(), Throws.ArgumentException);
        }
示例#2
0
        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"));
        }
示例#3
0
        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);
 }
示例#5
0
        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();
        }
示例#6
0
        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>());
        }
 public static void CatchesSyncException()
 {
     Assert.That(() => AsyncTestDelegates.ThrowsArgumentException(), Throws.Exception);
 }
 public static void CatchesAsyncException()
 {
     Assert.That(async() => await AsyncTestDelegates.ThrowsArgumentExceptionAsync(), Throws.Exception);
 }