Repository: dotnet/aspnetcore
File: src/Components/Analyzers/test/SupplyParameterFromFormAnalyzerTest.cs (C#)

Code before:
    [Fact]
    public void IgnoresNonComponentBaseClasses()
    {
        var test = $@"
    namespace ConsoleApplication1
    {{
        using {typeof(ParameterAttribute).Namespace};
        class NotAComponent
        {{
            [SupplyParameterFromForm] public string MyProperty {{ get; set; }} = ""default"";
        }}
    }}" + TestDeclarations;

        VerifyCSharpDiagnostic(test);
    }

    [Fact]
    public void ReportsWarningForSupplyParameterFromFormWithInitializer()
    {
        var test = $@"
    namespace ConsoleApplication1
    {{
        using {typeof(ParameterAttribute).Namespace};
        class TestComponent : ComponentBase
        {{
            [SupplyParameterFromForm] public string MyProperty {{ get; set; }} = ""default"";
        }}
    }}" + TestDeclarations;

        var expected = new DiagnosticResult
        {
            Id = "BL0008",
            Message = "Property 'ConsoleApplication1.TestComponent.MyProperty' has [SupplyParameterFromForm] and a property initializer. This can be overwritten with null during form posts.",
            Severity = DiagnosticSeverity.Warning,
            Locations = new[]
            {
                new DiagnosticResultLocation("Test0.cs", 7, 53)
            }
        };

        VerifyCSharpDiagnostic(test, expected);
    }

    [Fact]
    public void ReportsWarningForSupplyParameterFromFormWithObjectInitializer()
    {
        var test = $@"
    namespace ConsoleApplication1
    {{
        using {typeof(ParameterAttribute).Namespace};
        class TestComponent : ComponentBase

Review comment (suggestion):
@copilot Instead of using the string literal default which can be confused with the `default` keyword, use something else like "initial-value"

Code after:
    [Fact]
    public void IgnoresNonComponentBaseClasses()
    {
        var test = $@"
    namespace ConsoleApplication1
    {{
        using {typeof(ParameterAttribute).Namespace};
        class NotAComponent
        {{
            [SupplyParameterFromForm] public string MyProperty {{ get; set; }} = ""initial-value"";
        }}
    }}" + TestDeclarations;

        VerifyCSharpDiagnostic(test);
    }

    [Fact]
    public void ReportsWarningForSupplyParameterFromFormWithInitializer()
    {
        var test = $@"
    namespace ConsoleApplication1
    {{
        using {typeof(ParameterAttribute).Namespace};
        class TestComponent : ComponentBase
        {{
            [SupplyParameterFromForm] public string MyProperty {{ get; set; }} = ""initial-value"";
        }}
    }}" + TestDeclarations;

        var expected = new DiagnosticResult
        {
            Id = "BL0008",
            Message = "Property 'ConsoleApplication1.TestComponent.MyProperty' has [SupplyParameterFromForm] and a property initializer. This can be overwritten with null during form posts.",
            Severity = DiagnosticSeverity.Warning,
            Locations = new[]
            {
                new DiagnosticResultLocation("Test0.cs", 7, 53)
            }
        };

        VerifyCSharpDiagnostic(test, expected);
    }

    [Fact]
    public void ReportsWarningForSupplyParameterFromFormWithObjectInitializer()
    {
        var test = $@"
    namespace ConsoleApplication1
    {{
        using {typeof(ParameterAttribute).Namespace};
        class TestComponent : ComponentBase