Exemple #1
0
        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 propertyData = new PropertyPageData
            {
                Category     = ConfigurationGeneral.SchemaName,
                PropertyName = ConfigurationGeneral.BaseIntermediateOutputPathProperty,
                Value        = "obj\\"
            };
            var unconfiguredProject = IUnconfiguredProjectFactory.Create(filePath: @"C:\Foo\foo.proj");
            var watcher             = new ProjectLockFileWatcher(spMock,
                                                                 IProjectTreeProviderFactory.Create(),
                                                                 IUnconfiguredProjectCommonServicesFactory.Create(unconfiguredProject,
                                                                                                                  projectProperties: ProjectPropertiesFactory.Create(unconfiguredProject, new[] { propertyData })),
                                                                 IProjectLockServiceFactory.Create());

            var tree = ProjectTreeParser.Parse(inputTree);

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

            // If fileToWatch is null then we expect to not register any filewatcher.
            var times = fileToWatch == null?Times.Never() : Times.Once();

            Mock.Get <IVsFileChangeEx>(fileChangeService).Verify(s => s.AdviseFileChange(fileToWatch ?? It.IsAny <string>(), It.IsAny <uint>(), watcher, out adviseCookie), times);
        }
        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 watcher = new ProjectLockFileWatcher(spMock,
                                                     IProjectTreeProviderFactory.Create(),
                                                     IUnconfiguredProjectCommonServicesFactory.Create(IUnconfiguredProjectFactory.Create(filePath: @"C:\Foo\foo.proj")),
                                                     IProjectLockServiceFactory.Create());

            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 <IVsFileChangeEx>(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 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 ProjectLockFileWatcher(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 ProjectLockFileWatcher(spMock,
                                                     IProjectTreeProviderFactory.Create(),
                                                     IUnconfiguredProjectCommonServicesFactory.Create(IUnconfiguredProjectFactory.Create(filePath: @"C:\Foo\foo.proj")),
                                                     IProjectLockServiceFactory.Create());

            var tree = ProjectTreeParser.Parse(inputTree);

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

            // If fileToWatch is null then we expect to not register any filewatcher.
            var times = fileToWatch == null?Times.Never() : Times.Once();

            Mock.Get <IVsFileChangeEx>(fileChangeService).Verify(s => s.AdviseFileChange(fileToWatch ?? It.IsAny <string>(), It.IsAny <uint>(), watcher, out adviseCookie), times);
        }