public void TestInit()
        {
            this.serviceProvider = new ConfigurableServiceProvider();
            this.sonarQubeService = new ConfigurableSonarQubeServiceWrapper();
            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            this.host.SonarQubeService = this.sonarQubeService;
            this.projectSystemHelper = new ConfigurableVsProjectSystemHelper(this.serviceProvider);

            this.sonarQubeService.RegisterServerPlugin(new ServerPlugin { Key = MinimumSupportedServerPlugin.CSharp.Key, Version = MinimumSupportedServerPlugin.CSharp.MinimumVersion });
            this.sonarQubeService.RegisterServerPlugin(new ServerPlugin { Key = MinimumSupportedServerPlugin.VbNet.Key, Version = MinimumSupportedServerPlugin.VbNet.MinimumVersion });
            this.settings = new ConfigurableIntegrationSettings();

            var mefExports = MefTestHelpers.CreateExport<IIntegrationSettings>(settings);
            var mefModel = ConfigurableComponentModel.CreateWithExports(mefExports);
            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);

            this.filter = new ConfigurableProjectSystemFilter();
            this.serviceProvider.RegisterService(typeof(IProjectSystemFilter), this.filter);

            var outputWindow = new ConfigurableVsOutputWindow();
            this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane();
            this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow);
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper);
        }
 public void TestInitialize()
 {
     ThreadHelper.SetCurrentThreadAsUIThread();
     this.serviceProvider = new ConfigurableServiceProvider(assertOnUnexpectedServiceRequest: false);
     this.sonarQubeService = new ConfigurableSonarQubeServiceWrapper();
     this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
     this.host.SonarQubeService = this.sonarQubeService;
     this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), new ConfigurableVsProjectSystemHelper(this.serviceProvider));
 }
Exemplo n.º 3
0
        private StateManager CreateTestSubject(ConfigurableHost host, ConfigurableSectionController section = null)
        {
            var testSubject = new StateManager(host, new TransferableVisualState());

            if (section != null)
            {
                section.ViewModel.State = testSubject.ManagedState;
            }

            return(testSubject);
        }
        public void TestInitialize()
        {
            ThreadHelper.SetCurrentThreadAsUIThread();
            this.serviceProvider = new ConfigurableServiceProvider(assertOnUnexpectedServiceRequest: false);

            this.sonarQubeServiceMock = new Mock <ISonarQubeService>();
            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher)
            {
                SonarQubeService = this.sonarQubeServiceMock.Object
            };
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), new ConfigurableVsProjectSystemHelper(this.serviceProvider));
        }
        public void TestInitialize()
        {
            var provider = new ConfigurableServiceProvider();
            this.projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider);
            provider.RegisterService(typeof(IProjectSystemHelper), this.projectSystem);

            var host = new ConfigurableHost(provider, Dispatcher.CurrentDispatcher);
            var propertyManager = new ProjectPropertyManager(host);
            var mefExports = MefTestHelpers.CreateExport<IProjectPropertyManager>(propertyManager);
            var mefModel = ConfigurableComponentModel.CreateWithExports(mefExports);
            provider.RegisterService(typeof(SComponentModel), mefModel);

            this.serviceProvider = provider;
        }
        public void StateManager_Dispose()
        {
            // Arrange
            ConfigurableHost host        = new ConfigurableHost();
            StateManager     testSubject = this.CreateTestSubject(host);
            var connection1 = new ConnectionInformation(new Uri("http://conn1"));

            testSubject.SetProjects(connection1, new SonarQubeProject[0]);

            // Act
            testSubject.Dispose();

            // Assert
            connection1.IsDisposed.Should().BeTrue("Leaking connections?");
        }
Exemplo n.º 7
0
        public void StateManager_Dispose()
        {
            // Setup
            ConfigurableHost host        = new ConfigurableHost();
            StateManager     testSubject = this.CreateTestSubject(host);
            var connection1 = new ConnectionInformation(new Uri("http://conn1"));

            testSubject.SetProjects(connection1, new ProjectInformation[0]);

            // Act
            testSubject.Dispose();

            // Verify
            Assert.IsTrue(connection1.IsDisposed, "Leaking connections?");
        }
Exemplo n.º 8
0
        public void TestInitialize()
        {
            this.serviceProvider = new ConfigurableServiceProvider();

            this.projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider);
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystem);

            var host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);

            var propertyManager = new ProjectPropertyManager(host);
            var mefExports      = MefTestHelpers.CreateExport <IProjectPropertyManager>(propertyManager);
            var mefModel        = ConfigurableComponentModel.CreateWithExports(mefExports);

            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);
        }
        public void ClearBoundProject_RaisesBindingStateChangedWithExpectedArgs()
        {
            // Arrange
            ConfigurableHost host            = new ConfigurableHost();
            var testSubject                  = this.CreateTestSubject(host);
            BindingStateEventArgs actualArgs = null;

            testSubject.BindingStateChanged += (sender, e) => actualArgs = e;

            // Act
            testSubject.ClearBoundProject();

            // Assert
            actualArgs.Should().NotBeNull();
            actualArgs.IsBindingCleared.Should().BeTrue();
        }
        public void TestInit()
        {
            this.sonarQubeService = new ConfigurableSonarQubeServiceWrapper();
            this.connectionWorkflow = new ConfigurableConnectionWorkflow(this.sonarQubeService);
            this.connectionProvider = new ConfigurableConnectionInformationProvider();
            this.serviceProvider = new ConfigurableServiceProvider();
            var outputWindow = new ConfigurableVsOutputWindow();
            this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane();
            this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow);
            this.settings = new ConfigurableIntegrationSettings();
            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.host.SonarQubeService = this.sonarQubeService;

            var mefExports = MefTestHelpers.CreateExport<IIntegrationSettings>(settings);
            var mefModel = ConfigurableComponentModel.CreateWithExports(mefExports);
            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);
        }
