public void ShouldSummarizeAnyGivenException() { var assertionLibrary = AssertionLibraryFilter(); var exception = GetPrimaryException(); var compoundException = new CompoundException(new[] { exception }, assertionLibrary); compoundException.PrimaryException.DisplayName.ShouldEqual("Fixie.Tests.Execution.CompoundExceptionTests+PrimaryException"); compoundException.PrimaryException.Type.ShouldEqual("Fixie.Tests.Execution.CompoundExceptionTests+PrimaryException"); compoundException.PrimaryException.Message.ShouldEqual("Primary Exception!"); compoundException.PrimaryException.StackTrace.ShouldEqual(exception.StackTrace); compoundException.PrimaryException.InnerException.DisplayName.ShouldEqual("System.DivideByZeroException"); compoundException.PrimaryException.InnerException.Type.ShouldEqual("System.DivideByZeroException"); compoundException.PrimaryException.InnerException.Message.ShouldEqual("Divide by Zero Exception!"); compoundException.PrimaryException.InnerException.StackTrace.ShouldEqual(exception.InnerException.StackTrace); compoundException.PrimaryException.InnerException.InnerException.ShouldBeNull(); compoundException.SecondaryExceptions.Count.ShouldEqual(0); compoundException.CompoundStackTrace .Split(new[] { Environment.NewLine }, StringSplitOptions.None) .Select(x => Regex.Replace(x, @":line \d+", ":line #")) //Avoid brittle assertion introduced by stack trace line numbers. .ShouldEqual( "Primary Exception!", " at Fixie.Tests.Execution.CompoundExceptionTests.GetPrimaryException() in " + PathToThisFile() + ":line #", "", "------- Inner Exception: System.DivideByZeroException -------", "Divide by Zero Exception!", " at Fixie.Tests.Execution.CompoundExceptionTests.GetPrimaryException() in " + PathToThisFile() + ":line #"); }
public static IEnumerable <Tuple <CommandBarControl, CommandBarPopup[]> > EnumDescendantControls( [NotNull] this CommandBar root, [NotNull] CompoundException cex) { if (root == null) { throw new ArgumentNullException(nameof(root)); } if (cex == null) { throw new ArgumentNullException(nameof(cex)); } var queueEnumChildren = new Queue <Tuple <CommandBar, CommandBarPopup[]> >(new[] { Tuple.Create(root, EmptyArray <CommandBarPopup> .Instance) }); int nBar = -1; while (queueEnumChildren.Any()) { Tuple <CommandBar, CommandBarPopup[]> tuple = queueEnumChildren.Dequeue(); nBar++; List <CommandBarControl> children = null; try { // All children children = tuple.Item1.Controls.OfType <CommandBarControl>().ToList(); // EnqueueJob child containers var popups = children.OfType <CommandBarPopup>() .Select(popup => Tuple.Create(popup.CommandBar, tuple.Item2.Concat(popup).ToArray())); foreach (var popup in popups) { queueEnumChildren.Enqueue(popup); } } catch (Exception e) { var ex = new LoggerException("Failed to enum command bar child controls.", e); ex.AddData("IndexInQueue", () => nBar); ex.AddData("CommandBarName", () => tuple.Item1.Name); ex.AddData("CommandBarIndexProperty", () => tuple.Item1.Index); cex.Exceptions.Add(ex); } // Emit if (children != null) // Null if were exceptions (cannot yield from a catch) { foreach (CommandBarControl child in children) { yield return(Tuple.Create(child, tuple.Item2)); } } } }
private void PopulateCachedActionDefs() { var menuBar = Logger.CatchSilent(() => ((CommandBars)dte.CommandBars)["MenuBar"]); if (menuBar != null) { var compoundException = new CompoundException(); var enumDescendantControls = menuBar.EnumDescendantControls(compoundException).ToList(); foreach (var tuple in enumDescendantControls) { // Make sure it's an actionable type (e.g. not a CommandBarPopup, or _CommandBarActiveX) var commandBarControl = tuple.Item1; if (commandBarControl is CommandBarButton || commandBarControl is CommandBarComboBox) { var commandId = VsCommandHelpersTodo.TryGetVsControlCommandID(commandBarControl, dte); if (commandId == null) { continue; } // Breadth first enumeration of descendant controls means the first time a command is encountered // is always the shortest path to a control for that command var actionId = vsCmdNameMapping.TryMapCommandIdToVsCommandName(commandId); if (string.IsNullOrEmpty(actionId) || cachedActionDefs.ContainsKey(actionId)) { continue; } var commandBarPopups = tuple.Item2; var def = new CommandBarActionDef(vsShortcutFinder, dte, actionId, commandId, commandBarControl, commandBarPopups ?? EmptyArray <CommandBarPopup> .Instance); cachedActionDefs.Add(actionId, def); } } if (compoundException.Exceptions.Any()) { Logger.LogException(compoundException); } } }
public void ShouldSummarizeCollectionsOfExceptionsComprisedOfPrimaryAndSecondaryExceptions() { var assertionLibrary = AssertionLibraryFilter(); var primaryException = GetPrimaryException(); var secondaryExceptionA = new NotImplementedException(); var secondaryExceptionB = GetSecondaryException(); var compoundException = new CompoundException(new[] { primaryException, secondaryExceptionA, secondaryExceptionB }, assertionLibrary); compoundException.PrimaryException.DisplayName.ShouldEqual("Fixie.Tests.Execution.CompoundExceptionTests+PrimaryException"); compoundException.PrimaryException.Type.ShouldEqual("Fixie.Tests.Execution.CompoundExceptionTests+PrimaryException"); compoundException.PrimaryException.Message.ShouldEqual("Primary Exception!"); compoundException.PrimaryException.StackTrace.ShouldEqual(primaryException.StackTrace); compoundException.PrimaryException.InnerException.DisplayName.ShouldEqual("System.DivideByZeroException"); compoundException.PrimaryException.InnerException.Type.ShouldEqual("System.DivideByZeroException"); compoundException.PrimaryException.InnerException.Message.ShouldEqual("Divide by Zero Exception!"); compoundException.PrimaryException.InnerException.StackTrace.ShouldEqual(primaryException.InnerException.StackTrace); compoundException.PrimaryException.InnerException.InnerException.ShouldBeNull(); compoundException.SecondaryExceptions.Count.ShouldEqual(2); compoundException.SecondaryExceptions[0].DisplayName.ShouldEqual("System.NotImplementedException"); compoundException.SecondaryExceptions[0].Type.ShouldEqual("System.NotImplementedException"); compoundException.SecondaryExceptions[0].Message.ShouldEqual("The method or operation is not implemented."); compoundException.SecondaryExceptions[0].StackTrace.ShouldBeNull(); compoundException.SecondaryExceptions[0].InnerException.ShouldBeNull(); compoundException.SecondaryExceptions[1].DisplayName.ShouldEqual("Fixie.Tests.Execution.CompoundExceptionTests+SecondaryException"); compoundException.SecondaryExceptions[1].Type.ShouldEqual("Fixie.Tests.Execution.CompoundExceptionTests+SecondaryException"); compoundException.SecondaryExceptions[1].Message.ShouldEqual("Secondary Exception!"); compoundException.SecondaryExceptions[1].StackTrace.ShouldEqual(secondaryExceptionB.StackTrace); compoundException.SecondaryExceptions[1].InnerException.DisplayName.ShouldEqual("System.ApplicationException"); compoundException.SecondaryExceptions[1].InnerException.Type.ShouldEqual("System.ApplicationException"); compoundException.SecondaryExceptions[1].InnerException.Message.ShouldEqual("Application Exception!"); compoundException.SecondaryExceptions[1].InnerException.StackTrace.ShouldEqual(secondaryExceptionB.InnerException.StackTrace); compoundException.SecondaryExceptions[1].InnerException.InnerException.DisplayName.ShouldEqual("System.NotImplementedException"); compoundException.SecondaryExceptions[1].InnerException.InnerException.Type.ShouldEqual("System.NotImplementedException"); compoundException.SecondaryExceptions[1].InnerException.InnerException.Message.ShouldEqual("Not Implemented Exception!"); compoundException.SecondaryExceptions[1].InnerException.InnerException.StackTrace.ShouldEqual(secondaryExceptionB.InnerException.InnerException.StackTrace); compoundException.SecondaryExceptions[1].InnerException.InnerException.InnerException.ShouldBeNull(); compoundException.CompoundStackTrace .Split(new[] { Environment.NewLine }, StringSplitOptions.None) .Select(x => Regex.Replace(x, @":line \d+", ":line #")) //Avoid brittle assertion introduced by stack trace line numbers. .ShouldEqual( "Primary Exception!", " at Fixie.Tests.Execution.CompoundExceptionTests.GetPrimaryException() in " + PathToThisFile() + ":line #", "", "------- Inner Exception: System.DivideByZeroException -------", "Divide by Zero Exception!", " at Fixie.Tests.Execution.CompoundExceptionTests.GetPrimaryException() in " + PathToThisFile() + ":line #", "", "===== Secondary Exception: System.NotImplementedException =====", "The method or operation is not implemented.", "", "", "===== Secondary Exception: Fixie.Tests.Execution.CompoundExceptionTests+SecondaryException =====", "Secondary Exception!", " at Fixie.Tests.Execution.CompoundExceptionTests.GetSecondaryException() in " + PathToThisFile() + ":line #", "", "------- Inner Exception: System.ApplicationException -------", "Application Exception!", " at Fixie.Tests.Execution.CompoundExceptionTests.GetSecondaryException() in " + PathToThisFile() + ":line #", "", "------- Inner Exception: System.NotImplementedException -------", "Not Implemented Exception!", " at Fixie.Tests.Execution.CompoundExceptionTests.GetSecondaryException() in " + PathToThisFile() + ":line #"); }