Skip to content

Commit

Permalink
Fix XUnit warnings that better assertion operators should be used. (#858
Browse files Browse the repository at this point in the history
)

* fix XUnit warnings that better assertion operators should be used. This also cleans up the build log
  • Loading branch information
bergmeister authored and rjmholt committed Jan 30, 2019
1 parent 2c5f8cf commit f853185
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 48 deletions.
24 changes: 12 additions & 12 deletions test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ await this.WaitForEvent(
PublishDiagnosticsNotification.Type);

// Was there a syntax error?
Assert.NotEqual(0, diagnostics.Diagnostics.Length);
Assert.NotEmpty(diagnostics.Diagnostics);
Assert.False(
string.IsNullOrEmpty(diagnostics.Diagnostics[0].Message));
}
Expand All @@ -99,7 +99,7 @@ await this.WaitForEvent(
PublishDiagnosticsNotification.Type);

// Was there a semantic error?
Assert.NotEqual(0, diagnostics.Diagnostics.Length);
Assert.NotEmpty(diagnostics.Diagnostics);
Assert.Contains("unapproved", diagnostics.Diagnostics[0].Message);
}

Expand All @@ -115,7 +115,7 @@ await this.WaitForEvent(
PublishDiagnosticsNotification.Type);

// Was there a syntax error?
Assert.Equal(0, diagnostics.Diagnostics.Length);
Assert.Empty(diagnostics.Diagnostics);
}

[Fact]
Expand All @@ -140,7 +140,7 @@ await this.SendRequest(
});

Assert.NotNull(completions);
Assert.NotEqual(completions.Length, 0);
Assert.NotEmpty(completions);

// TODO: Add more asserts
}
Expand Down Expand Up @@ -279,7 +279,7 @@ await this.SendRequest(
});

Assert.NotNull(locations);
Assert.Equal(locations.Length, 3);
Assert.Equal(3, locations.Length);

Assert.Equal(5, locations[0].Range.Start.Line);
Assert.Equal(0, locations[0].Range.Start.Character);
Expand Down Expand Up @@ -311,7 +311,7 @@ await this.SendRequest(
});

Assert.NotNull(locations);
Assert.Equal(0, locations.Length);
Assert.Empty(locations);
}

[Fact]
Expand Down Expand Up @@ -400,7 +400,7 @@ await this.SendRequest(
});

Assert.NotNull(locations);
Assert.Equal(1, locations.Length);
Assert.Single(locations);
Assert.Equal(0, locations[0].Range.Start.Line);
Assert.Equal(9, locations[0].Range.Start.Character);
}
Expand All @@ -427,7 +427,7 @@ await this.SendRequest(
});

Assert.NotNull(locations);
Assert.Equal(0, locations.Length);
Assert.Empty(locations);
}

[Fact]
Expand All @@ -452,7 +452,7 @@ await this.SendRequest(
});

Assert.NotNull(locations);
Assert.Equal(1, locations.Length);
Assert.Single(locations);
Assert.Equal(5, locations[0].Range.Start.Line);
Assert.Equal(0, locations[0].Range.Start.Character);
Assert.Equal(5, locations[0].Range.End.Line);
Expand Down Expand Up @@ -481,7 +481,7 @@ await this.SendRequest(
});

Assert.NotNull(locations);
Assert.Equal(1, locations.Length);
Assert.Single(locations);
Assert.EndsWith("VariableDefinition.ps1", locations[0].Uri);
Assert.Equal(0, locations[0].Range.Start.Line);
Assert.Equal(0, locations[0].Range.Start.Character);
Expand Down Expand Up @@ -511,7 +511,7 @@ await this.SendRequest(
});

Assert.NotNull(locations);
Assert.Equal(1, locations.Length);
Assert.Single(locations);
Assert.EndsWith("FindReferences.ps1", locations[0].Uri);
Assert.Equal(17, locations[0].Range.Start.Line);
Assert.Equal(0, locations[0].Range.Start.Character);
Expand Down Expand Up @@ -567,7 +567,7 @@ await this.SendRequest(
});