Exemplo n.º 11
0
        public void TestInitialize()
        {
            this.serviceProvider = new ConfigurableServiceProvider(false);

            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.activeSolutionBoundTracker = new ConfigurableActiveSolutionBoundTracker();
            var outputWindow = new ConfigurableVsOutputWindow();

            var mefExport1 = MefTestHelpers.CreateExport <IHost>(this.host);
            var mefExport2 = MefTestHelpers.CreateExport <IActiveSolutionBoundTracker>(this.activeSolutionBoundTracker);
            var mefModel   = ConfigurableComponentModel.CreateWithExports(mefExport1, mefExport2);

            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);
            this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow);

            this.testSubject = new SonarAnalyzerManager(this.serviceProvider, new AdhocWorkspace());
        }
        public void TestInitialize()
        {
            this.serviceProvider = new ConfigurableServiceProvider(false);

            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.activeSolutionBoundTracker = new ConfigurableActiveSolutionBoundTracker();
            var outputWindow = new ConfigurableVsOutputWindow();

            var mefExport1 = MefTestHelpers.CreateExport<IHost>(this.host);
            var mefExport2 = MefTestHelpers.CreateExport<IActiveSolutionBoundTracker>(this.activeSolutionBoundTracker);
            var mefModel = ConfigurableComponentModel.CreateWithExports(mefExport1, mefExport2);

            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);
            this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow);

            this.testSubject = new SonarAnalyzerManager(this.serviceProvider, new AdhocWorkspace());
        }
        public void TestInitialize()
        {
            ThreadHelper.SetCurrentThreadAsUIThread();
            this.serviceProvider = new ConfigurableServiceProvider(assertOnUnexpectedServiceRequest: false);
            this.sonarQubeService = new ConfigurableSonarQubeServiceWrapper();
            this.stepRunner = new ConfigurableProgressStepRunner();
            this.solutionBinding = new ConfigurableSolutionBindingSerializer();

            var projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider);
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), projectSystem);

            var host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);

            var propertyManager = new ProjectPropertyManager(host);
            var mefExports = MefTestHelpers.CreateExport<IProjectPropertyManager>(propertyManager);
            var mefModel = ConfigurableComponentModel.CreateWithExports(mefExports);
            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);
        }
Exemplo n.º 14
0
        public void TestInitialize()
        {
            ThreadHelper.SetCurrentThreadAsUIThread();
            this.serviceProvider = new ConfigurableServiceProvider(assertOnUnexpectedServiceRequest: false);

            IComponentModel componentModel = ConfigurableComponentModel.CreateWithExports(
                new Export[]
            {
                MefTestHelpers.CreateExport <ITelemetryLogger>(new ConfigurableTelemetryLogger())
            });

            this.serviceProvider.RegisterService(typeof(SComponentModel), componentModel);


            this.sonarQubeServiceMock = new Mock <ISonarQubeService>();
            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.host.SonarQubeService = this.sonarQubeServiceMock.Object;
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), new ConfigurableVsProjectSystemHelper(this.serviceProvider));
        }
        public void StateManager_IsBusyChanged()
        {
            // Arrange
            var section                  = ConfigurableSectionController.CreateDefault();
            ConfigurableHost host        = new ConfigurableHost();
            StateManager     testSubject = this.CreateTestSubject(host);

            testSubject.IsBusyChanged += (s, isBusy) => section.ViewModel.IsBusy = isBusy;

            // Case 1: no active section -> no-op (i.e. no exception)
            testSubject.IsBusy = true;
            testSubject.ManagedState.IsBusy.Should().BeTrue();
            testSubject.IsBusy = false;
            testSubject.ManagedState.IsBusy.Should().BeFalse();

            // Case 2: has active section
            host.SetActiveSection(section);

            // Sanity (!IsBusy)
            section.ViewModel.IsBusy.Should().BeFalse();

            // Act (IsBusy -> IsBusy)
            testSubject.IsBusy = true;

            // Assert
            section.ViewModel.IsBusy.Should().BeTrue();
            testSubject.ManagedState.IsBusy.Should().BeTrue();

            // Act (!IsBusy -> !IsBusy)
            testSubject.IsBusy = false;

            // Assert
            section.ViewModel.IsBusy.Should().BeFalse();
            testSubject.ManagedState.IsBusy.Should().BeFalse();

            // Dispose (should stop updated the view model)
            testSubject.Dispose();
            testSubject.IsBusy = true;

            // Assert
            section.ViewModel.IsBusy.Should().BeFalse();
            testSubject.ManagedState.IsBusy.Should().BeTrue();
        }
