Example #1
0
        public async Task FilesChanged_SkipsNonRegisteredProjects()
        {
            string projectFile = @"c:\temp\project1.csproj";
            var    spMock      = new IServiceProviderMoq();

            spMock.AddService(typeof(IVsFileChangeEx), typeof(SVsFileChangeEx), IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(100));
            spMock.AddService(typeof(IVsSolution), typeof(SVsSolution), IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(150));

            var rlm = new ProjectReloadManager(IProjectThreadingServiceFactory.Create(), spMock, IUserNotificationServicesFactory.ImplementReportErrorInfo(), new Mock <IDialogServices>().Object);

            var reloadableProjectMock = new Mock <IReloadableProject>(MockBehavior.Strict);

            reloadableProjectMock.Setup(x => x.ProjectFile).Returns(projectFile);

            await rlm.RegisterProjectAsync(reloadableProjectMock.Object);

            Assert.Equal <int>(1, rlm.RegisteredProjects.Count);

            rlm.FilesChanged(1, new string[1] {
                projectFile + ".csproj"
            }, new uint[1] {
                (uint)_VSFILECHANGEFLAGS.VSFILECHG_Size
            });
            Assert.True(rlm.ReloadDelayScheduler.LatestScheduledTask == null);
            reloadableProjectMock.VerifyAll();
        }
Example #2
0
        public async Task FilesChanged_CallsProjectToReload(_VSFILECHANGEFLAGS flags)
        {
            string projectFile = @"c:\temp\project1.csproj";
            var    spMock      = new IServiceProviderMoq();

            spMock.AddService(typeof(IVsFileChangeEx), typeof(SVsFileChangeEx), IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(100));
            spMock.AddService(typeof(IVsSolution), typeof(SVsSolution), IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(150));

            var rlm = new ProjectReloadManager(IProjectThreadingServiceFactory.Create(), spMock, IUserNotificationServicesFactory.ImplementReportErrorInfo(), new Mock <IDialogServices>().Object);

            var reloadableProjectMock = new Mock <IReloadableProject>(MockBehavior.Strict);

            reloadableProjectMock.Setup(x => x.ProjectFile).Returns(projectFile);
            reloadableProjectMock.Setup(x => x.ReloadProjectAsync()).Returns(Task.FromResult(ProjectReloadResult.ReloadCompleted));

            await rlm.RegisterProjectAsync(reloadableProjectMock.Object);

            Assert.Equal <int>(1, rlm.RegisteredProjects.Count);
            // Shorten the normal delay so unit tests run faster
            ((TaskDelayScheduler)rlm.ReloadDelayScheduler).TaskDelayTime = TimeSpan.FromMilliseconds(20);

            rlm.FilesChanged(1, new string[1] {
                projectFile
            }, new uint[1] {
                (uint)flags
            });
            await rlm.ReloadDelayScheduler.LatestScheduledTask;

            reloadableProjectMock.VerifyAll();
        }
Example #3
0
        public async Task Dispose_ValidateSolutionEventsEstablished()
        {
            var spMock = new IServiceProviderMoq();

            spMock.AddService(typeof(IVsFileChangeEx), typeof(SVsFileChangeEx), IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(100));
            spMock.AddService(typeof(IVsSolution), typeof(SVsSolution), IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(150));

            var rlm = new ProjectReloadManager(IProjectThreadingServiceFactory.Create(), spMock, IUserNotificationServicesFactory.ImplementReportErrorInfo(), new Mock <IDialogServices>().Object);

            await rlm.DisposeAsync();

            Assert.Equal <uint>(0, rlm.SolutionEventsCookie);
        }
        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));
        }
Example #5
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 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 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 ProjectAssetFileWatcher(spMock,
                                                      IProjectTreeProviderFactory.Create(),
                                                      IUnconfiguredProjectCommonServicesFactory.Create(),
                                                      IProjectLockServiceFactory.Create(),
                                                      IActiveConfiguredProjectSubscriptionServiceFactory.CreateInstance());

            watcher.Load();
            var projectUpdate = IProjectSubscriptionUpdateFactory.FromJson(ProjectCurrentStateJson);

            var firstTree = ProjectTreeParser.Parse(inputTree);

            watcher.DataFlow_Changed(IProjectVersionedValueFactory <Tuple <IProjectTreeSnapshot, IProjectSubscriptionUpdate> > .Create((Tuple.Create(IProjectTreeSnapshotFactory.Create(firstTree), projectUpdate))));

            var secondTree = ProjectTreeParser.Parse(changedTree);

            watcher.DataFlow_Changed(IProjectVersionedValueFactory <Tuple <IProjectTreeSnapshot, IProjectSubscriptionUpdate> > .Create((Tuple.Create(IProjectTreeSnapshotFactory.Create(secondTree), projectUpdate))));

            // 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 watcher = new ProjectAssetFileWatcher(spMock,
                                                      IProjectTreeProviderFactory.Create(),
                                                      IUnconfiguredProjectCommonServicesFactory.Create(),
                                                      IProjectLockServiceFactory.Create(),
                                                      IActiveConfiguredProjectSubscriptionServiceFactory.CreateInstance());

            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();
            watcher.DataFlow_Changed(IProjectVersionedValueFactory <Tuple <IProjectTreeSnapshot, IProjectSubscriptionUpdate> > .Create((Tuple.Create(IProjectTreeSnapshotFactory.Create(tree), projectUpdate))));

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

            fileChangeServiceMock.Verify(s => s.AdviseFileChange(It.IsAny <string>(), It.IsAny <uint>(), watcher, out cookie),
                                         Times.Never());
        }
Example #9
0
        public async Task Dispose_ValidateProjectIsUnRegistered()
        {
            var spMock = new IServiceProviderMoq();

            spMock.AddService(typeof(IVsFileChangeEx), typeof(SVsFileChangeEx), IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(100));
            spMock.AddService(typeof(IVsSolution), typeof(SVsSolution), IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(150));

            var rlmMock = new Mock <IProjectReloadManager>(MockBehavior.Strict);

            rlmMock.Setup(x => x.UnregisterProjectAsync(It.IsAny <IReloadableProject>())).Returns(Task.CompletedTask);

            var project = new ReloadableProject(IUnconfiguredProjectVsServicesFactory.Implement(), rlmMock.Object);

            await project.DisposeAsync();

            rlmMock.VerifyAll();
        }
Example #10
0
        public async Task Dispose_ValidateRegisterProject()
        {
            var spMock = new IServiceProviderMoq();

            spMock.AddService(typeof(IVsFileChangeEx), typeof(SVsFileChangeEx), IVsFileChangeExFactory.CreateWithAdviseUnadviseFileChange(100));
            spMock.AddService(typeof(IVsSolution), typeof(SVsSolution), IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(150));

            var rlm = new ProjectReloadManager(IProjectThreadingServiceFactory.Create(), spMock, IUserNotificationServicesFactory.ImplementReportErrorInfo(), new Mock <IDialogServices>().Object);

            var reloadableProjectMock = new Mock <IReloadableProject>(MockBehavior.Strict);

            reloadableProjectMock.Setup(x => x.ProjectFile).Returns(@"c:\temp\project1.csproj");

            await rlm.RegisterProjectAsync(reloadableProjectMock.Object);

            Assert.Equal <int>(1, rlm.RegisteredProjects.Count);
            Assert.Same(reloadableProjectMock.Object, rlm.RegisteredProjects.First().Key);
            reloadableProjectMock.VerifyAll();
        }
        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);
        }