Assert.NotNull(signatureHelp);
Assert.Equal(1, signatureHelp.Signatures.Length);
Assert.Single(signatureHelp.Signatures);
Assert.Equal(2, signatureHelp.Signatures[0].Parameters.Length);
Assert.Equal(
"Write-Output [-InputObject] <psobject[]> [-NoEnumerate] [<CommonParameters>]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task OutputDebouncerAggregatesOutputEvents()
await SendOutput(debouncer, "for great justice");

// Assert that there's only one event with the expected string
Assert.Equal(1, messageSender.OutputEvents.Count);
Assert.Single(messageSender.OutputEvents);
Assert.Equal(
TestUtilities.NormalizeNewlines("This is a test\nAnother line"),
messageSender.OutputEvents[0].Output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ await this.debugService.SetCommandBreakpointsAsync(
await this.debugService.SetCommandBreakpointsAsync(
new[] { CommandBreakpointDetails.Create("Get-Host") });

Assert.Equal(1, breakpoints.Length);
Assert.Single(breakpoints);
Assert.Equal("Get-Host", breakpoints[0].Name);

breakpoints =
await this.debugService.SetCommandBreakpointsAsync(
new CommandBreakpointDetails[] {});

Assert.Equal(0, breakpoints.Length);
Assert.Empty(breakpoints);
}

[Fact]
Expand Down Expand Up @@ -258,7 +258,7 @@ await this.debugService.SetLineBreakpointsAsync(

confirmedBreakpoints = await this.GetConfirmedBreakpoints(this.debugScriptFile);

Assert.Equal(1, confirmedBreakpoints.Count());
Assert.Single(confirmedBreakpoints);
Assert.Equal(2, breakpoints[0].LineNumber);

await this.debugService.SetLineBreakpointsAsync(
Expand Down Expand Up @@ -843,8 +843,8 @@ await this.debugService.SetLineBreakpointsAsync(
Assert.Equal(2, childVars.Count);
Assert.Contains("Age", childVars.Keys);
Assert.Contains("Name", childVars.Keys);
Assert.Equal(childVars["Age"], "75");
Assert.Equal(childVars["Name"], "\"John\"");
Assert.Equal("75", childVars["Age"]);
Assert.Equal("\"John\"", childVars["Name"]);

// Abort execution of the script
this.powerShellContext.AbortExecution();
Expand Down Expand Up @@ -931,7 +931,7 @@ public async Task AssertDebuggerPaused()
DebuggerStoppedEventArgs eventArgs =
await this.debuggerStoppedQueue.DequeueAsync(new CancellationTokenSource(5000).Token);

Assert.Equal(0, eventArgs.OriginalEvent.Breakpoints.Count);
Assert.Empty(eventArgs.OriginalEvent.Breakpoints);
}

public async Task AssertDebuggerStopped(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ await extensionService.PowerShellContext.ExecuteScriptStringAsync(
await this.AssertExtensionEvent(EventType.Remove, "test.scriptblock");

// Ensure that the command has been unregistered
await Assert.ThrowsAsync(
typeof(KeyNotFoundException),
() => extensionService.InvokeCommandAsync("test.scriptblock", this.commandContext));
await Assert.ThrowsAsync<KeyNotFoundException>(() =>
extensionService.InvokeCommandAsync("test.scriptblock", this.commandContext));
}

private async Task<EditorCommand> AssertExtensionEvent(EventType expectedEventType, string expectedExtensionName)
Expand Down
20 changes: 10 additions & 10 deletions test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task LanguageServiceCompletesCommandInFile()
await this.GetCompletionResults(
CompleteCommandInFile.SourceDetails);

Assert.NotEqual(0, completionResults.Completions.Length);
Assert.NotEmpty(completionResults.Completions);
Assert.Equal(
CompleteCommandInFile.ExpectedCompletion,
completionResults.Completions[0]);
Expand All @@ -62,7 +62,7 @@ public async Task LanguageServiceCompletesCommandFromModule()
await this.GetCompletionResults(
CompleteCommandFromModule.SourceDetails);

Assert.NotEqual(0, completionResults.Completions.Length);
Assert.NotEmpty(completionResults.Completions);
Assert.Equal(
CompleteCommandFromModule.ExpectedCompletion,
completionResults.Completions[0]);
Expand All @@ -75,7 +75,7 @@ public async Task LanguageServiceCompletesVariableInFile()
await this.GetCompletionResults(
CompleteVariableInFile.SourceDetails);

Assert.Equal(1, completionResults.Completions.Length);
Assert.Single(completionResults.Completions);
Assert.Equal(
CompleteVariableInFile.ExpectedCompletion,
completionResults.Completions[0]);
Expand All @@ -88,7 +88,7 @@ public async Task LanguageServiceCompletesAttributeValue()
await this.GetCompletionResults(
CompleteAttributeValue.SourceDetails);

Assert.NotEqual(0, completionResults.Completions.Length);
Assert.NotEmpty(completionResults.Completions);
Assert.Equal(
CompleteAttributeValue.ExpectedRange,
completionResults.ReplacedRange);
Expand All @@ -101,7 +101,7 @@ public async Task LanguageServiceCompletesFilePath()
await this.GetCompletionResults(
CompleteFilePath.SourceDetails);

Assert.NotEqual(0, completionResults.Completions.Length);
Assert.NotEmpty(completionResults.Completions);
// TODO: Since this is a path completion, this test will need to be
// platform specific. Probably something like:
// - Windows: C:\Program
Expand Down Expand Up @@ -133,7 +133,7 @@ await this.GetParamSetSignatures(

Assert.NotNull(paramSignatures);
Assert.Equal("Write-Host", paramSignatures.CommandName);
Assert.Equal(1, paramSignatures.Signatures.Count());
Assert.Single(paramSignatures.Signatures);
}

[Fact]
Expand Down Expand Up @@ -299,9 +299,9 @@ public void LanguageServiceFindsSymbolsInFile()
this.FindSymbolsInFile(
FindSymbolsInMultiSymbolFile.SourceDetails);

Assert.Equal(4, symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Function).Count());
Assert.Equal(3, symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Variable).Count());
Assert.Equal(1, symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Workflow).Count());
Assert.Equal(4, symbolsResult.FoundOccurrences.Where(symbolReference => symbolReference.SymbolType == SymbolType.Function).Count());
Assert.Equal(3, symbolsResult.FoundOccurrences.Where(symbolReference => symbolReference.SymbolType == SymbolType.Variable).Count());
Assert.Single(symbolsResult.FoundOccurrences.Where(symbolReference => symbolReference.SymbolType == SymbolType.Workflow));

SymbolReference firstFunctionSymbol = symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Function).First();
Assert.Equal("AFunction", firstFunctionSymbol.SymbolName);
Expand Down Expand Up @@ -347,7 +347,7 @@ public void LanguageServiceFindsSymbolsInNoSymbolsFile()
this.FindSymbolsInFile(
FindSymbolsInNoSymbolsFile.SourceDetails);

Assert.Equal(0, symbolsResult.FoundOccurrences.Count());
Assert.Empty(symbolsResult.FoundOccurrences);
}