Exemplo n.º 16
0
        public void TestInit()
        {
            this.sonarQubeServiceMock   = new Mock <ISonarQubeService>();
            this.connectionWorkflowMock = new Mock <IConnectionWorkflowExecutor>();
            this.connectionProvider     = new ConfigurableConnectionInformationProvider();
            this.serviceProvider        = new ConfigurableServiceProvider();
            var outputWindow = new ConfigurableVsOutputWindow();

            this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane();
            this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow);
            this.settings = new ConfigurableSonarLintSettings();
            this.host     = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.host.SonarQubeService = this.sonarQubeServiceMock.Object;

            var mefExports = MefTestHelpers.CreateExport <ISonarLintSettings>(settings);
            var mefModel   = ConfigurableComponentModel.CreateWithExports(mefExports);

            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);
        }
        public void SetBoundProject_RaisesBindingStateChangedWithExpectedArgs()
        {
            // Arrange
            ConfigurableHost host            = new ConfigurableHost();
            var testSubject                  = this.CreateTestSubject(host);
            BindingStateEventArgs actualArgs = null;

            testSubject.BindingStateChanged += (sender, e) => actualArgs = e;

            testSubject.ManagedState.ConnectedServers.Add(new ServerViewModel(new ConnectionInformation(new Uri("http://zzz1"))));
            testSubject.ManagedState.ConnectedServers.ToList().ForEach(s => s.Projects.Add(new ProjectViewModel(s, new SonarQubeProject(Guid.NewGuid().ToString(), ""))));
            var allProjects = testSubject.ManagedState.ConnectedServers.SelectMany(s => s.Projects).ToList();

            // Act
            testSubject.SetBoundProject(new Uri("http://zzz1"), null, allProjects.First().Project.Key);

            // Assert
            actualArgs.Should().NotBeNull();
            actualArgs.IsBindingCleared.Should().BeFalse();
        }
Exemplo n.º 18
0
        public void TestInitialize()
        {
            ThreadHelper.SetCurrentThreadAsUIThread();
            this.serviceProvider      = new ConfigurableServiceProvider(assertOnUnexpectedServiceRequest: false);
            this.sonarQubeServiceMock = new Mock <ISonarQubeService>();
            this.stepRunner           = new ConfigurableProgressStepRunner();
            this.solutionBinding      = new ConfigurableSolutionBindingSerializer();

            var projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider);

            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), projectSystem);

            var host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);

            var propertyManager = new ProjectPropertyManager(host);
            var mefExports      = MefTestHelpers.CreateExport <IProjectPropertyManager>(propertyManager);
            var mefModel        = ConfigurableComponentModel.CreateWithExports(mefExports);

            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);
        }
        public void StateManager_SetBoundProject()
        {
            // Arrange
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;
            ConfigurableHost             host          = new ConfigurableHost();

            host.SetActiveSection(section);
            StateManager testSubject = this.CreateTestSubject(host);

            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            var conn = new ConnectionInformation(new Uri("http://xyz"))
            {
                Organization = new SonarQubeOrganization("org1", "org1 name")
            };
            var projects = new[] { new SonarQubeProject("111", ""), new SonarQubeProject("222", "") };

            testSubject.SetProjects(conn, projects);
            TransferableVisualState state = testSubject.ManagedState;
            bool hasBoundProjectChanged   = false;

            state.PropertyChanged += (o, e) =>
            {
                e.PropertyName.Should().Be(nameof(state.HasBoundProject));
                hasBoundProjectChanged = true;
            };

            // Act
            testSubject.SetBoundProject(conn.ServerUri, "org1", "222");

            // Assert
            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            var serverVM   = state.ConnectedServers.Single();
            var project0VM = serverVM.Projects.Single(p => p.Project == projects[0]);
            var project1VM = serverVM.Projects.Single(p => p.Project == projects[1]);

            project1VM.IsBound.Should().BeTrue();
            project0VM.IsBound.Should().BeFalse();
            testSubject.ManagedState.HasBoundProject.Should().BeTrue("Expected a bound project");
            hasBoundProjectChanged.Should().BeTrue("HasBoundProject expected to change");
        }
        public void TestInitialize()
        {
            KnownUIContextsAccessor.Reset();
            this.sonarQubeService = new ConfigurableSonarQubeServiceWrapper();
            this.workflow         = new TestBindingWorkflow();
            this.serviceProvider  = new ConfigurableServiceProvider();
            this.dteMock          = new DTEMock();
            this.serviceProvider.RegisterService(typeof(DTE), this.dteMock);
            this.solutionMock        = new SolutionMock();
            this.monitorSelection    = KnownUIContextsAccessor.MonitorSelectionService;
            this.projectSystemHelper = new ConfigurableVsProjectSystemHelper(this.serviceProvider);
            this.conflictsController = new ConfigurableRuleSetConflictsController();
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper);
            this.serviceProvider.RegisterService(typeof(IRuleSetConflictsController), this.conflictsController);

            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.host.SonarQubeService = sonarQubeService;

            // Instead of ignored unexpected service, register one (for telemetry)
            this.serviceProvider.RegisterService(typeof(SComponentModel), new ConfigurableComponentModel());
        }
        public void StateManager_IsConnected()
        {
            // Arrange
            ConfigurableHost host        = new ConfigurableHost();
            StateManager     testSubject = this.CreateTestSubject(host);

            // Sanity
            testSubject.IsConnected.Should().BeFalse();

            // Act (connect)
            testSubject.SetProjects(new ConnectionInformation(new Uri("http://qwerty")), new SonarQubeProject[0]);

            // Assert
            testSubject.IsConnected.Should().BeTrue();

            // Act (disconnect)
            testSubject.SetProjects(new ConnectionInformation(new Uri("http://qwerty")), null);

            // Assert
            testSubject.IsConnected.Should().BeFalse();
        }
        public void TestInitialize()
        {
            KnownUIContextsAccessor.Reset();
            this.sonarQubeService = new ConfigurableSonarQubeServiceWrapper();
            this.workflow = new TestBindingWorkflow();
            this.serviceProvider = new ConfigurableServiceProvider();
            this.dteMock = new DTEMock();
            this.serviceProvider.RegisterService(typeof(DTE), this.dteMock);
            this.solutionMock = new SolutionMock();
            this.monitorSelection = KnownUIContextsAccessor.MonitorSelectionService;
            this.projectSystemHelper = new ConfigurableVsProjectSystemHelper(this.serviceProvider);
            this.conflictsController = new ConfigurableRuleSetConflictsController();
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper);
            this.serviceProvider.RegisterService(typeof(IRuleSetConflictsController), this.conflictsController);

            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.host.SonarQubeService = sonarQubeService;

            // Instead of ignored unexpected service, register one (for telemetry)
            this.serviceProvider.RegisterService(typeof(SComponentModel), new ConfigurableComponentModel());
        }
