예제 #1
0
        public async Task FindReferences_DifferingAssemblies()
        {
            var solution = new AdhocWorkspace().CurrentSolution;

            solution = AddProjectWithMetadataReferences(solution, "NetStandardProject", LanguageNames.CSharp, @"
namespace N
{
    public interface I
    {
        System.Uri Get();
    }
}", NetStandard20Ref);

            solution = AddProjectWithMetadataReferences(solution, "DesktopProject", LanguageNames.CSharp, @"
using N;

namespace N2 
{
    public class Impl : I
    {
        public System.Uri Get()
        {
            return null;
        }
    }
}", SystemRef_v46, solution.Projects.Single(pid => pid.Name == "NetStandardProject").Id);

            var desktopProject = solution.Projects.First(p => p.Name == "DesktopProject");

            solution = solution.AddMetadataReferences(desktopProject.Id, new[] { MscorlibRef_v46, Net46StandardFacade });

            desktopProject = solution.GetProject(desktopProject.Id);
            var netStandardProject = solution.Projects.First(p => p.Name == "NetStandardProject");

            var interfaceMethod = (IMethodSymbol)(await netStandardProject.GetCompilationAsync()).GetTypeByMetadataName("N.I").GetMembers("Get").First();

            var references = (await SymbolFinder.FindReferencesAsync(interfaceMethod, solution)).ToList();

            Assert.Equal(2, references.Count);

            var projectIds = new HashSet <ProjectId>();

            foreach (var r in references)
            {
                projectIds.Add(solution.GetOriginatingProjectId(r.Definition));
            }

            Assert.True(projectIds.Contains(desktopProject.Id));
        }