private void VerifyCSharpDiagnostic(string assertion)
        {
            var code = new StringBuilder()
                       .AppendLine("using System;")
                       .AppendLine("using FluentAssertions;using FluentAssertions.Extensions;")
                       .AppendLine("namespace TestNamespace")
                       .AppendLine("{")
                       .AppendLine("    class TestClass")
                       .AppendLine("    {")
                       .AppendLine("        void TestMethod(int? actual, int expected)")
                       .AppendLine("        {")
                       .AppendLine($"            {assertion}")
                       .AppendLine("        }")
                       .AppendLine("    }")
                       .AppendLine("    class Program")
                       .AppendLine("    {")
                       .AppendLine("        public static void Main()")
                       .AppendLine("        {")
                       .AppendLine("        }")
                       .AppendLine("    }")
                       .AppendLine("}")
                       .ToString();

            DiagnosticVerifier.VerifyCSharpDiagnostic <NullConditionalAssertionAnalyzer>(code, new DiagnosticResult
            {
                Id        = NullConditionalAssertionAnalyzer.DiagnosticId,
                Message   = NullConditionalAssertionAnalyzer.Message,
                Severity  = Microsoft.CodeAnalysis.DiagnosticSeverity.Warning,
                Locations = new DiagnosticResultLocation[]
                {
                    new DiagnosticResultLocation("Test0.cs", 9, 13)
                }
            });
        }
Esempio n. 2
0
        public void CollectionShouldHaveElementAt_ShouldIgnoreDictionaryTypes()
        {
            string source = GenerateCode.DictionaryAssertion("actual[\"key\"].Should().Be(expectedValue);");

            DiagnosticVerifier.VerifyCSharpDiagnostic <CollectionShouldHaveElementAtAnalyzer>(source);
        }