public void CustomAggregateToStringIncludesCallstack() { Guid clientRequestId = Guid.NewGuid(); BatchException e1 = ThrowWithStack <BatchException>(() => { throw new BatchException(new RequestInformation() { BatchError = new BatchError(new Microsoft.Azure.Batch.Protocol.Models.BatchError(code: "Foo")), ClientRequestId = clientRequestId, }, "Test", null); }); ArgumentNullException e2 = ThrowWithStack <ArgumentNullException>(() => { throw new ArgumentNullException(); }); ParallelOperationsException parallelOperationsException = new ParallelOperationsException(new Exception[] { e1, e2 }); string exceptionText = parallelOperationsException.ToString(); Assert.Contains(typeof(ParallelOperationsException).Name, exceptionText); Assert.Contains("Exception #0", exceptionText); Assert.Contains("Exception #1", exceptionText); Assert.Contains("One or more errors occurred", exceptionText); //Ensure each exception logs a stacktrace from the ToString(). The stacktrace should include this test method's name. IEnumerable <string> innerExceptionDumps = GetInnerExceptionText(exceptionText); foreach (string innerExceptionText in innerExceptionDumps) { Assert.Contains("CustomAggregateToStringIncludesCallstack", innerExceptionText); } //Ensure that our BatchException was ToString()'ed correctly Assert.Contains(clientRequestId.ToString(), exceptionText); }
public async Task ExceptionOnSomeRestOperationsAllWrappedInParallelOperationsException() { const int operationCount = 4; const int modFactor = 2; ParallelOperationsException exception = await IssueAddTaskCollectionAndAssertExceptionIsExpectedAsync <ParallelOperationsException>( operationCount, (count, message) => { if (count % modFactor == 0) { return(new ArgumentException(message)); } else { return(null); } }); Assert.Contains("One or more requests to the Azure Batch service failed", exception.ToString()); Assert.Equal(operationCount / modFactor, exception.InnerExceptions.Count); foreach (Exception innerException in exception.InnerExceptions) { Assert.IsType <ArgumentException>(innerException); } }
public async Task ExceptionOnRestOperationIsWrappedInParallelOperationsException(int operationCount) { ParallelOperationsException exception = await IssueAddTaskCollectionAndAssertExceptionIsExpectedAsync <ParallelOperationsException>( operationCount, (count, message) => new ArgumentException(message)); Assert.Contains("One or more requests to the Azure Batch service failed", exception.ToString()); Assert.Equal(operationCount, exception.InnerExceptions.Count); foreach (Exception innerException in exception.InnerExceptions) { Assert.IsType <ArgumentException>(innerException); } }