Beispiel #1
0
        public async Task WhenBaseIntermediateOutputPathNotSet_DoesNotAttemptToAdviseFileChange()
        {
            var spMock            = new IAsyncServiceProviderMoq();
            var fileChangeService = IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(100);

            spMock.AddService(typeof(SVsFileChangeEx), fileChangeService);
            var tasksService = IUnconfiguredProjectTasksServiceFactory.ImplementLoadedProjectAsync <ConfiguredProject>(t => t());

            var watcher = new ProjectAssetFileWatcher(spMock,
                                                      IProjectTreeProviderFactory.Create(),
                                                      IUnconfiguredProjectCommonServicesFactory.Create(threadingService: new IProjectThreadingServiceMock()),
                                                      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());
        }
Beispiel #2
0
        public async Task VerifyFileWatcherRegistrationOnTreeChange(string inputTree, string changedTree, int numRegisterCalls, int numUnregisterCalls)
        {
            var  spMock            = new IAsyncServiceProviderMoq();
            uint adviseCookie      = 100;
            var  fileChangeService = IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(adviseCookie);

            spMock.AddService(typeof(SVsFileChangeEx), fileChangeService);
            var tasksService = IUnconfiguredProjectTasksServiceFactory.ImplementLoadedProjectAsync <ConfiguredProject>(t => t());

            var watcher = new ProjectAssetFileWatcher(spMock,
                                                      IProjectTreeProviderFactory.Create(),
                                                      IUnconfiguredProjectCommonServicesFactory.Create(threadingService: new IProjectThreadingServiceMock()),
                                                      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));
        }
Beispiel #3
0
        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());

            using var watcher = new ProjectAssetFileWatcherInstance(
                      IVsServiceFactory.Create <SVsFileChangeEx, IVsAsyncFileChangeEx>(fileChangeService),
                      IProjectTreeProviderFactory.Create(),
                      IUnconfiguredProjectCommonServicesFactory.Create(threadingService: IProjectThreadingServiceFactory.Create()),
                      tasksService,
                      IActiveConfiguredProjectSubscriptionServiceFactory.Create());
            await watcher.InitializeAsync();

            var projectUpdate = IProjectSubscriptionUpdateFactory.FromJson(ProjectCurrentStateJson);

            var firstTree = ProjectTreeParser.Parse(inputTree);
            await watcher.DataFlow_ChangedAsync(IProjectVersionedValueFactory.Create(Tuple.Create(IProjectTreeSnapshotFactory.Create(firstTree), projectUpdate)));

            var secondTree = ProjectTreeParser.Parse(changedTree);
            await watcher.DataFlow_ChangedAsync(IProjectVersionedValueFactory.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.AdviseFileChangeAsync(It.IsAny <string>(), It.IsAny <_VSFILECHANGEFLAGS>(), watcher, CancellationToken.None),
                                         Times.Exactly(numRegisterCalls));
            fileChangeServiceMock.Verify(s => s.UnadviseFileChangeAsync(adviseCookie, CancellationToken.None), Times.Exactly(numUnregisterCalls));
        }
Beispiel #4
0
        public async Task WhenBaseIntermediateOutputPathNotSet_DoesNotAttemptToAdviseFileChange()
        {
            var fileChangeService = IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(100);

            var tasksService = IUnconfiguredProjectTasksServiceFactory.ImplementLoadedProjectAsync <ConfiguredProject>(t => t());

            using var watcher = new ProjectAssetFileWatcherInstance(
                      IVsServiceFactory.Create <SVsFileChangeEx, IVsAsyncFileChangeEx>(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""
            }
        }
    }
}");

            await watcher.InitializeAsync();

            await watcher.DataFlow_ChangedAsync(IProjectVersionedValueFactory.Create(Tuple.Create(IProjectTreeSnapshotFactory.Create(tree), projectUpdate)));

            var fileChangeServiceMock = Mock.Get(fileChangeService);

            fileChangeServiceMock.Verify(s => s.AdviseFileChangeAsync(It.IsAny <string>(), It.IsAny <_VSFILECHANGEFLAGS>(), watcher, CancellationToken.None),
                                         Times.Never());
        }
Beispiel #5
0
        private StartupProjectRegistrar CreateInstance(
            UnconfiguredProject project           = null,
            IAsyncServiceProvider serviceProvider = null,
            IVsStartupProjectsListService vsStartupProjectsListService = null,
            IProjectThreadingService threadingService = null,
            IProjectGuidService2 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(),
                projectSubscriptionService ?? IActiveConfiguredProjectSubscriptionServiceFactory.Create(),
                launchProviders);

            if (projectGuidService != null)
            {
                instance.ProjectGuidServices.Add((IProjectGuidService)projectGuidService);
            }

            return(instance);
        }
        private static DesignTimeInputsDataSource CreateDesignTimeInputsDataSource(out ProjectValueDataSource <IProjectSubscriptionUpdate> sourceItemsRuleSource)
        {
            var unconfiguredProjectServices = UnconfiguredProjectServicesFactory.Create(
                projectService: IProjectServiceFactory.Create(
                    services: ProjectServicesFactory.Create(
                        threadingService: IProjectThreadingServiceFactory.Create(),
                        projectLockService: IProjectLockServiceFactory.Create())));
            var unconfiguredProject = UnconfiguredProjectFactory.Create(unconfiguredProjectServices: unconfiguredProjectServices);

            sourceItemsRuleSource = new ProjectValueDataSource <IProjectSubscriptionUpdate>(unconfiguredProjectServices);

            var projectSubscriptionService = IActiveConfiguredProjectSubscriptionServiceFactory.Create(sourceItemsRuleSource: sourceItemsRuleSource);

            var dataSource = new DesignTimeInputsDataSource(unconfiguredProject, unconfiguredProjectServices, projectSubscriptionService);

            return(dataSource);
        }
