diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs index 739885883..cf68689d8 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs @@ -191,11 +191,7 @@ private static string GetValueStringAndType(object value, bool isExpandable, out { // For DictionaryEntry - display the key/value as the value. var entry = (DictionaryEntry)value; - valueString = - string.Format( - "[{0}, {1}]", - entry.Key, - GetValueStringAndType(entry.Value, GetIsExpandable(entry.Value), out typeName)); + valueString = GetValueStringAndType(entry.Value, GetIsExpandable(entry.Value), out typeName); } else { @@ -328,12 +324,11 @@ private VariableDetails[] GetChildren(object obj, ILogger logger) // function that defines parameters and has been passed parameters. // If you open the $PSBoundParameters variable node in this scenario and see nothing, // this code is broken. - int i = 0; foreach (DictionaryEntry entry in dictionary) { childVariables.Add( new VariableDetails( - "[" + i++ + "]", + "[" + entry.Key + "]", entry)); } } diff --git a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs index d8507afba..00996db96 100644 --- a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs @@ -719,19 +719,15 @@ await debugService.SetLineBreakpointsAsync( VariableDetailsBase[] childVars = debugService.GetVariables(var.Id); // 2 variables plus "Raw View" Assert.Equal(3, childVars.Length); - Assert.Equal("[0]", childVars[0].Name); - Assert.Equal("[1]", childVars[1].Name); - var childVarStrs = new HashSet(childVars.Select(v => v.ValueString)); - var expectedVars = new[] { - "[firstChild, \"Child\"]", - "[secondChild, 42]" - }; + // Hashtables are unordered hence the Linq examination, examination by index is unreliable + VariableDetailsBase firstChild = Array.Find(childVars, v => v.Name == "[firstChild]"); + Assert.NotNull(firstChild); + Assert.Equal("\"Child\"", firstChild.ValueString); - foreach (string expectedVar in expectedVars) - { - Assert.Contains(expectedVar, childVarStrs); - } + VariableDetailsBase secondChild = Array.Find(childVars, v => v.Name == "[secondChild]"); + Assert.NotNull(secondChild); + Assert.Equal("42", secondChild.ValueString); } [Fact]