private static WorkspaceProjectContextProvider CreateInstance(UnconfiguredProject project = null, IProjectThreadingService threadingService = null, IWorkspaceProjectContextFactory workspaceProjectContextFactory = null, ISafeProjectGuidService projectGuidService = null, IProjectRuleSnapshot projectRuleSnapshot = null)
        {
            projectRuleSnapshot = projectRuleSnapshot ?? IProjectRuleSnapshotFactory.FromJson(
                @"{
    ""Properties"": {
        ""MSBuildProjectFullPath"": ""C:\\Project\\Project.csproj"",
        ""LanguageServiceName"": ""CSharp"",
        ""TargetPath"": ""C:\\Target.dll""
    }
}");

            var telemetryService = ITelemetryServiceFactory.Create();

            project          = project ?? UnconfiguredProjectFactory.Create();
            threadingService = threadingService ?? IProjectThreadingServiceFactory.Create();
            workspaceProjectContextFactory = workspaceProjectContextFactory ?? IWorkspaceProjectContextFactoryFactory.Create();
            projectGuidService             = projectGuidService ?? ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(Guid.NewGuid());

            var mock = new Mock <WorkspaceProjectContextProvider>(project, threadingService, projectGuidService, telemetryService, workspaceProjectContextFactory.AsLazy());

            mock.Protected().Setup <Task <IProjectRuleSnapshot> >("GetLatestSnapshotAsync", ItExpr.IsAny <ConfiguredProject>())
            .ReturnsAsync(projectRuleSnapshot);

            return(mock.Object);
        }
        private StartupProjectRegistrar CreateInstance(
            UnconfiguredProject project           = null,
            IAsyncServiceProvider serviceProvider = null,
            IVsStartupProjectsListService vsStartupProjectsListService = null,
            IProjectThreadingService threadingService  = null,
            ISafeProjectGuidService projectGuidService = null,
            IActiveConfiguredProjectSubscriptionService projectSubscriptionService = null,
            ActiveConfiguredProject <DebuggerLaunchProviders> launchProviders      = null)
        {
            if (serviceProvider == null)
            {
                var sp = new IAsyncServiceProviderMoq();
                sp.AddService(typeof(SVsStartupProjectsListService), vsStartupProjectsListService ?? IVsStartupProjectsListServiceFactory.Create());
                serviceProvider = sp;
            }

            var instance = new StartupProjectRegistrar(
                project ?? UnconfiguredProjectFactory.Create(),
                serviceProvider,
                threadingService ?? new IProjectThreadingServiceMock(),
                projectGuidService ?? ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(Guid.NewGuid()),
                projectSubscriptionService ?? IActiveConfiguredProjectSubscriptionServiceFactory.Create(),
                launchProviders);

            return(instance);
        }
        public async Task CreateProjectContextAsync_UniquelyIdentifiesContext(string configuration, string guid, string expected)
        {
            var projectGuidService = ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(new Guid(guid));

            string result = null;
            var    workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((_, id, ___, ____, ______, _______) => { result = id; return(null); });
            var    provider = CreateInstance(workspaceProjectContextFactory: workspaceProjectContextFactory, projectGuidService: projectGuidService);

            var project = ConfiguredProjectFactory.ImplementProjectConfiguration(configuration);

            await provider.CreateProjectContextAsync(project);

            Assert.Equal(expected, result);
        }
        private static Task <StartupProjectRegistrar> CreateInitializedInstanceAsync(Guid projectGuid, IVsStartupProjectsListService?vsStartupProjectsListService, params IDebugLaunchProvider[] launchProviders)
        {
            var projectGuidService      = ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(projectGuid);
            var debuggerLaunchProviders = new OrderPrecedenceImportCollection <IDebugLaunchProvider>(ImportOrderPrecedenceComparer.PreferenceOrder.PreferredComesFirst);

            int orderPrecedence = 0;

            foreach (IDebugLaunchProvider launchProvider in launchProviders)
            {
                debuggerLaunchProviders.Add(launchProvider, orderPrecedence: orderPrecedence++);
            }

            return(CreateInitializedInstanceAsync(vsStartupProjectsListService: vsStartupProjectsListService,
                                                  projectGuidService: projectGuidService,
                                                  launchProviders: IActiveConfiguredValuesFactory.ImplementValues(() => debuggerLaunchProviders)));
        }