Beispiel #7
0
            public TestTempPEBuildManager(IFileSystem fileSystem)
                : base(IProjectThreadingServiceFactory.Create(),
                       IUnconfiguredProjectCommonServicesFactory.Create(threadingService: IProjectThreadingServiceFactory.Create()),
                       IActiveWorkspaceProjectContextHostFactory.Create(),
                       IActiveConfiguredProjectSubscriptionServiceFactory.Create(),
                       null,
                       fileSystem,
                       IProjectFaultHandlerServiceFactory.Create(),
                       null)
            {
                BuildManager = new TestBuildManager(this);

                AppliedValue = new ProjectVersionedValue <DesignTimeInputsItem>(new DesignTimeInputsItem()
                {
                    OutputPath = "TempPE"
                }, ImmutableDictionary <NamedIdentity, IComparable> .Empty);
            }
        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);
        }
Beispiel #9
0
        public DesignTimeInputsChangeTrackerTests()
        {
            var services = IProjectCommonServicesFactory.CreateWithDefaultThreadingPolicy();

            using var designTimeInputsSource = ProjectValueDataSourceFactory.Create <DesignTimeInputs>(services);

            var dataSourceMock = new Mock <IDesignTimeInputsDataSource>();

            dataSourceMock.SetupGet(s => s.SourceBlock)
            .Returns(designTimeInputsSource.SourceBlock);

            using var fileWatcherSource = ProjectValueDataSourceFactory.Create <string[]>(services);

            var watcherMock = new Mock <IDesignTimeInputsFileWatcher>();

            watcherMock.SetupGet(s => s.SourceBlock)
            .Returns(fileWatcherSource.SourceBlock);

            var threadingService           = IProjectThreadingServiceFactory.Create();
            var projectSubscriptionService = IActiveConfiguredProjectSubscriptionServiceFactory.Create();
            var unconfiguredProject        = UnconfiguredProjectFactory.Create(
                filePath: Path.Combine(_projectFolder, "MyTestProj.csproj"),
                projectAsynchronousTasksService: IProjectAsynchronousTasksServiceFactory.Create());

            var unconfiguredProjectServices = IUnconfiguredProjectServicesFactory.Create(
                projectService: IProjectServiceFactory.Create(
                    services: ProjectServicesFactory.Create(
                        threadingService: threadingService)));

            _changeTracker = new DesignTimeInputsChangeTracker(unconfiguredProject,
                                                               unconfiguredProjectServices,
                                                               threadingService,
                                                               projectSubscriptionService,
                                                               dataSourceMock.Object,
                                                               watcherMock.Object)
            {
                AllowSourceBlockCompletion = true
            };


            // Create a block to receive the output
            var receiver = DataflowBlockSlim.CreateActionBlock <IProjectVersionedValue <DesignTimeInputsDelta> >(OutputProduced);

            _changeTracker.SourceBlock.LinkTo(receiver, DataflowOption.PropagateCompletion);
        }
        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);
        }
Beispiel #11
0
        public static TestVisualBasicNamespaceImportsList CreateInstance(params string[] list)
        {
            var newList = new TestVisualBasicNamespaceImportsList(
                UnconfiguredProjectFactory.Create(),
                IProjectThreadingServiceFactory.Create(),
                IActiveConfiguredProjectSubscriptionServiceFactory.Create());

            newList.VSImports = new Lazy <VisualBasicVSImports>(() => new TestVisualBasicVSImports(
                                                                    Mock.Of <VSLangProj.VSProject>(),
                                                                    IProjectThreadingServiceFactory.Create(),
                                                                    IActiveConfiguredValueFactory.ImplementValue(() => ConfiguredProjectFactory.Create()),
                                                                    IProjectAccessorFactory.Create(),
                                                                    IUnconfiguredProjectVsServicesFactory.Create(),
                                                                    newList));

            newList.TestApply(list);

            newList.ImportsAdded.Clear();
            newList.ImportsRemoved.Clear();

            return(newList);
        }
Beispiel #12
0
        private StartupProjectRegistrar CreateInstance(
            IAsyncServiceProvider serviceProvider = null,
            IVsStartupProjectsListService vsStartupProjectsListService = null,
            IProjectThreadingService threadingService = null,
            IProjectGuidService2 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;
            }

            return(new StartupProjectRegistrar(
                       serviceProvider,
                       threadingService ?? new IProjectThreadingServiceMock(),
                       projectGuidService ?? IProjectGuidService2Factory.ImplementGetProjectGuidAsync(Guid.NewGuid()),
                       projectSubscriptionService ?? IActiveConfiguredProjectSubscriptionServiceFactory.Create(),
                       launchProviders));
        }
        public async Task VerifyFileWatcherRegistration(string inputTree, string fileToWatch)
        {
            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());

            var tree          = ProjectTreeParser.Parse(inputTree);
            var projectUpdate = IProjectSubscriptionUpdateFactory.FromJson(ProjectCurrentStateJson);

            watcher.Load();
            await watcher.DataFlow_ChangedAsync(IProjectVersionedValueFactory <Tuple <IProjectTreeSnapshot, IProjectSubscriptionUpdate> > .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.AdviseFileChange(fileToWatch ?? It.IsAny <string>(), It.IsAny <uint>(), watcher, out adviseCookie), times);
        }