Exemplo n.º 23
0
        public void StateManager_IsConnected()
        {
            // Setup
            ConfigurableHost host        = new ConfigurableHost();
            StateManager     testSubject = this.CreateTestSubject(host);

            // Sanity
            Assert.IsFalse(testSubject.IsConnected);

            // Act (connect)
            testSubject.SetProjects(new ConnectionInformation(new Uri("http://qwerty")), new ProjectInformation[0]);

            // Verify
            Assert.IsTrue(testSubject.IsConnected);

            // Act (disconnect)
            testSubject.SetProjects(new ConnectionInformation(new Uri("http://qwerty")), null);

            // Verify
            Assert.IsFalse(testSubject.IsConnected);
        }
        public void TestInitialize()
        {
            KnownUIContextsAccessor.Reset();
            this.sonarQubeService = new Mock <ISonarQubeService>();
            this.workflow         = new TestBindingWorkflow();
            this.serviceProvider  = new ConfigurableServiceProvider();
            this.dteMock          = new DTEMock();
            this.serviceProvider.RegisterService(typeof(DTE), this.dteMock);
            this.solutionMock                = new SolutionMock();
            this.monitorSelection            = KnownUIContextsAccessor.MonitorSelectionService;
            this.projectSystemHelper         = new ConfigurableVsProjectSystemHelper(this.serviceProvider);
            this.conflictsController         = new ConfigurableRuleSetConflictsController();
            this.configProvider              = new ConfigurableConfigurationProvider();
            this.ruleSetsInformationProvider = new ConfigurableSolutionRuleSetsInformationProvider();
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper);
            this.serviceProvider.RegisterService(typeof(IRuleSetConflictsController), this.conflictsController);
            this.serviceProvider.RegisterService(typeof(IConfigurationProvider), this.configProvider);
            this.serviceProvider.RegisterService(typeof(ISolutionRuleSetsInformationProvider), this.ruleSetsInformationProvider);
            this.serviceProvider.RegisterService(typeof(ISourceControlledFileSystem), new ConfigurableSourceControlledFileSystem(new MockFileSystem()));

            var outputWindow = new ConfigurableVsOutputWindow();

            this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane();
            this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow);

            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher)
            {
                SonarQubeService = sonarQubeService.Object
            };

            IComponentModel componentModel = ConfigurableComponentModel.CreateWithExports(
                new []
            {
                MefTestHelpers.CreateExport <ITelemetryLogger>(new ConfigurableTelemetryLogger())
            });

            this.serviceProvider.RegisterService(typeof(SComponentModel), componentModel);
        }
Exemplo n.º 25
0
        public void StateManager_SetBoundProject()
        {
            // Setup
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;
            ConfigurableHost             host          = new ConfigurableHost();

            host.SetActiveSection(section);
            StateManager testSubject = this.CreateTestSubject(host);

            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            var conn     = new ConnectionInformation(new Uri("http://xyz"));
            var projects = new[] { new ProjectInformation(), new ProjectInformation() };

            testSubject.SetProjects(conn, projects);
            TransferableVisualState state = testSubject.ManagedState;
            bool hasBoundProjectChanged   = false;

            state.PropertyChanged += (o, e) =>
            {
                Assert.AreEqual(nameof(state.HasBoundProject), e.PropertyName);
                hasBoundProjectChanged = true;
            };

            // Act
            testSubject.SetBoundProject(projects[1]);

            // Verify
            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            var serverVM   = state.ConnectedServers.Single();
            var project0VM = serverVM.Projects.Single(p => p.ProjectInformation == projects[0]);
            var project1VM = serverVM.Projects.Single(p => p.ProjectInformation == projects[1]);

            Assert.IsTrue(project1VM.IsBound, "Expected to be bound");
            Assert.IsFalse(project0VM.IsBound, "Not expected to be bound");
            Assert.IsTrue(testSubject.ManagedState.HasBoundProject, "Expected a bound project");
            Assert.IsTrue(hasBoundProjectChanged, "HasBoundProject expected to change");
        }
Exemplo n.º 26
0
        public void StateManager_GetConnectedServer()
        {
            // Arrange
            const string     SharedKey   = "Key"; // The key is the same for all projects on purpose
            ConfigurableHost host        = new ConfigurableHost();
            StateManager     testSubject = this.CreateTestSubject(host);
            var connection1 = new ConnectionInformation(new Uri("http://conn1"));
            var project1    = new SonarQubeProject(SharedKey, "");
            var connection2 = new ConnectionInformation(new Uri("http://conn2"));
            var project2    = new SonarQubeProject(SharedKey, "");

            testSubject.SetProjects(connection1, new SonarQubeProject[] { project1 });
            testSubject.SetProjects(connection2, new SonarQubeProject[] { project2 });

            // Case 1: Exists
            // Act+Verify
            testSubject.GetConnectedServer(project1).Should().Be(connection1);
            testSubject.GetConnectedServer(project2).Should().Be(connection2);

            // Case 2: Doesn't exist
            // Act+Verify
            testSubject.GetConnectedServer(new SonarQubeProject(SharedKey, "")).Should().BeNull();
        }
