Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
        public void GlobaJsonSetup_NoExistingRemover_RegistersForAdvise()
        {
            UnitTestHelper.IsRunningUnitTests = true;
            GlobalJsonRemover.Remover         = null;

            var solution      = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(1234);
            var setupOccurred = new GlobalJsonRemover.GlobalJsonSetup().SetupRemoval(solution, IServiceProviderFactory.Create(), IFileSystemFactory.Create());

            Assert.True(setupOccurred);
            Assert.Equal(1234u, GlobalJsonRemover.Remover.SolutionCookie);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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 async Task FrameOpenCloseListener_InitializeEventsAsync_SetsUpWindowFrameEvents()
        {
            var uiShell = IVsUIShell7Factory.ImplementAdviseWindowEvents(l => 1);

            uint eventsCookie = 2;
            var  solution     = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(eventsCookie);

            var serviceProvider = IServiceProviderFactory.ImplementGetService(ServiceTypeChecker(uiShell, solution));

            var listener = new FrameOpenCloseListener(serviceProvider,
                                                      IProjectFileEditorPresenterFactory.Create(),
                                                      new IProjectThreadingServiceMock(),
                                                      UnconfiguredProjectFactory.Create());

            await listener.InitializeEventsAsync(IVsWindowFrameFactory.Create());

            Mock.Get(uiShell).Verify(u => u.AdviseWindowFrameEvents(listener), Times.Once);
            Mock.Get(solution).Verify(s => s.AdviseSolutionEvents(listener, out eventsCookie), Times.Once);
        }
        public async Task FrameOpenCloseListener_Dispose_UnsubscribesCorrectly()
        {
            var uiShell = IVsUIShell7Factory.ImplementAdviseUnadviseWindowEvents(l => 1234, c => Assert.Equal <uint>(1234, c));

            var solution = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(4321);

            var serviceProvider = IServiceProviderFactory.ImplementGetService(ServiceTypeChecker(uiShell, solution));

            var listener = new FrameOpenCloseListener(serviceProvider,
                                                      IProjectFileEditorPresenterFactory.Create(),
                                                      new IProjectThreadingServiceMock(),
                                                      UnconfiguredProjectFactory.Create());

            await listener.InitializeEventsAsync(IVsWindowFrameFactory.Create());

            await listener.DisposeAsync();

            Mock.Get(uiShell).Verify(u => u.UnadviseWindowFrameEvents(1234), Times.Once);
            Mock.Get(solution).Verify(s => s.UnadviseSolutionEvents(4321), Times.Once);
        }
        public void FrameOpenCloseListener_QueryUnloadCorrectProjectNoCancel_CallsCloseOnEditor()
        {
            var uiShell = IVsUIShell7Factory.ImplementAdviseUnadviseWindowEvents(l => 1234, c => Assert.Equal <uint>(1234, c));

            var solution = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(4321);

            var serviceProvider = IServiceProviderFactory.ImplementGetService(ServiceTypeChecker(uiShell, solution));

            var editorState = IProjectFileEditorPresenterFactory.ImplementCloseWindowAsync(true);

            var projPath            = @"C:\ConsoleApp\ConsoleApp1\ConsoleApp1.csproj";
            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projPath);
            var hierarchy           = IVsHierarchyFactory.ImplementAsUnconfiguredProject(unconfiguredProject);

            int shouldCancel = -1;

            var listener = new FrameOpenCloseListener(serviceProvider, editorState, new IProjectThreadingServiceMock(), unconfiguredProject);

            Assert.Equal(VSConstants.S_OK, listener.OnQueryUnloadProject(hierarchy, ref shouldCancel));
            Assert.Equal(0, shouldCancel);
            Mock.Get(editorState).Verify(e => e.CanCloseWindowAsync(), Times.Once);
        }
Ejemplo n.º 10
0
        private static DotNetCoreProjectCompatibilityDetector CreateCompatibilityDetector(out IDialogServices dialogServices,
                                                                                          string versionDataString      = null,
                                                                                          Version vsVersion             = null,
                                                                                          bool isSolutionOpen           = false,
                                                                                          bool hasNewProjects           = false,
                                                                                          bool usingPreviewSDK          = false,
                                                                                          string targetFrameworkMoniker = ".NETCoreApp,Version=v3.0")
        {
            dialogServices = IDialogServicesFactory.Create();
            var additionalReference = dialogServices;
            var projectProperties   = IProjectPropertiesFactory.CreateWithPropertyAndValue("TargetFrameworkMoniker", targetFrameworkMoniker);
            var propertiesProvider  = IProjectPropertiesProviderFactory.Create(commonProps: projectProperties);
            var project             = ConfiguredProjectFactory.Create(services: ConfiguredProjectServicesFactory.Create(projectPropertiesProvider: propertiesProvider));
            var scope                  = hasNewProjects ? IProjectCapabilitiesScopeFactory.Create(new[] { ProjectCapability.DotNet, ProjectCapability.PackageReferences }) : null;
            var projectAccessor        = new Lazy <IProjectServiceAccessor>(() => IProjectServiceAccessorFactory.Create(scope, project));
            var lazyDialogServices     = new Lazy <IDialogServices>(() => additionalReference);
            var threadHandling         = new Lazy <IProjectThreadingService>(() => IProjectThreadingServiceFactory.Create(verifyOnUIThread: false));
            var vsShellUtilitiesHelper = new Lazy <IVsShellUtilitiesHelper>(() => IVsShellUtilitiesHelperFactory.Create(string.Empty, vsVersion ?? new Version("16.1")));
            var fileSystem             = new Lazy <IFileSystem>(() => IFileSystemFactory.Create(existsFunc: x => true, readAllTextFunc: x => versionDataString ?? defaultVersionDataString));
            var httpClient             = new Lazy <IHttpClient>(() => IHttpClientFactory.Create(versionDataString ?? defaultVersionDataString));
            var vsUIShellService       = IVsServiceFactory.Create <SVsUIShell, IVsUIShell>(Mock.Of <IVsUIShell>());
            var settingsManagerService = IVsServiceFactory.Create <SVsSettingsPersistenceManager, ISettingsManager>(Mock.Of <ISettingsManager>());
            var vsSolutionService      = IVsServiceFactory.Create <SVsSolution, IVsSolution>(IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(1, isFullyLoaded: isSolutionOpen));
            var vsAppIdService         = IVsServiceFactory.Create <SVsAppId, IVsAppId>(Mock.Of <IVsAppId>());
            var vsShellService         = IVsServiceFactory.Create <SVsShell, IVsShell>(Mock.Of <IVsShell>());

            var compatibilityDetector = new TestDotNetCoreProjectCompatibilityDetector(projectAccessor,
                                                                                       lazyDialogServices,
                                                                                       threadHandling,
                                                                                       vsShellUtilitiesHelper,
                                                                                       fileSystem,
                                                                                       httpClient,
                                                                                       vsUIShellService,
                                                                                       settingsManagerService,
                                                                                       vsSolutionService,
                                                                                       vsAppIdService,
                                                                                       vsShellService,
                                                                                       hasNewProjects,
                                                                                       usingPreviewSDK);

            return(compatibilityDetector);
        }