public static void Verify(
            this IEnumerable <Diagnostic> actualResults,
            DiagnosticAnalyzer analyzer,
            bool printActualDiagnosticsOnFailure,
            string expectedDiagnosticsAssertionTemplate,
            params DiagnosticResult[] expectedResults)
        {
            if (analyzer != null && analyzer.SupportedDiagnostics.Length == 0)
            {
                // Not implemented analyzer
                return;
            }

            int expectedCount = expectedResults.Count();
            int actualCount   = actualResults.Count();

            if (expectedCount != actualCount)
            {
                string diagnosticsOutput = actualResults.Any() ? FormatDiagnostics(analyzer, actualResults) : "    NONE.";

                AssertFalse(
                    string.Format("Mismatch between number of diagnostics returned, expected \"{0}\" actual \"{1}\"\r\n\r\nDiagnostics:\r\n{2}\r\n", expectedCount, actualCount, diagnosticsOutput),
                    printActualDiagnosticsOnFailure,
                    expectedDiagnosticsAssertionTemplate,
                    actualResults);
            }

            for (int i = 0; i < expectedResults.Length; i++)
            {
                Diagnostic       actual   = actualResults.ElementAt(i);
                DiagnosticResult expected = expectedResults[i];

                if (expected.Line == -1 && expected.Column == -1)
                {
                    if (actual.Location != Location.None)
                    {
                        AssertFalse(
                            string.Format("Expected:\nA project diagnostic with No location\nActual:\n{0}",
                                          FormatDiagnostics(analyzer, actual)),
                            printActualDiagnosticsOnFailure,
                            expectedDiagnosticsAssertionTemplate,
                            actualResults);
                    }
                }
                else
                {
                    VerifyDiagnosticLocation(analyzer, actual, actual.Location, expected.Locations.First());
                    Location[] additionalLocations = actual.AdditionalLocations.ToArray();

                    if (additionalLocations.Length != expected.Locations.Length - 1)
                    {
                        AssertFalse(
                            string.Format("Expected {0} additional locations but got {1} for Diagnostic:\r\n    {2}\r\n",
                                          expected.Locations.Length - 1, additionalLocations.Length,
                                          FormatDiagnostics(analyzer, actual)),
                            printActualDiagnosticsOnFailure,
                            expectedDiagnosticsAssertionTemplate,
                            actualResults);
                    }

                    for (int j = 0; j < additionalLocations.Length; ++j)
                    {
                        VerifyDiagnosticLocation(analyzer, actual, additionalLocations[j], expected.Locations[j + 1]);
                    }
                }

                if (actual.Id != expected.Id)
                {
                    AssertFalse(
                        string.Format("Expected diagnostic id to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n    {2}\r\n",
                                      expected.Id, actual.Id, FormatDiagnostics(analyzer, actual)),
                        printActualDiagnosticsOnFailure,
                        expectedDiagnosticsAssertionTemplate,
                        actualResults);
                }

                if (actual.Severity != expected.Severity)
                {
                    AssertFalse(
                        string.Format("Expected diagnostic severity to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n    {2}\r\n",
                                      expected.Severity, actual.Severity, FormatDiagnostics(analyzer, actual)),
                        printActualDiagnosticsOnFailure,
                        expectedDiagnosticsAssertionTemplate,
                        actualResults);
                }

                if (actual.GetMessage() != expected.Message)
                {
                    AssertFalse(
                        string.Format("Expected diagnostic message to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n    {2}\r\n",
                                      expected.Message, actual.GetMessage(), FormatDiagnostics(analyzer, actual)),
                        printActualDiagnosticsOnFailure,
                        expectedDiagnosticsAssertionTemplate,
                        actualResults);
                }
            }
        }
 public static async Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource)
 => await VerifyCodeFixAsync(source, new[] { expected }, fixedSource);