Exemplo n.º 27
0
        public void TestInit()
        {
            this.serviceProvider      = new ConfigurableServiceProvider();
            this.sonarQubeServiceMock = new Mock <ISonarQubeService>();
            this.host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            this.host.SonarQubeService = this.sonarQubeServiceMock.Object;
            this.projectSystemHelper   = new ConfigurableVsProjectSystemHelper(this.serviceProvider);

            this.sonarQubeServiceMock.Setup(x => x.GetAllPluginsAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <SonarQubePlugin>
            {
                new SonarQubePlugin(MinimumSupportedSonarQubePlugin.CSharp.Key, MinimumSupportedSonarQubePlugin.CSharp.MinimumVersion),
                new SonarQubePlugin(MinimumSupportedSonarQubePlugin.VbNet.Key, MinimumSupportedSonarQubePlugin.VbNet.MinimumVersion)
            });
            this.settings = new ConfigurableSonarLintSettings();

            var mefExports = MefTestHelpers.CreateExport <ISonarLintSettings>(settings);
            var mefModel   = ConfigurableComponentModel.CreateWithExports(mefExports);

            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);

            this.filter = new ConfigurableProjectSystemFilter();
            this.serviceProvider.RegisterService(typeof(IProjectSystemFilter), this.filter);

            var outputWindow = new ConfigurableVsOutputWindow();

            this.outputWindowPane = outputWindow.GetOrCreateSonarLintPane();
            this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow);
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper);

            this.credentialStoreMock = new Mock <ICredentialStoreService>();
            this.serviceProvider.RegisterService(typeof(ICredentialStoreService), this.credentialStoreMock.Object);

            this.testProjectRegexSetter = new Mock <ITestProjectRegexSetter>();
            this.serviceProvider.RegisterService(typeof(ITestProjectRegexSetter), testProjectRegexSetter.Object);
        }
        public void StateManager_ClearBoundProject()
        {
            // Setup
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;
            ConfigurableHost host = new ConfigurableHost();
            host.SetActiveSection(section);
            StateManager testSubject = this.CreateTestSubject(host);

            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            testSubject.ManagedState.ConnectedServers.Add(new ServerViewModel(new ConnectionInformation(new Uri("http://zzz1"))));
            testSubject.ManagedState.ConnectedServers.Add(new ServerViewModel(new ConnectionInformation(new Uri("http://zzz2"))));
            testSubject.ManagedState.ConnectedServers.ToList().ForEach(s => s.Projects.Add(new ProjectViewModel(s, new ProjectInformation())));
            var allProjects = testSubject.ManagedState.ConnectedServers.SelectMany(s => s.Projects).ToList();
            testSubject.SetBoundProject(allProjects.First().ProjectInformation);

            // Sanity
            Assert.IsTrue(testSubject.ManagedState.HasBoundProject);

            // Act
            testSubject.ClearBoundProject();

            // Verify
            Assert.IsFalse(testSubject.ManagedState.HasBoundProject);
            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
        }
        public void StateManager_SetBoundProject()
        {
            // Setup
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;
            ConfigurableHost host = new ConfigurableHost();
            host.SetActiveSection(section);
            StateManager testSubject = this.CreateTestSubject(host);

            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            var conn = new ConnectionInformation(new Uri("http://xyz"));
            var projects = new[] { new ProjectInformation(), new ProjectInformation() };
            testSubject.SetProjects(conn, projects);
            TransferableVisualState state = testSubject.ManagedState;
            bool hasBoundProjectChanged = false;
            state.PropertyChanged += (o, e) =>
              {
                  Assert.AreEqual(nameof(state.HasBoundProject), e.PropertyName);
                  hasBoundProjectChanged = true;
              };

            // Act
            testSubject.SetBoundProject(projects[1]);

            // Verify
            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            var serverVM = state.ConnectedServers.Single();
            var project0VM = serverVM.Projects.Single(p => p.ProjectInformation == projects[0]);
            var project1VM = serverVM.Projects.Single(p => p.ProjectInformation == projects[1]);
            Assert.IsTrue(project1VM.IsBound, "Expected to be bound");
            Assert.IsFalse(project0VM.IsBound, "Not expected to be bound");
            Assert.IsTrue(testSubject.ManagedState.HasBoundProject, "Expected a bound project");
            Assert.IsTrue(hasBoundProjectChanged, "HasBoundProject expected to change");
        }
        public void StateManager_IsBusyChanged()
        {
            // Setup
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableHost host = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host);
            testSubject.IsBusyChanged += (s, isBusy) => section.ViewModel.IsBusy = isBusy;

            // Case 1: no active section -> no-op (i.e. no exception)
            testSubject.IsBusy = true;
            Assert.IsTrue(testSubject.ManagedState.IsBusy);
            testSubject.IsBusy = false;
            Assert.IsFalse(testSubject.ManagedState.IsBusy);

            // Case 2: has active section
            host.SetActiveSection(section);

            // Sanity (!IsBusy)
            Assert.IsFalse(section.ViewModel.IsBusy);

            // Act (IsBusy -> IsBusy)
            testSubject.IsBusy = true;

            // Verify
            Assert.IsTrue(section.ViewModel.IsBusy);
            Assert.IsTrue(testSubject.ManagedState.IsBusy);

            // Act (!IsBusy -> !IsBusy)
            testSubject.IsBusy = false;

            // Verify
            Assert.IsFalse(section.ViewModel.IsBusy);
            Assert.IsFalse(testSubject.ManagedState.IsBusy);

            // Dispose (should stop updated the view model)
            testSubject.Dispose();
            testSubject.IsBusy = true;

            // Verify
            Assert.IsFalse(section.ViewModel.IsBusy);
            Assert.IsTrue(testSubject.ManagedState.IsBusy);
        }
        public void StateManager_BindingStateChanged()
        {
            // Setup
            ConfigurableHost host = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host);
            var countOnBindingStateChangeFired = 0;
            testSubject.BindingStateChanged += (sender, e) => countOnBindingStateChangeFired++;

            testSubject.ManagedState.ConnectedServers.Add(new ServerViewModel(new ConnectionInformation(new Uri("http://zzz1"))));
            testSubject.ManagedState.ConnectedServers.ToList().ForEach(s => s.Projects.Add(new ProjectViewModel(s, new ProjectInformation())));
            var allProjects = testSubject.ManagedState.ConnectedServers.SelectMany(s => s.Projects).ToList();

            // Sanity
            Assert.AreEqual(0, countOnBindingStateChangeFired);

            // Act
            testSubject.SetBoundProject(allProjects.First().ProjectInformation);

            // Verify
            Assert.AreEqual(1, countOnBindingStateChangeFired);

            // Act
            testSubject.ClearBoundProject();

            // Verify
            Assert.AreEqual(2, countOnBindingStateChangeFired);
        }
        public void StateManager_IsConnected()
        {
            // Setup
            ConfigurableHost host = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host);

            // Sanity
            Assert.IsFalse(testSubject.IsConnected);

            // Act (connect)
            testSubject.SetProjects(new ConnectionInformation(new Uri("http://qwerty")), new ProjectInformation[0]);

            // Verify
            Assert.IsTrue(testSubject.IsConnected);

            // Act (disconnect)
            testSubject.SetProjects(new ConnectionInformation(new Uri("http://qwerty")), null);

            // Verify
            Assert.IsFalse(testSubject.IsConnected);
        }
 private ProjectSystemFilter CreateTestSubject()
 {
     var host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
     return new ProjectSystemFilter(host);
 }
