public async void ObserveOneExceptionAsync_NoCondition_ThrowsException() { // ARRANGE Exception exception = null; // ACT Task resultTask = WaitForAllTaskWithExceptionHandling.ObserveOneExceptionAsync(); try { await resultTask; } catch (Exception e) { exception = e; System.Diagnostics.Debug.WriteLine( string.Format("Task completed in Status: '{0}'", resultTask.Status)); } // ASSERT Assert.NotNull(exception, "exception is null."); var IsValidExceptionType = (exception is NotImplementedException) || (exception is InvalidOperationException); Assert.True(IsValidExceptionType, "IsValidExceptionType has unexpected value."); }
public async void ThrowInvalidOperationExceptionAsync_NoCondition_ThrowsException() { // ARRANGE Exception exception = null; // ACT try { await WaitForAllTaskWithExceptionHandling.ThrowInvalidOperationExceptionAsync(); } catch (Exception e) { exception = e; } // ASSERT Assert.NotNull(exception, "exception is null."); Assert.IsInstanceOf <InvalidOperationException>(exception, "exception has unexpected type."); }
public async void ObserveAllExceptionAsync_NoCondition_ThrowsAggregateException() { // ARRANGE Exception exception = null; // ACT Task resultTask = WaitForAllTaskWithExceptionHandling.ObserveAllExceptionAsync(); try { await resultTask; } catch (Exception e) { exception = e; System.Diagnostics.Debug.WriteLine( string.Format("Task completed in Status: '{0}'", resultTask.Status)); } // ASSERT Assert.NotNull(exception, "exception is null."); Assert.IsInstanceOf <AggregateException>(exception, "exception has unexpected type."); var aggregateException = (exception as AggregateException); Assert.AreEqual(2, aggregateException.InnerExceptions.Count, "aggregateException.InnerExceptions.Count has unexpected value."); var notImplementedException = aggregateException.InnerExceptions .FirstOrDefault(innerException => innerException.GetType() == typeof(NotImplementedException)); Assert.IsInstanceOf <NotImplementedException>(notImplementedException, "notImplementedException has unexpected type."); var invalidOperationException = aggregateException.InnerExceptions .FirstOrDefault(innerException => innerException.GetType() == typeof(InvalidOperationException)); Assert.IsInstanceOf <InvalidOperationException>(invalidOperationException, "notImplementedException has unexpected type."); }