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