Exemple #5
0
        private Task <StartupProjectRegistrar> CreateInitializedInstanceAsync(Guid projectGuid, IVsStartupProjectsListService vsStartupProjectsListService, params IDebugLaunchProvider[] launchProviders)
        {
            var projectGuidService      = ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(projectGuid);
            var debuggerLaunchProviders = new DebuggerLaunchProviders(ConfiguredProjectFactory.Create());

            int orderPrecedence = 0;

            foreach (IDebugLaunchProvider launchProvider in launchProviders)
            {
                debuggerLaunchProviders.Debuggers.Add(launchProvider, orderPrecedence: orderPrecedence++);
            }

            return(CreateInitializedInstanceAsync(vsStartupProjectsListService: vsStartupProjectsListService,
                                                  projectGuidService: projectGuidService,
                                                  launchProviders: ActiveConfiguredProjectFactory.ImplementValue(() => debuggerLaunchProviders)));
        }
        private static StartupProjectRegistrar CreateInstance(
            IVsStartupProjectsListService?vsStartupProjectsListService = null,
            IProjectThreadingService?threadingService  = null,
            ISafeProjectGuidService?projectGuidService = null,
            IActiveConfiguredProjectSubscriptionService?projectSubscriptionService = null,
            ActiveConfiguredProject <DebuggerLaunchProviders>?launchProviders      = null)
        {
            var instance = new StartupProjectRegistrar(
                null !,
                IVsServiceFactory.Create <SVsStartupProjectsListService, IVsStartupProjectsListService>(vsStartupProjectsListService),
                threadingService ?? IProjectThreadingServiceFactory.Create(),
                projectGuidService ?? ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(Guid.NewGuid()),
                projectSubscriptionService ?? IActiveConfiguredProjectSubscriptionServiceFactory.Create(),
                launchProviders !);

            return(instance);
        }
        private static StartupProjectRegistrar CreateInstance(
            IVsStartupProjectsListService?vsStartupProjectsListService = null,
            IProjectThreadingService?threadingService  = null,
            ISafeProjectGuidService?projectGuidService = null,
            IActiveConfiguredProjectSubscriptionService?projectSubscriptionService = null,
            IActiveConfiguredValues <IDebugLaunchProvider>?launchProviders         = null)
        {
            var project  = UnconfiguredProjectFactory.Create();
            var instance = new StartupProjectRegistrar(
                project,
                IUnconfiguredProjectTasksServiceFactory.Create(),
                IVsServiceFactory.Create <SVsStartupProjectsListService, IVsStartupProjectsListService?>(vsStartupProjectsListService !),
                threadingService ?? IProjectThreadingServiceFactory.Create(),
                projectGuidService ?? ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(Guid.NewGuid()),
                projectSubscriptionService ?? IActiveConfiguredProjectSubscriptionServiceFactory.Create(),
                launchProviders !);

            return(instance);
        }
        public async Task CreateProjectContextAsync_PassesThroughDataToCreateProjectContext()
        {
            var projectRuleSnapshot = IProjectRuleSnapshotFactory.FromJson(
                @"{
    ""Properties"": {
        ""MSBuildProjectFullPath"": ""C:\\Project\\Project.csproj"",
        ""LanguageServiceName"": ""CSharp"",
        ""TargetPath"": ""C:\\Target.dll""
    }
}");
            var projectGuid        = new Guid("{72B509BD-C502-4707-ADFD-E2D43867CF45}");
            var projectGuidService = ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(projectGuid);

            var hostObject          = new object();
            var unconfiguredProject = UnconfiguredProjectFactory.Create(hostObject);

            string languageNameResult = null, projectFilePathResult = null, binOutputPathResult = null;
            Guid?  projectGuidResult              = null;
            object hierarchyResult                = null;
            var    workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((languageName, _, projectFilePath, guid, hierarchy, binOutputPath) =>
            {
                languageNameResult    = languageName;
                projectFilePathResult = projectFilePath;
                projectGuidResult     = guid;
                hierarchyResult       = hierarchy;
                binOutputPathResult   = binOutputPath;
                return(null);
            });

            var provider = CreateInstance(project: unconfiguredProject, workspaceProjectContextFactory: workspaceProjectContextFactory, projectGuidService: projectGuidService);
            var project  = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");

            await provider.CreateProjectContextAsync(project);

            Assert.Equal("CSharp", languageNameResult);
            Assert.Equal("C:\\Project\\Project.csproj", projectFilePathResult);
            Assert.Equal("C:\\Target.dll", binOutputPathResult);
            Assert.Equal(projectGuid, projectGuidResult.Value);
            Assert.Equal(hostObject, hierarchyResult);
        }