Exemplo n.º 1
0
        public async void ThrowExceptionAsync_ReturnedTaskAwaited_ThrowsExceptionOnAwaitedTask()
        {
            // ARRANGE
            Exception exception = null;

            //ACT

            // The exception is thrown by the method and placed on the task.
            Task task = ExceptionHandlingFromAsyncTask.ThrowExceptionAsync();

            try
            {
                // The exception is reraised here, where the task is awaited.
                await task;
            }
            catch (Exception ex)
            {
                // The exception is correctly caught here.
                exception = ex;
            }

            // ASSERT
            Assert.NotNull(exception, "exception is null.");
            Assert.IsInstanceOf <InvalidOperationException>(exception, "exception has unexpected type.");
        }
Exemplo n.º 2
0
        public async void ThrowExceptionAsync_NoCondition_ThrowsExceptionOnAwaitedTask()
        {
            // ARRANGE
            Exception exception = null;

            //ACT
            try
            {
                await ExceptionHandlingFromAsyncTask.ThrowExceptionAsync();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // ASSERT
            Assert.NotNull(exception, "exception is null.");
            Assert.IsInstanceOf <InvalidOperationException>(exception, "exception has unexpected type.");
        }