本文整理匯總了C#中TestHelper.DiagnosticResult.Count方法的典型用法代碼示例。如果您正苦於以下問題:C# DiagnosticResult.Count方法的具體用法?C# DiagnosticResult.Count怎麽用?C# DiagnosticResult.Count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類TestHelper.DiagnosticResult
的用法示例。
在下文中一共展示了DiagnosticResult.Count方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: VerifyDiagnosticResults
/// <summary>
/// Checks each of the actual <see cref="Diagnostic"/>s found and compares them with the corresponding
/// <see cref="DiagnosticResult"/> in the array of expected results. <see cref="Diagnostic"/>s are considered
/// equal only if the <see cref="DiagnosticResult.Locations"/>, <see cref="DiagnosticResult.Id"/>,
/// <see cref="DiagnosticResult.Severity"/>, and <see cref="DiagnosticResult.Message"/> of the
/// <see cref="DiagnosticResult"/> match the actual <see cref="Diagnostic"/>.
/// </summary>
/// <param name="actualResults">The <see cref="Diagnostic"/>s found by the compiler after running the analyzer
/// on the source code.</param>
/// <param name="analyzers">The analyzers that have been run on the sources.</param>
/// <param name="expectedResults">A collection of <see cref="DiagnosticResult"/>s describing the expected
/// diagnostics for the sources.</param>
private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResults, ImmutableArray<DiagnosticAnalyzer> analyzers, DiagnosticResult[] expectedResults)
{
int expectedCount = expectedResults.Count();
int actualCount = actualResults.Count();
if (expectedCount != actualCount)
{
string diagnosticsOutput = actualResults.Any() ? FormatDiagnostics(analyzers, actualResults.ToArray()) : " NONE.";
Assert.True(
false,
string.Format("Mismatch between number of diagnostics returned, expected \"{0}\" actual \"{1}\"\r\n\r\nDiagnostics:\r\n{2}\r\n", expectedCount, actualCount, diagnosticsOutput));
}
for (int i = 0; i < expectedResults.Length; i++)
{
var actual = actualResults.ElementAt(i);
var expected = expectedResults[i];
if (expected.Line == -1 && expected.Column == -1)
{
if (actual.Location != Location.None)
{
string message =
string.Format(
"Expected:\nA project diagnostic with No location\nActual:\n{0}",
FormatDiagnostics(analyzers, actual));
Assert.True(false, message);
}
}
else
{
VerifyDiagnosticLocation(analyzers, actual, actual.Location, expected.Locations.First());
var additionalLocations = actual.AdditionalLocations.ToArray();
if (additionalLocations.Length != expected.Locations.Length - 1)
{
string message =
string.Format(
"Expected {0} additional locations but got {1} for Diagnostic:\r\n {2}\r\n",
expected.Locations.Length - 1,
additionalLocations.Length,
FormatDiagnostics(analyzers, actual));
Assert.True(false, message);
}
for (int j = 0; j < additionalLocations.Length; ++j)
{
VerifyDiagnosticLocation(analyzers, actual, additionalLocations[j], expected.Locations[j + 1]);
}
}
if (actual.Id != expected.Id)
{
string message =
string.Format(
"Expected diagnostic id to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
expected.Id,
actual.Id,
FormatDiagnostics(analyzers, actual));
Assert.True(false, message);
}
if (actual.Severity != expected.Severity)
{
string message =
string.Format(
"Expected diagnostic severity to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
expected.Severity,
actual.Severity,
FormatDiagnostics(analyzers, actual));
Assert.True(false, message);
}
if (actual.GetMessage() != expected.Message)
{
string message =
string.Format(
"Expected diagnostic message to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
expected.Message,
actual.GetMessage(),
FormatDiagnostics(analyzers, actual));
Assert.True(false, message);
}
}
}