Exemplo n.º 34
0
        private ProjectSystemFilter CreateTestSubject()
        {
            var host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);

            return(new ProjectSystemFilter(host));
        }
        public void StateManager_SetProjectsUIThread()
        {
            // Setup
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;
            ConfigurableHost host = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host);
            host.VisualStateManager = testSubject;
            section.ViewModel.State = testSubject.ManagedState;
            var connection1 = new ConnectionInformation(new Uri("http://127.0.0.1"));
            var connection2 = new ConnectionInformation(new Uri("http://127.0.0.2"));
            var projects = new[] { new ProjectInformation(), new ProjectInformation() };
            host.SetActiveSection(section);
            ServerViewModel serverVM;

            // Act + Verify
            // Case 1 - not connected to server (indicated by null)
            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            testSubject.SetProjects(connection1, null);

            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            VerifyConnectSectionViewModelIsNotConnected(section.ViewModel, connection1);
            VerifyConnectSectionViewModelIsNotConnected(section.ViewModel, connection2);
            VerifyConnectSectionViewModelHasNoBoundProjects(section.ViewModel);

            // Case 2 - connection1, empty project collection
            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            testSubject.SetProjects(connection1, new ProjectInformation[0]);

            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasNoProjects(section.ViewModel, connection1);
            Assert.IsTrue(serverVM.ShowAllProjects, "Expected show all projects");
            VerifySectionCommands(section, serverVM);
            VerifyConnectSectionViewModelIsNotConnected(section.ViewModel, connection2);
            VerifyConnectSectionViewModelHasNoBoundProjects(section.ViewModel);

            // Case 3 - connection1, non-empty project collection
            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            testSubject.SetProjects(connection1, projects);

            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasProjects(section.ViewModel, connection1, projects);
            VerifySectionCommands(section, serverVM);
            VerifyConnectSectionViewModelIsNotConnected(section.ViewModel, connection2);
            VerifyConnectSectionViewModelHasNoBoundProjects(section.ViewModel);
            Assert.IsTrue(serverVM.ShowAllProjects, "Expected show all projects to be true when adding new projects");

            // Case 4 - connection2, change projects
            testSubject.SetProjects(connection1, projects);
            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            testSubject.SetProjects(connection2, projects);

            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasProjects(section.ViewModel, connection1, projects);
            VerifySectionCommands(section, serverVM);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasProjects(section.ViewModel, connection2, projects);
            VerifySectionCommands(section, serverVM);
            VerifyConnectSectionViewModelHasNoBoundProjects(section.ViewModel);
            Assert.IsTrue(serverVM.ShowAllProjects, "Expected show all projects to be true when changing projects");

            // Case 5 - connection1 & connection2, once detached (connected or not), are reset, changes still being tracked
            host.ClearActiveSection();
            testSubject.SetProjects(connection1, projects);
            testSubject.SetProjects(connection2, projects);
            // Act
            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            host.SetActiveSection(section);
            // Verify
            notifications.AssertNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasProjects(section.ViewModel, connection1, projects);
            VerifySectionCommands(section, serverVM);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasProjects(section.ViewModel, connection2, projects);
            VerifySectionCommands(section, serverVM);
            VerifyConnectSectionViewModelHasNoBoundProjects(section.ViewModel);
        }
        public void StateManager_Dispose()
        {
            // Setup
            ConfigurableHost host = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host);
            var connection1 = new ConnectionInformation(new Uri("http://conn1"));
            testSubject.SetProjects(connection1, new ProjectInformation[0]);

            // Act
            testSubject.Dispose();

            // Verify
            Assert.IsTrue(connection1.IsDisposed, "Leaking connections?");
        }
        public void StateManager_SetProjectsUIThread()
        {
            // Arrange
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;
            ConfigurableHost             host          = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host);

            host.VisualStateManager = testSubject;
            section.ViewModel.State = testSubject.ManagedState;
            var connection1 = new ConnectionInformation(new Uri("http://127.0.0.1"));
            var connection2 = new ConnectionInformation(new Uri("http://127.0.0.2"));
            var projects    = new[] { new SonarQubeProject("", ""), new SonarQubeProject("", "") };

            host.SetActiveSection(section);
            ServerViewModel serverVM;

            // Act + Assert
            // Case 1 - not connected to server (indicated by null)
            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            testSubject.SetProjects(connection1, null);

            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            VerifyConnectSectionViewModelIsNotConnected(section.ViewModel, connection1);
            VerifyConnectSectionViewModelIsNotConnected(section.ViewModel, connection2);
            VerifyConnectSectionViewModelHasNoBoundProjects(section.ViewModel);

            // Case 2 - connection1, empty project collection
            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            testSubject.SetProjects(connection1, new SonarQubeProject[0]);

            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasNoProjects(section.ViewModel, connection1);
            serverVM.ShowAllProjects.Should().BeTrue("Expected show all projects");
            VerifySectionCommands(section, serverVM);
            VerifyConnectSectionViewModelIsNotConnected(section.ViewModel, connection2);
            VerifyConnectSectionViewModelHasNoBoundProjects(section.ViewModel);

            // Case 3 - connection1, non-empty project collection
            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            testSubject.SetProjects(connection1, projects);

            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasProjects(section.ViewModel, connection1, projects);
            VerifySectionCommands(section, serverVM);
            VerifyConnectSectionViewModelIsNotConnected(section.ViewModel, connection2);
            VerifyConnectSectionViewModelHasNoBoundProjects(section.ViewModel);
            serverVM.ShowAllProjects.Should().BeTrue("Expected show all projects to be true when adding new SonarQubeProjects");

            // Case 4 - connection2, change projects
            testSubject.SetProjects(connection1, projects);
            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            testSubject.SetProjects(connection2, projects);

            notifications.AssertNoNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasProjects(section.ViewModel, connection1, projects);
            VerifySectionCommands(section, serverVM);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasProjects(section.ViewModel, connection2, projects);
            VerifySectionCommands(section, serverVM);
            VerifyConnectSectionViewModelHasNoBoundProjects(section.ViewModel);
            serverVM.ShowAllProjects.Should().BeTrue("Expected show all projects to be true when changing projects");

            // Case 5 - connection1 & connection2, once detached (connected or not), are reset, changes still being tracked
            host.ClearActiveSection();
            testSubject.SetProjects(connection1, projects);
            testSubject.SetProjects(connection2, projects);
            // Act
            section.UserNotifications.ShowNotificationError("message", NotificationIds.FailedToFindBoundProjectKeyId, null);
            host.SetActiveSection(section);
            // Assert
            notifications.AssertNotification(NotificationIds.FailedToFindBoundProjectKeyId);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasProjects(section.ViewModel, connection1, projects);
            VerifySectionCommands(section, serverVM);
            serverVM = VerifyConnectSectionViewModelIsConnectedAndHasProjects(section.ViewModel, connection2, projects);
            VerifySectionCommands(section, serverVM);
            VerifyConnectSectionViewModelHasNoBoundProjects(section.ViewModel);
        }
        public void StateManager_GetConnectedServer()
        {
            // Setup
            const string SharedKey = "Key"; // The key is the same for all projects on purpose
            ConfigurableHost host = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host);
            var connection1 = new ConnectionInformation(new Uri("http://conn1"));
            var project1 = new ProjectInformation { Key = SharedKey };
            var connection2 = new ConnectionInformation(new Uri("http://conn2"));
            var project2 = new ProjectInformation { Key = SharedKey };
            testSubject.SetProjects(connection1, new ProjectInformation[] { project1 });
            testSubject.SetProjects(connection2, new ProjectInformation[] { project2 });

            // Case 1: Exists
            // Act+Verify
            Assert.AreEqual(connection1, testSubject.GetConnectedServer(project1));
            Assert.AreEqual(connection2, testSubject.GetConnectedServer(project2));

            // Case 2: Doesn't exist
            // Act+Verify
            Assert.IsNull(testSubject.GetConnectedServer(new ProjectInformation { Key = SharedKey }));
        }
        private StateManager CreateTestSubject(ConfigurableHost host, ConfigurableSectionController section = null)
        {
            var testSubject = new StateManager(host, new TransferableVisualState());

            if (section != null)
            {
                section.ViewModel.State = testSubject.ManagedState;
            }

            return testSubject;
        }
        public void StateManager_ToggleShowAllProjectsCommand_DynamicText()
        {
            // Setup
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableHost host = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host, section);
            var connection1 = new ConnectionInformation(new Uri("http://127.0.0.1"));
            var projects = new ProjectInformation[] { new ProjectInformation(), new ProjectInformation() };
            testSubject.SetProjects(connection1, projects);
            ServerViewModel serverVM = testSubject.ManagedState.ConnectedServers.Single();
            host.SetActiveSection(section);
            testSubject.SyncCommandFromActiveSection();
            ContextualCommandViewModel toggleContextCmd = serverVM.Commands.First(x => x.InternalRealCommand.Equals(section.ToggleShowAllProjectsCommand));

            // Case 1: No bound projects
            serverVM.ShowAllProjects = true;
            // Act + Verify
            Assert.AreEqual(Strings.HideUnboundProjectsCommandText, toggleContextCmd.DisplayText, "Unexpected disabled context command text");

            // Case 2: has bound projects
            serverVM.ShowAllProjects = false;

            // Act + Verify
            Assert.AreEqual(Strings.ShowAllProjectsCommandText, toggleContextCmd.DisplayText, "Unexpected context command text");
        }
        public void StateManager_BindCommand_DynamicText()
        {
            // Setup
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableHost host = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host, section);
            var connection1 = new ConnectionInformation(new Uri("http://127.0.0.1"));
            var projects = new ProjectInformation[] { new ProjectInformation() };
            testSubject.SetProjects(connection1, projects);
            ProjectViewModel projectVM = testSubject.ManagedState.ConnectedServers.Single().Projects.Single();
            host.SetActiveSection(section);
            testSubject.SyncCommandFromActiveSection();
            ContextualCommandViewModel bindCmd = projectVM.Commands.First(x => x.InternalRealCommand.Equals(section.BindCommand));

            // Case 1: Bound
            projectVM.IsBound = true;
            // Act + Verify
            Assert.AreEqual(Strings.SyncButtonText, bindCmd.DisplayText, "Unexpected disabled context command text");

            // Case 2: Not bound
            projectVM.IsBound = false;

            // Act + Verify
            Assert.AreEqual(Strings.BindButtonText, bindCmd.DisplayText, "Unexpected context command text");
        }
        public void StateManager_GetConnectedServers()
        {
            // Setup
            ConfigurableHost host = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host);
            var connection1 = new ConnectionInformation(new Uri("http://conn1"));
            var connection2 = new ConnectionInformation(new Uri("http://conn2"));

            // Sanity
            Assert.IsFalse(testSubject.GetConnectedServers().Any());

            // Act (connect)
            testSubject.SetProjects(connection1, new ProjectInformation[0]);

            // Verify
            CollectionAssert.AreEquivalent(new[] { connection1 } , testSubject.GetConnectedServers().ToArray());

            // Act (connect another one)
            testSubject.SetProjects(connection2, new ProjectInformation[0]);

            // Verify
            CollectionAssert.AreEquivalent(new[] { connection1, connection2 }, testSubject.GetConnectedServers().ToArray());

            // Act (disconnect)
            testSubject.SetProjects(connection1, null);
            testSubject.SetProjects(connection2, null);

            // Verify
            Assert.IsFalse(testSubject.GetConnectedServers().Any());
            Assert.IsTrue(connection1.IsDisposed, "Leaking connections?");
            Assert.IsTrue(connection2.IsDisposed, "Leaking connections?");
        }
        public void StateManager_SyncCommandFromActiveSection()
        {
            // Setup
            var section = ConfigurableSectionController.CreateDefault();
            ConfigurableHost host = new ConfigurableHost();
            StateManager testSubject = this.CreateTestSubject(host, section);
            var connection1 = new ConnectionInformation(new Uri("http://127.0.0.1"));
            var projects = new ProjectInformation[] { new ProjectInformation(), new ProjectInformation() };
            testSubject.SetProjects(connection1, projects);
            ServerViewModel serverVM = testSubject.ManagedState.ConnectedServers.Single();

            // Case 1: has active section
            host.SetActiveSection(section);

            // Act
            testSubject.SyncCommandFromActiveSection();
            VerifySectionCommands(section, serverVM);

            // Case 2: has no active section
            host.ClearActiveSection();

            // Act
            testSubject.SyncCommandFromActiveSection();
            VerifyNoCommands(serverVM);

            // Case 3: re-active
            host.SetActiveSection(section);

            // Act
            testSubject.SyncCommandFromActiveSection();
            VerifySectionCommands(section, serverVM);
        }
        public void SonarAnalyzerManager_Triggers_SolutionBindingChanged_ReanalyzeSolution()
        {
            ConfigurableHost host = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            Export mefExport1 = MefTestHelpers.CreateExport<IHost>(host);

            ConfigurableActiveSolutionBoundTracker activeSolutionBoundTracker = new ConfigurableActiveSolutionBoundTracker();
            Export mefExport2 = MefTestHelpers.CreateExport<IActiveSolutionBoundTracker>(activeSolutionBoundTracker);

            IComponentModel mefModel = ConfigurableComponentModel.CreateWithExports(mefExport1, mefExport2);
            this.serviceProvider.RegisterService(typeof(SComponentModel), mefModel);

            ConfigurableSolutionAnalysisRequester solutionAnalysisRequester = new ConfigurableSolutionAnalysisRequester();

            using (new SonarAnalyzerManager(this.serviceProvider, new AdhocWorkspace(), solutionAnalysisRequester))
            {
                // Sanity
                Assert.AreEqual(0, solutionAnalysisRequester.ReanalyzeSolutionCallCount);

                // Act
                activeSolutionBoundTracker.SimulateSolutionBindingChanged(true);

                // Verify
                Assert.AreEqual(1, solutionAnalysisRequester.ReanalyzeSolutionCallCount);
            }
        }