Beispiel #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));
        }
        public void VerifyFileWatcherRegistrationOnTreeChange(string inputTree, string changedTree, int numRegisterCalls, int numUnregisterCalls)
        {
            var  spMock            = new IServiceProviderMoq();
            uint adviseCookie      = 100;
            var  fileChangeService = IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(adviseCookie);

            spMock.AddService(typeof(IVsFileChangeEx), typeof(SVsFileChangeEx), fileChangeService);

            var propertyData = CreateBaseIntermediateOutputPathProperty("obj\\");

            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: @"C:\Foo\foo.proj");
            var watcher             = new ProjectAssetFileWatcher(spMock,
                                                                  IProjectTreeProviderFactory.Create(),
                                                                  IUnconfiguredProjectCommonServicesFactory.Create(unconfiguredProject,
                                                                                                                   projectProperties: ProjectPropertiesFactory.Create(unconfiguredProject, new[] { propertyData })),
                                                                  IProjectLockServiceFactory.Create());

            watcher.Load();

            var firstTree = ProjectTreeParser.Parse(inputTree);

            watcher.ProjectTree_ChangedAsync(IProjectVersionedValueFactory <IProjectTreeSnapshot> .Create(IProjectTreeSnapshotFactory.Create(firstTree)));

            var secondTree = ProjectTreeParser.Parse(changedTree);

            watcher.ProjectTree_ChangedAsync(IProjectVersionedValueFactory <IProjectTreeSnapshot> .Create(IProjectTreeSnapshotFactory.Create(secondTree)));

            // If fileToWatch is null then we expect to not register any filewatcher.
            Mock <IVsFileChangeEx> 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 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());
        }
        public void WhenBaseIntermediateOutputPathNotSet_DoesNotAttemptToAdviseFileChange()
        {
            var spMock            = new IServiceProviderMoq();
            var fileChangeService = IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(100);

            spMock.AddService(typeof(IVsFileChangeEx), typeof(SVsFileChangeEx), fileChangeService);

            var propertyData = CreateBaseIntermediateOutputPathProperty(string.Empty);

            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: @"C:\Foo\foo.proj");
            var watcher             = new ProjectAssetFileWatcher(spMock,
                                                                  IProjectTreeProviderFactory.Create(),
                                                                  IUnconfiguredProjectCommonServicesFactory.Create(unconfiguredProject,
                                                                                                                   projectProperties: ProjectPropertiesFactory.Create(unconfiguredProject, new[] { propertyData })),
                                                                  IProjectLockServiceFactory.Create());

            var tree = ProjectTreeParser.Parse(@"Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\foo.proj""");

            watcher.Load();
            watcher.ProjectTree_ChangedAsync(IProjectVersionedValueFactory <IProjectTreeSnapshot> .Create(IProjectTreeSnapshotFactory.Create(tree)));

            Mock <IVsFileChangeEx> fileChangeServiceMock = Mock.Get(fileChangeService);
            uint cookie;

            fileChangeServiceMock.Verify(s => s.AdviseFileChange(It.IsAny <string>(), It.IsAny <uint>(), watcher, out cookie),
                                         Times.Never());
        }
        public void VerifyFileWatcherRegistration(string inputTree, string fileToWatch)
        {
            var  spMock            = new IServiceProviderMoq();
            uint adviseCookie      = 100;
            var  fileChangeService = IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(adviseCookie);

            spMock.AddService(typeof(IVsFileChangeEx), typeof(SVsFileChangeEx), fileChangeService);

            var watcher = new ProjectAssetFileWatcher(spMock,
                                                      IProjectTreeProviderFactory.Create(),
                                                      IUnconfiguredProjectCommonServicesFactory.Create(),
                                                      IProjectLockServiceFactory.Create(),
                                                      IActiveConfiguredProjectSubscriptionServiceFactory.CreateInstance());

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

            watcher.Load();
            watcher.DataFlow_Changed(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);
        }
Beispiel #6
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 ProjectAssetFileWatcher(
                       IVsServiceFactory.Create <SVsFileChangeEx, IVsAsyncFileChangeEx>(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.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 #7
0
        public async Task WhenBaseIntermediateOutputPathNotSet_DoesNotAttemptToAdviseFileChange()
        {
            var fileChangeService = IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(100);

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

            using (var watcher = new ProjectAssetFileWatcher(
                       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""
            }
        }
    }
}");

                watcher.Load();
                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());
            }
        }
        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);
        }