Esempio n. 1
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));
        }
Esempio n. 2
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());
        }
Esempio n. 3
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);
        }
Esempio n. 4
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));
        }