Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Symbol/Compilation/GetUnusedImportDirectivesTests.cs (C#)

Code before:
            }
        }
    }
}
""";
            var classLib2 = CreateCompilation(source: class2Source, assemblyName: "ClassLibrary2", references: [classLib1.ToMetadataReference()]);

            string consoleApplicationSource = """
using ClassLibrary2;
using ClassLibrary1;

var instance1 = new Class1();
instance1.Method1("Argument1");
""";
            var tree = Parse(consoleApplicationSource);
            var comp = CreateCompilation(tree, [classLib1.ToMetadataReference(), classLib2.ToMetadataReference()], assemblyName: "ConsoleApplication");
            var model = comp.GetSemanticModel(tree) as CSharpSemanticModel;

            var syntax = tree.GetRoot().DescendantNodes().OfType<InvocationExpressionSyntax>().Single().Expression;

            //This is the crux of the test.
            //Without this line, with or without the fix, the model never gets pushed to evaluate extension method candidates
            //and therefore never marked ClassLibrary2 as a used import in consoleApplication.
            //Without the fix, this call used to result in ClassLibrary2 getting marked as used, after the fix, this call does not
            //result in changing ClassLibrary2's used status.
            model.GetMemberGroup(syntax);

            model.GetDiagnostics().Verify(
                // (1,1): hidden CS8019: Unnecessary using directive.
                // using ClassLibrary2;
                Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using ClassLibrary2;").WithLocation(1, 1));
        }

        [WorkItem(747219, "DevDiv2/DevDiv")]
        [Fact]
        public void UnusedUsing747219()
        {
            var text = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
 
class Program
{
    static void Main(string[] args)
    {
        Enumerable.Repeat(1, 1);
    }
}";
            var comp = CreateEmptyCompilation(text, new[] { MscorlibRef });

Review comment (suggestion):
>model.GetMemberGroup(syntax); [](http://example.com/codeflow?start=12&length=29)

Does the set include a method from ClassLibrary2? Consider asserting the fact to strengthen the test and to make it clearer. #Closed

Code after:
                // using System.Collections.Generic;
                Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using System.Collections.Generic;"),
                // (5,1): info CS8019: Unnecessary using directive.
                // using System.Threading.Tasks;
                Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using System.Threading.Tasks;")
                );

            comp = comp.WithReferences(comp.References.Concat(SystemCoreRef));
            comp.VerifyDiagnostics(
                // (2,1): info CS8019: Unnecessary using directive.
                // using System;
                Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using System;"),
                // (3,1): info CS8019: Unnecessary using directive.
                // using System.Collections.Generic;
                Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using System.Collections.Generic;"),
                // (5,1): info CS8019: Unnecessary using directive.
                // using System.Threading.Tasks;
                Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using System.Threading.Tasks;")
                );
        }

        [Fact]
        public void UsedUsing1()
        {
            var text = @"
using System;

class C
{
    void Goo()
    {
        Console.WriteLine();
    }
}";
            var tree = Parse(text);
            var comp = CreateCompilation(tree);
            comp.VerifyDiagnostics();
        }

        [Fact]
        public void SpeculativeBindingDoesNotAffectResult()
        {
            var text = @"
using System;

class C
{
    void Goo()
    {
        /*here*/
    }