public void ExceptionPropertySetterHandlesAggregateExceptionsWithMultipleNestedExceptionsCorrectly() { Exception exception1121 = new Exception("1.1.2.1"); Exception exception111 = new Exception("1.1.1"); Exception exception112 = new Exception("1.1.2", exception1121); AggregateException exception11 = new AggregateException("1.1", exception111, exception112); Exception exception121 = new Exception("1.2.1"); Exception exception12 = new Exception("1.2", exception121); AggregateException rootLevelException = new AggregateException("1", exception11, exception12); ExceptionTelemetry telemetry = new ExceptionTelemetry { Exception = rootLevelException }; string[] expectedSequence = new string[] { "1", "1.1", "1.1.1", "1.1.2", "1.1.2.1", "1.2", "1.2.1" }; Assert.AreEqual(expectedSequence.Length, telemetry.Exceptions.Count); Assert.AreEqual(expectedSequence.Length, telemetry.ExceptionDetailsInfoList.Count); for (int counter = 0; counter < expectedSequence.Length; counter++) { ExceptionDetails details = telemetry.Exceptions[counter]; ExceptionDetailsInfo newExceptionDetails = telemetry.ExceptionDetailsInfoList[counter]; Assert.IsTrue(ReferenceEquals(details, newExceptionDetails.InternalExceptionDetails)); if (details.typeName == "System.AggregateException") { AssertEx.StartsWith(expectedSequence[counter], details.message); } else { Assert.AreEqual(expectedSequence[counter], details.message); } } }
public void ExceptionTelemetryCreatedBasedOnCustomData() { // ARRANGE var topLevelexceptionDetails = new ExceptionDetailsInfo(1, -1, "TopLevelException", "Top level exception", true, "Top level exception stack", new[] { new StackFrame("Some.Assembly", "SomeFile.dll", 3, 33, "TopLevelMethod"), new StackFrame("Some.Assembly", "SomeOtherFile.dll", 2, 22, "LowerLevelMethod"), new StackFrame("Some.Assembly", "YetAnotherFile.dll", 1, 11, "LowLevelMethod") }); var innerExceptionDetails = new ExceptionDetailsInfo(2, 1, "InnerException", "Inner exception", false, "Inner exception stack", new[] { new StackFrame("Some.Assembly", "ImportantFile.dll", 2, 22, "InnerMethod"), new StackFrame("Some.Assembly", "LessImportantFile.dll", 1, 11, "DeeperInnerMethod") }); // ACT ExceptionTelemetry item = new ExceptionTelemetry(new[] { topLevelexceptionDetails, innerExceptionDetails }, SeverityLevel.Error, "ProblemId", new Dictionary <string, string>() { ["property1"] = "value1", ["property2"] = "value2" }, new Dictionary <string, double>() { ["property1"] = 1, ["property2"] = 2 }); item.ExceptionDetailsInfoList[1].Message = "Inner exception modified"; item.ProblemId = "ProblemId modified"; // ASSERT // use internal fields to validate Assert.AreEqual("Top level exception <--- Inner exception modified", item.Message); Assert.AreEqual(item.Data.Data.ver, 2); Assert.AreEqual(item.Data.Data.problemId, "ProblemId modified"); Assert.AreEqual(item.Data.Data.severityLevel, Extensibility.Implementation.External.SeverityLevel.Error); Assert.AreEqual(item.Data.Data.properties.Count, 2); Assert.IsTrue(item.Data.Data.properties.Keys.Contains("property1")); Assert.IsTrue(item.Data.Data.properties.Keys.Contains("property2")); Assert.IsTrue(item.Data.Data.properties.Values.Contains("value1")); Assert.IsTrue(item.Data.Data.properties.Values.Contains("value2")); Assert.AreEqual(item.Data.Data.measurements.Count, 2); Assert.IsTrue(item.Data.Data.measurements.Keys.Contains("property1")); Assert.IsTrue(item.Data.Data.measurements.Keys.Contains("property2")); Assert.IsTrue(item.Data.Data.measurements.Values.Contains(1)); Assert.IsTrue(item.Data.Data.measurements.Values.Contains(2)); Assert.AreEqual(item.Data.Data.exceptions.Count, 2); Assert.AreEqual(item.Data.Data.exceptions.First().id, 1); Assert.AreEqual(item.Data.Data.exceptions.First().outerId, -1); Assert.AreEqual(item.Data.Data.exceptions.First().typeName, "TopLevelException"); Assert.AreEqual(item.Data.Data.exceptions.First().message, "Top level exception"); Assert.AreEqual(item.Data.Data.exceptions.First().hasFullStack, true); Assert.AreEqual(item.Data.Data.exceptions.First().stack, "Top level exception stack"); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack.Count, 3); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[0].assembly, "Some.Assembly"); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[0].fileName, "SomeFile.dll"); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[0].level, 3); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[0].line, 33); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[0].method, "TopLevelMethod"); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[1].assembly, "Some.Assembly"); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[1].fileName, "SomeOtherFile.dll"); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[1].level, 2); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[1].line, 22); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[1].method, "LowerLevelMethod"); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[2].assembly, "Some.Assembly"); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[2].fileName, "YetAnotherFile.dll"); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[2].level, 1); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[2].line, 11); Assert.AreEqual(item.Data.Data.exceptions.First().parsedStack[2].method, "LowLevelMethod"); Assert.AreEqual(item.Data.Data.exceptions.Last().id, 2); Assert.AreEqual(item.Data.Data.exceptions.Last().outerId, 1); Assert.AreEqual(item.Data.Data.exceptions.Last().typeName, "InnerException"); Assert.AreEqual(item.Data.Data.exceptions.Last().message, "Inner exception modified"); Assert.AreEqual(item.Data.Data.exceptions.Last().hasFullStack, false); Assert.AreEqual(item.Data.Data.exceptions.Last().stack, "Inner exception stack"); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack.Count, 2); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack[0].assembly, "Some.Assembly"); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack[0].fileName, "ImportantFile.dll"); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack[0].level, 2); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack[0].line, 22); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack[0].method, "InnerMethod"); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack[1].assembly, "Some.Assembly"); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack[1].fileName, "LessImportantFile.dll"); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack[1].level, 1); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack[1].line, 11); Assert.AreEqual(item.Data.Data.exceptions.Last().parsedStack[1].method, "DeeperInnerMethod"); }
public void ExceptionTelemetryCreatedBasedOnCustomDataConstructsFakeExceptionCorrectly() { // ARRANGE var topLevelexceptionDetails = new ExceptionDetailsInfo(1, -1, "TopLevelException", "Top level exception", true, "Top level exception stack", new[] { new StackFrame("Some.Assembly", "SomeFile.dll", 3, 33, "TopLevelMethod"), new StackFrame("Some.Assembly", "SomeOtherFile.dll", 2, 22, "LowerLevelMethod"), new StackFrame("Some.Assembly", "YetAnotherFile.dll", 1, 11, "LowLevelMethod") }); var innerExceptionDetails = new ExceptionDetailsInfo(2, 1, "InnerException", "Inner exception", false, "Inner exception stack", new[] { new StackFrame("Some.Assembly", "ImportantFile.dll", 2, 22, "InnerMethod"), new StackFrame("Some.Assembly", "LessImportantFile.dll", 1, 11, "DeeperInnerMethod") }); var innerInnerExceptionDetails = new ExceptionDetailsInfo(3, 1, "InnerInnerException", "Inner inner exception", false, "Inner inner exception stack", new[] { new StackFrame("Some.Assembly", "ImportantInnerFile.dll", 2, 22, "InnerInnerMethod"), new StackFrame("Some.Assembly", "LessImportantInnerFile.dll", 1, 11, "DeeperInnerInnerMethod") }); ExceptionTelemetry item1 = new ExceptionTelemetry(new[] { topLevelexceptionDetails, innerExceptionDetails, innerInnerExceptionDetails }, SeverityLevel.Error, "ProblemId", new Dictionary <string, string>() { ["property1"] = "value1", ["property2"] = "value2" }, new Dictionary <string, double>() { ["property1"] = 1, ["property2"] = 2 }); ExceptionTelemetry item2 = new ExceptionTelemetry(new[] { topLevelexceptionDetails, innerExceptionDetails }, SeverityLevel.Error, "ProblemId", new Dictionary <string, string>() { ["property1"] = "value1", ["property2"] = "value2" }, new Dictionary <string, double>() { ["property1"] = 1, ["property2"] = 2 }); ExceptionTelemetry item3 = new ExceptionTelemetry(new[] { topLevelexceptionDetails }, SeverityLevel.Error, "ProblemId", new Dictionary <string, string>() { ["property1"] = "value1", ["property2"] = "value2" }, new Dictionary <string, double>() { ["property1"] = 1, ["property2"] = 2 }); ExceptionTelemetry item4 = new ExceptionTelemetry(new ExceptionDetailsInfo[] { }, SeverityLevel.Error, "ProblemId", new Dictionary <string, string>() { ["property1"] = "value1", ["property2"] = "value2" }, new Dictionary <string, double>() { ["property1"] = 1, ["property2"] = 2 }); // ACT Exception exception1 = item1.Exception; Exception exception2 = item2.Exception; Exception exception3 = item3.Exception; Exception exception4 = item4.Exception; // ASSERT Assert.AreEqual("Top level exception", exception1.Message); Assert.AreEqual("Inner exception", exception1.InnerException.Message); Assert.AreEqual("Inner inner exception", exception1.InnerException.InnerException.Message); Assert.IsNull(exception1.InnerException.InnerException.InnerException); Assert.AreEqual("Top level exception", exception2.Message); Assert.AreEqual("Inner exception", exception2.InnerException.Message); Assert.IsNull(exception2.InnerException.InnerException); Assert.AreEqual("Top level exception", exception3.Message); Assert.IsNull(exception3.InnerException); Assert.AreEqual(string.Empty, exception4.Message); Assert.IsNull(exception4.InnerException); }