private ScriptFile GetScriptFile(ScriptRegion scriptRegion)
Expand Down
25 changes: 10 additions & 15 deletions test/PowerShellEditorServices.Test/Session/ScriptFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ public void FindsDotSourcedFiles()
[Fact]
public void ThrowsExceptionWithEditOutsideOfRange()
{
Assert.Throws(
typeof(ArgumentOutOfRangeException),
Assert.Throws<ArgumentOutOfRangeException>(
() =>
{
this.AssertFileChange(
Expand Down Expand Up @@ -293,7 +292,7 @@ public void CanGetWholeLine()
_scriptFile_noTrailingNewline.GetLinesInRange(
new BufferRange(5, 1, 5, 10));

Assert.Equal(1, lines.Length);
Assert.Single(lines);
Assert.Equal("Line Five", lines[0]);
}

Expand All @@ -314,7 +313,7 @@ public void CanGetSubstringInSingleLine()
_scriptFile_noTrailingNewline.GetLinesInRange(
new BufferRange(4, 3, 4, 8));

Assert.Equal(1, lines.Length);
Assert.Single(lines);
Assert.Equal("ne Fo", lines[0]);
}

Expand All @@ -325,7 +324,7 @@ public void CanGetEmptySubstringRange()
_scriptFile_noTrailingNewline.GetLinesInRange(
new BufferRange(4, 3, 4, 3));

Assert.Equal(1, lines.Length);
Assert.Single(lines);
Assert.Equal("", lines[0]);
}

Expand Down Expand Up @@ -386,15 +385,15 @@ public void CanGetSameLinesWithUnixLineBreaks()
public void CanGetLineForEmptyString()
{
var emptyFile = ScriptFileChangeTests.CreateScriptFile(string.Empty);
Assert.Equal(1, emptyFile.FileLines.Count);
Assert.Single(emptyFile.FileLines);
Assert.Equal(string.Empty, emptyFile.FileLines[0]);
}

[Fact]
public void CanGetLineForSpace()
{
var spaceFile = ScriptFileChangeTests.CreateScriptFile(" ");
Assert.Equal(1, spaceFile.FileLines.Count);
Assert.Single(spaceFile.FileLines);
Assert.Equal(" ", spaceFile.FileLines[0]);
}
}
Expand Down Expand Up @@ -445,8 +444,7 @@ public void CanOffsetByColumn()
public void ThrowsWhenPositionOutOfRange()
{
// Less than line range
Assert.Throws(
typeof(ArgumentOutOfRangeException),
Assert.Throws<ArgumentOutOfRangeException>(
() =>
{
scriptFile.CalculatePosition(
Expand All @@ -455,8 +453,7 @@ public void ThrowsWhenPositionOutOfRange()
});

// Greater than line range
Assert.Throws(
typeof(ArgumentOutOfRangeException),
Assert.Throws<ArgumentOutOfRangeException>(
() =>
{
scriptFile.CalculatePosition(
Expand All @@ -465,8 +462,7 @@ public void ThrowsWhenPositionOutOfRange()
});

// Less than column range
Assert.Throws(
typeof(ArgumentOutOfRangeException),
Assert.Throws<ArgumentOutOfRangeException>(
() =>
{
scriptFile.CalculatePosition(
Expand All @@ -475,8 +471,7 @@ public void ThrowsWhenPositionOutOfRange()
});

// Greater than column range
Assert.Throws(
typeof(ArgumentOutOfRangeException),
Assert.Throws<ArgumentOutOfRangeException>(
() =>
{
scriptFile.CalculatePosition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ await Task.WhenAll(

// At this point, numbers 0 through 299 should be in the outputItems
IEnumerable<int> expectedItems = Enumerable.Range(0, 300);
Assert.Equal(0, expectedItems.Except(outputItems).Count());
Assert.Empty(expectedItems.Except(outputItems));
}

[Fact]
Expand Down

0 comments on commit f853185

Please sign in to comment.