public async Task WhenBaseIntermediateOutputPathNotSet_DoesNotAttemptToAdviseFileChange() { var fileChangeService = IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(100); var tasksService = IUnconfiguredProjectTasksServiceFactory.ImplementLoadedProjectAsync <ConfiguredProject>(t => t()); var watcher = new ProjectAssetFileWatcher(IVsServiceFactory.Create <SVsFileChangeEx, IVsFileChangeEx>(fileChangeService), IProjectTreeProviderFactory.Create(), IUnconfiguredProjectCommonServicesFactory.Create(threadingService: IProjectThreadingServiceFactory.Create()), tasksService, IActiveConfiguredProjectSubscriptionServiceFactory.Create()); var tree = ProjectTreeParser.Parse(@"Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\foo.proj"""); var projectUpdate = IProjectSubscriptionUpdateFactory.FromJson(@"{ ""CurrentState"": { ""ConfigurationGeneral"": { ""Properties"": { ""MSBuildProjectFullPath"": ""C:\\Foo\\foo.proj"" } } } }"); watcher.Load(); await watcher.DataFlow_ChangedAsync(IProjectVersionedValueFactory <Tuple <IProjectTreeSnapshot, IProjectSubscriptionUpdate> > .Create((Tuple.Create(IProjectTreeSnapshotFactory.Create(tree), projectUpdate)))); var fileChangeServiceMock = Mock.Get(fileChangeService); uint cookie; fileChangeServiceMock.Verify(s => s.AdviseFileChange(It.IsAny <string>(), It.IsAny <uint>(), watcher, out cookie), Times.Never()); }
public async Task VerifyFileWatcherRegistrationOnTreeChange(string inputTree, string changedTree, int numRegisterCalls, int numUnregisterCalls) { uint adviseCookie = 100; var fileChangeService = IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(adviseCookie); var tasksService = IUnconfiguredProjectTasksServiceFactory.ImplementLoadedProjectAsync <ConfiguredProject>(t => t()); var watcher = new ProjectAssetFileWatcher(IVsServiceFactory.Create <SVsFileChangeEx, IVsFileChangeEx>(fileChangeService), IProjectTreeProviderFactory.Create(), IUnconfiguredProjectCommonServicesFactory.Create(threadingService: IProjectThreadingServiceFactory.Create()), tasksService, IActiveConfiguredProjectSubscriptionServiceFactory.Create()); watcher.Load(); var projectUpdate = IProjectSubscriptionUpdateFactory.FromJson(ProjectCurrentStateJson); var firstTree = ProjectTreeParser.Parse(inputTree); await watcher.DataFlow_ChangedAsync(IProjectVersionedValueFactory <Tuple <IProjectTreeSnapshot, IProjectSubscriptionUpdate> > .Create((Tuple.Create(IProjectTreeSnapshotFactory.Create(firstTree), projectUpdate)))); var secondTree = ProjectTreeParser.Parse(changedTree); await watcher.DataFlow_ChangedAsync(IProjectVersionedValueFactory <Tuple <IProjectTreeSnapshot, IProjectSubscriptionUpdate> > .Create((Tuple.Create(IProjectTreeSnapshotFactory.Create(secondTree), projectUpdate)))); // If fileToWatch is null then we expect to not register any filewatcher. var fileChangeServiceMock = Mock.Get(fileChangeService); fileChangeServiceMock.Verify(s => s.AdviseFileChange(It.IsAny <string>(), It.IsAny <uint>(), watcher, out adviseCookie), Times.Exactly(numRegisterCalls)); fileChangeServiceMock.Verify(s => s.UnadviseFileChange(adviseCookie), Times.Exactly(numUnregisterCalls)); }
private static async Task <ImplicitlyTriggeredDebugBuildManager> CreateInitializedInstanceAsync( Action?onImplicitBuildStart = null, Action?onImplicitBuildEndOrCancel = null, bool startDebuggingBuild = false, bool startWithoutDebuggingBuild = false, bool skipAnalyzersForImplicitBuildsOption = true) { var buildFlags = VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_NONE; if (startDebuggingBuild) { buildFlags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_LAUNCHDEBUG; } if (startWithoutDebuggingBuild) { buildFlags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_LAUNCH; } var solutionBuildManager = IVsSolutionBuildManager3Factory.Create(buildFlags: buildFlags); var serviceProvider = IVsServiceFactory.Create <SVsSolutionBuildManager, IVsSolutionBuildManager3>(solutionBuildManager); var instance = new ImplicitlyTriggeredDebugBuildManager( IProjectThreadingServiceFactory.Create(), IProjectSystemOptionsWithChangesFactory.ImplementGetSkipAnalyzersForImplicitlyTriggeredBuildAsync(_ => skipAnalyzersForImplicitBuildsOption), serviceProvider, IImplicitlyTriggeredBuildManagerFactory.Create(onImplicitBuildStart, onImplicitBuildEndOrCancel)); await instance.LoadAsync(); return(instance); }
private static VsContainedLanguageComponentsFactory CreateInstance(IOleAsyncServiceProvider serviceProvider = null, IUnconfiguredProjectVsServices projectVsServices = null, IActiveWorkspaceProjectContextHost projectContextHost = null) { projectVsServices = projectVsServices ?? IUnconfiguredProjectVsServicesFactory.Create(); projectContextHost = projectContextHost ?? IActiveWorkspaceProjectContextHostFactory.Create(); return(new VsContainedLanguageComponentsFactory(IVsServiceFactory.Create <SAsyncServiceProvider, IOleAsyncServiceProvider>(serviceProvider), projectVsServices, projectContextHost)); }
public async Tasks.Task VerifyProjectNotAdded() { var projectGuid = Guid.NewGuid(); var mockIVsStartupProjectsListService = IVsStartupProjectsListServiceFactory.CreateMockInstance(projectGuid); var iVsStartupProjectsListService = IVsServiceFactory.Create <SVsStartupProjectsListService, IVsStartupProjectsListService>(mockIVsStartupProjectsListService.Object); var debuggerLaunchProvider = CreateDebuggerLaunchProviderInstance(); debuggerLaunchProvider.Debuggers.Add(GetLazyDebugLaunchProvider(debugs: false)); var activeConfiguredProjectWithLaunchProviders = ActiveConfiguredProjectFactory.ImplementValue(() => debuggerLaunchProvider); var startupProjectRegistrar = CreateInstance( iVsStartupProjectsListService, activeConfiguredProjectWithLaunchProviders); var testWrapperMethod = new DataFlowExtensionMethodCaller(new DataFlowExtensionMethodWrapperMock()); startupProjectRegistrar.WrapperMethodCaller = testWrapperMethod; await startupProjectRegistrar.Load(); var projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(@"{ ""ProjectChanges"": { ""ConfigurationGeneral"": { ""Difference"": { ""ChangedProperties"": [ ""Something"" ] } } } }"); await startupProjectRegistrar.ConfigurationGeneralRuleBlock_ChangedAsync( IProjectVersionedValueFactory <IProjectSubscriptionUpdate> .Create(projectSubscriptionUpdate)); mockIVsStartupProjectsListService.Verify(s => s.RemoveProject(ref projectGuid), Times.Never); mockIVsStartupProjectsListService.Verify(s => s.AddProject(ref projectGuid), Times.Never); projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(@"{ ""ProjectChanges"": { ""ConfigurationGeneral"": { ""Difference"": { ""ChangedProperties"": [ ""ProjectGuid"" ] }, ""After"": { ""Properties"": { ""ProjectGuid"": ""GuidNotParsable"" } } } } }"); await startupProjectRegistrar.ConfigurationGeneralRuleBlock_ChangedAsync( IProjectVersionedValueFactory <IProjectSubscriptionUpdate> .Create(projectSubscriptionUpdate)); mockIVsStartupProjectsListService.Verify(s => s.RemoveProject(ref projectGuid), Times.Never); mockIVsStartupProjectsListService.Verify(s => s.AddProject(ref projectGuid), Times.Never); }
private IVsService <SVsSettingsPersistenceManager, ISettingsManager> CreateSettingsManagerService(bool enableSymbolicRename) { var settingsManagerMock = new Mock <ISettingsManager>(); settingsManagerMock.Setup(f => f.GetValueOrDefault("SolutionNavigator.EnableSymbolicRename", true)) .Returns(enableSymbolicRename); return(IVsServiceFactory.Create <SVsSettingsPersistenceManager, ISettingsManager>(settingsManagerMock.Object)); }
public async Tasks.Task VerifyProjectAdded_RemovedWithChange() { var projectGuid = Guid.NewGuid(); var mockIVsStartupProjectsListService = IVsStartupProjectsListServiceFactory.CreateMockInstance(projectGuid); var iVsStartupProjectsListService = IVsServiceFactory.Create <SVsStartupProjectsListService, IVsStartupProjectsListService>(mockIVsStartupProjectsListService.Object); var serviceProvider = SVsServiceProviderFactory.Create(iVsStartupProjectsListService); var debuggerLaunchProvider = CreateDebuggerLaunchProviderInstance(); debuggerLaunchProvider.Debuggers.Add(GetLazyDebugLaunchProvider(debugs: true)); var activeConfiguredProjectWithLaunchProviders = ActiveConfiguredProjectFactory.ImplementValue(() => debuggerLaunchProvider); var startupProjectRegistrar = CreateInstance( iVsStartupProjectsListService, activeConfiguredProjectWithLaunchProviders); var projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(@"{ ""ProjectChanges"": { ""ConfigurationGeneral"": { ""Difference"": { ""ChangedProperties"": [ ""ProjectGuid"" ] }, ""After"": { ""Properties"": { ""ProjectGuid"": """ + projectGuid + @""" } } } } }"); await startupProjectRegistrar.ConfigurationGeneralRuleBlock_ChangedAsync( IProjectVersionedValueFactory <IProjectSubscriptionUpdate> .Create(projectSubscriptionUpdate)); mockIVsStartupProjectsListService.Verify(s => s.AddProject(ref projectGuid), Times.Once); mockIVsStartupProjectsListService.Verify(s => s.RemoveProject(ref projectGuid), Times.Never); debuggerLaunchProvider.Debuggers.Clear(); debuggerLaunchProvider.Debuggers.Add(GetLazyDebugLaunchProvider(debugs: false)); projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(@"{ ""ProjectChanges"": { ""ConfigurationGeneral"": { ""Difference"": { ""ChangedProperties"": [ ""OutputType"" ] } } } }"); await startupProjectRegistrar.ConfigurationGeneralRuleBlock_ChangedAsync( IProjectVersionedValueFactory <IProjectSubscriptionUpdate> .Create(projectSubscriptionUpdate)); mockIVsStartupProjectsListService.Verify(s => s.RemoveProject(ref projectGuid), Times.Once); }
private static VsContainedLanguageComponentsFactory CreateInstance(IOleAsyncServiceProvider serviceProvider = null, IUnconfiguredProjectVsServices projectVsServices = null, IProjectHostProvider projectHostProvider = null, ILanguageServiceHost languageServiceHost = null) { projectVsServices = projectVsServices ?? IUnconfiguredProjectVsServicesFactory.Create(); projectHostProvider = projectHostProvider ?? IProjectHostProviderFactory.Create(); languageServiceHost = languageServiceHost ?? ILanguageServiceHostFactory.Create(); return(new VsContainedLanguageComponentsFactory(IVsServiceFactory.Create <SAsyncServiceProvider, IOleAsyncServiceProvider>(serviceProvider), projectVsServices, projectHostProvider, languageServiceHost)); }
private static (VisualStudioWaitIndicator, Action cancel) CreateVisualStudioWaitIndicator(string title = "", string message = "", bool isCancelable = false) { var threadingService = IProjectThreadingServiceFactory.Create(); var(threadedWaitDialogFactory, cancel) = IVsThreadedWaitDialogFactoryFactory.Create(title, message, isCancelable); var threadedWaitDialogFactoryService = IVsServiceFactory.Create <SVsThreadedWaitDialogFactory, IVsThreadedWaitDialogFactory>(threadedWaitDialogFactory); var unconfiguredProject = UnconfiguredProjectFactory.Create(); var waitIndicator = new VisualStudioWaitIndicator(unconfiguredProject, threadingService, threadedWaitDialogFactoryService); return(waitIndicator, cancel); }
private static async Task <(VisualStudioWaitIndicator.Instance, Action cancel)> CreateAsync(string title = "", string message = "", bool isCancelable = false) { var threadingService = IProjectThreadingServiceFactory.Create(); var(threadedWaitDialogFactory, cancel) = IVsThreadedWaitDialogFactoryFactory.Create(title, message, isCancelable); var threadedWaitDialogFactoryService = IVsServiceFactory.Create <SVsThreadedWaitDialogFactory, IVsThreadedWaitDialogFactory>(threadedWaitDialogFactory); var instance = new VisualStudioWaitIndicator.Instance(threadingService, threadedWaitDialogFactoryService); await instance.InitializeAsync(); return(instance, cancel); }
internal AbstractGenerateNuGetPackageCommand CreateInstance( GeneratePackageOnBuildPropertyProvider generatePackageOnBuildPropertyProvider = null, IVsSolutionBuildManager2 buildManager = null, IVsUpdateSolutionEvents solutionEventsListener = null, bool isBuilding = false, bool cancelBuild = false) { var hierarchy = IVsHierarchyFactory.Create(); var project = UnconfiguredProjectFactory.Create(hierarchy); var threadingService = IProjectThreadingServiceFactory.Create(); buildManager ??= IVsSolutionBuildManager2Factory.Create(solutionEventsListener, hierarchy, isBuilding, cancelBuild); var serviceProvider = IVsServiceFactory.Create<SVsSolutionBuildManager, IVsSolutionBuildManager2>(buildManager); generatePackageOnBuildPropertyProvider ??= CreateGeneratePackageOnBuildPropertyProvider(); return CreateInstanceCore(project, threadingService, serviceProvider, generatePackageOnBuildPropertyProvider); }
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 DotNetCoreProjectCompatibilityDetector CreateCompatibilityDetector(out IDialogServices dialogServices, string?versionDataString = null, Version?vsVersion = null, bool isSolutionOpen = false, bool hasNewProjects = false, bool usingPreviewSDK = false, bool isCapabilityMatch = true, string targetFrameworkMoniker = ".NETCoreApp,Version=v3.0") { dialogServices = IDialogServicesFactory.Create(); var additionalReference = dialogServices; var projectProperties = IProjectPropertiesFactory.CreateWithPropertyAndValue("TargetFrameworkMoniker", targetFrameworkMoniker); var propertiesProvider = IProjectPropertiesProviderFactory.Create(commonProps: projectProperties); var project = ConfiguredProjectFactory.Create(services: ConfiguredProjectServicesFactory.Create(projectPropertiesProvider: propertiesProvider)); var scope = hasNewProjects ? IProjectCapabilitiesScopeFactory.Create(new[] { ProjectCapability.DotNet, ProjectCapability.PackageReferences }) : null; var projectAccessor = new Lazy <IProjectServiceAccessor>(() => IProjectServiceAccessorFactory.Create(scope, project)); var lazyDialogServices = new Lazy <IDialogServices>(() => additionalReference); var threadHandling = new Lazy <IProjectThreadingService>(() => IProjectThreadingServiceFactory.Create(verifyOnUIThread: false)); var vsShellUtilitiesHelper = new Lazy <IVsShellUtilitiesHelper>(() => IVsShellUtilitiesHelperFactory.Create(string.Empty, vsVersion ?? new Version("16.1"))); var fileSystem = new Lazy <IFileSystem>(() => IFileSystemFactory.Create(existsFunc: x => true, readAllTextFunc: x => versionDataString ?? defaultVersionDataString)); var httpClient = new Lazy <IHttpClient>(() => IHttpClientFactory.Create(versionDataString ?? defaultVersionDataString)); var vsUIShellService = IVsServiceFactory.Create <SVsUIShell, IVsUIShell>(Mock.Of <IVsUIShell>()); var settingsManagerService = IVsServiceFactory.Create <SVsSettingsPersistenceManager, ISettingsManager>(Mock.Of <ISettingsManager>()); var vsSolutionService = IVsServiceFactory.Create <SVsSolution, IVsSolution>(IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(1, isFullyLoaded: isSolutionOpen)); var vsAppIdService = IVsServiceFactory.Create <SVsAppId, IVsAppId>(Mock.Of <IVsAppId>()); var vsShellService = IVsServiceFactory.Create <SVsShell, IVsShell>(Mock.Of <IVsShell>()); var compatibilityDetector = new TestDotNetCoreProjectCompatibilityDetector(projectAccessor, lazyDialogServices, threadHandling, vsShellUtilitiesHelper, fileSystem, httpClient, vsUIShellService, settingsManagerService, vsSolutionService, vsAppIdService, vsShellService, hasNewProjects, usingPreviewSDK, isCapabilityMatch); return(compatibilityDetector); }
public async Task VerifyFileWatcherRegistration(string inputTree, string fileToWatch) { uint adviseCookie = 100; var fileChangeService = IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(adviseCookie); var tasksService = IUnconfiguredProjectTasksServiceFactory.ImplementLoadedProjectAsync <ConfiguredProject>(t => t()); using var watcher = new ProjectAssetFileWatcherInstance(IVsServiceFactory.Create <SVsFileChangeEx, Shell.IVsAsyncFileChangeEx>(fileChangeService), IProjectTreeProviderFactory.Create(), IUnconfiguredProjectCommonServicesFactory.Create(threadingService: IProjectThreadingServiceFactory.Create()), tasksService, IActiveConfiguredProjectSubscriptionServiceFactory.Create()); var tree = ProjectTreeParser.Parse(inputTree); var projectUpdate = IProjectSubscriptionUpdateFactory.FromJson(ProjectCurrentStateJson); await watcher.InitializeAsync(); await watcher.DataFlow_ChangedAsync(IProjectVersionedValueFactory.Create(Tuple.Create(IProjectTreeSnapshotFactory.Create(tree), projectUpdate))); // If fileToWatch is null then we expect to not register any filewatcher. var times = fileToWatch == null?Times.Never() : Times.Once(); Mock.Get(fileChangeService).Verify(s => s.AdviseFileChangeAsync(fileToWatch ?? It.IsAny <string>(), It.IsAny <_VSFILECHANGEFLAGS>(), watcher, CancellationToken.None), times); }
private static DesignTimeInputsFileWatcher CreateDesignTimeInputsFileWatcher(IVsAsyncFileChangeEx fileChangeService, out ProjectValueDataSource <DesignTimeInputs> source) { // Create our mock design time inputs data source, but with a source we can actually use var services = IProjectCommonServicesFactory.CreateWithDefaultThreadingPolicy(); source = ProjectValueDataSourceFactory.Create <DesignTimeInputs>(services); var mock = new Mock <IDesignTimeInputsDataSource>(); mock.SetupGet(s => s.SourceBlock) .Returns(source.SourceBlock); var dataSource = mock.Object; var threadingService = IProjectThreadingServiceFactory.Create(); var unconfiguredProject = UnconfiguredProjectFactory.Create(fullPath: @"C:\MyProject\MyProject.csproj"); var unconfiguredProjectServices = IUnconfiguredProjectServicesFactory.Create( projectService: IProjectServiceFactory.Create( services: ProjectServicesFactory.Create( threadingService: threadingService))); // Create our class under test return(new DesignTimeInputsFileWatcher(unconfiguredProject, unconfiguredProjectServices, threadingService, dataSource, IVsServiceFactory.Create <SVsFileChangeEx, IVsAsyncFileChangeEx>(fileChangeService))); }
public void Constructor_NullAsGeneratePackageOnBuildPropertyProvider_ThrowsArgumentNull() { Assert.Throws <ArgumentNullException>(() => CreateInstanceCore(UnconfiguredProjectFactory.Create(), IProjectThreadingServiceFactory.Create(), IVsServiceFactory.Create <SVsSolutionBuildManager, IVsSolutionBuildManager2>(null), null)); }