Beispiel #1
0
        public void TestInit()
        {
            KnownUIContextsAccessor.Reset();
            this.serviceProvider = new ConfigurableServiceProvider();

            this.teamExplorerController = new ConfigurableTeamExplorerController();
            this.infoBarManager         = new ConfigurableInfoBarManager();

            IComponentModel componentModel = ConfigurableComponentModel.CreateWithExports(
                new Export[]
            {
                MefTestHelpers.CreateExport <ITeamExplorerController>(this.teamExplorerController),
                MefTestHelpers.CreateExport <IInfoBarManager>(this.infoBarManager),
            });

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

            this.unboundProjectFinder = new ConfigurableUnboundProjectFinder();

            var outputWindow = new ConfigurableVsOutputWindow();

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

            this.configProvider = new ConfigurableConfigurationProvider {
                FolderPathToReturn = "c:\\test"
            };

            this.serviceProvider.RegisterService(typeof(IConfigurationProviderService), this.configProvider);

            this.host         = new ConfigurableHost(this.serviceProvider, Dispatcher.CurrentDispatcher);
            this.stateManager = (ConfigurableStateManager)this.host.VisualStateManager;
        }
        public void InitializeSolutionBinding_Update_AllUpToDate_NoProjectsUpdated()
        {
            // Arrange
            var allProjects = new Project[]
            {
                new ProjectMock("cs1.csproj"),
                new ProjectMock("cs2.csproj"),
                new ProjectMock("cs3.csproj"),
                new ProjectMock("cs4.csproj")
            };

            var logger = new TestLogger();
            var finder = new ConfigurableUnboundProjectFinder
            {
                UnboundProjects = null
            };

            // Act
            var result = BindingProcessImpl.GetProjectsForRulesetBinding(false, allProjects, finder, logger);

            // Assert
            result.Should().BeEmpty();
            logger.AssertOutputStringExists(Strings.Bind_Ruleset_SomeProjectsDoNotNeedToBeUpdated);
            logger.AssertPartialOutputStringExists("cs1.csproj", "cs2.csproj", "cs3.csproj", "cs4.csproj");
        }
        public void Ctor_ArgChecks()
        {
            var validHost             = new ConfigurableHost();
            var bindingArgs           = new BindCommandArgs("key", "name", new ConnectionInformation(new Uri("http://server")));
            var slnBindOp             = new Mock <ISolutionBindingOperation>().Object;
            var nuGetOp               = new Mock <INuGetBindingOperation>().Object;
            var finder                = new ConfigurableUnboundProjectFinder();
            var bindingConfigProvider = new Mock <IBindingConfigProvider>().Object;

            // 1. Null host
            Action act = () => new BindingProcessImpl(null, bindingArgs, slnBindOp, nuGetOp, finder, bindingConfigProvider, SonarLintMode.Connected);

            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("host");

            // 2. Null binding args
            act = () => new BindingProcessImpl(validHost, null, slnBindOp, nuGetOp, finder, bindingConfigProvider, SonarLintMode.Connected);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("bindingArgs");

            // 3. Null solution binding operation
            act = () => new BindingProcessImpl(validHost, bindingArgs, null, nuGetOp, finder, bindingConfigProvider, SonarLintMode.Connected);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("solutionBindingOperation");

            // 4. Null NuGet operation
            act = () => new BindingProcessImpl(validHost, bindingArgs, slnBindOp, null, finder, bindingConfigProvider, SonarLintMode.Connected);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("nugetBindingOperation");

            // 5. Null binding info provider
            act = () => new BindingProcessImpl(validHost, bindingArgs, slnBindOp, nuGetOp, null, bindingConfigProvider, SonarLintMode.Connected);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("unboundProjectFinder");

            // 6. Null rules configuration provider
            act = () => new BindingProcessImpl(validHost, bindingArgs, slnBindOp, nuGetOp, finder, null, SonarLintMode.Connected);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("bindingConfigProvider");
        }
        public void InitializeSolutionBinding_Update_NotAllUpToDate_SomeProjectsUpdated()
        {
            // Arrange
            var allProjects = new Project[]
            {
                new ProjectMock("csA.csproj"),
                new ProjectMock("csB.csproj"),
                new ProjectMock("csC.csproj"),
                new ProjectMock("csD.csproj")
            };

            var unboundProjects = new Project[]
            {
                new ProjectMock("XXX.csproj"),
                allProjects[1],
                allProjects[3]
            };

            var logger = new TestLogger();
            var finder = new ConfigurableUnboundProjectFinder
            {
                UnboundProjects = unboundProjects
            };

            // Act
            var result = BindingProcessImpl.GetProjectsForRulesetBinding(false, allProjects, finder, logger);

            // Assert
            result.Should().BeEquivalentTo(allProjects[1], allProjects[3]);
            logger.AssertOutputStringExists(Strings.Bind_Ruleset_SomeProjectsDoNotNeedToBeUpdated);
            logger.AssertPartialOutputStringExists("csA.csproj", "csC.csproj");
        }
        private BindingProcessImpl CreateTestSubject(string projectKey = "anykey", string projectName = "anyname",
                                                     INuGetBindingOperation nuGetBindingOperation = null,
                                                     IBindingConfigProvider configProvider        = null)
        {
            nuGetBindingOperation = nuGetBindingOperation ?? new NoOpNuGetBindingOperation(this.host.Logger);
            configProvider        = configProvider ?? new Mock <IBindingConfigProvider>().Object;

            this.host.SonarQubeService = this.sonarQubeServiceMock.Object;
            var bindingArgs = new BindCommandArgs(projectKey, projectName, new ConnectionInformation(new Uri("http://connected")));

            var slnBindOperation = new SolutionBindingOperation(this.host, bindingArgs.Connection, projectKey, "projectName", SonarLintMode.LegacyConnected, this.host.Logger);
            var finder           = new ConfigurableUnboundProjectFinder();

            return(new BindingProcessImpl(this.host, bindingArgs, slnBindOperation, nuGetBindingOperation, finder, configProvider));
        }
        private BindingProcessImpl CreateTestSubject(BindCommandArgs bindingArgs = null,
                                                     INuGetBindingOperation nuGetBindingOperation = null,
                                                     IBindingConfigProvider configProvider        = null,
                                                     SonarLintMode mode = SonarLintMode.Connected)
        {
            bindingArgs           = bindingArgs ?? new BindCommandArgs("key", "name", new ConnectionInformation(new Uri("http://connected")));
            nuGetBindingOperation = nuGetBindingOperation ?? new NoOpNuGetBindingOperation(this.host.Logger);
            configProvider        = configProvider ?? new Mock <IBindingConfigProvider>().Object;

            this.host.SonarQubeService = this.sonarQubeServiceMock.Object;

            var slnBindOperation = new SolutionBindingOperation(this.host, SonarLintMode.LegacyConnected, this.host.Logger);
            var finder           = new ConfigurableUnboundProjectFinder();

            return(new BindingProcessImpl(this.host, bindingArgs, slnBindOperation, nuGetBindingOperation, finder, configProvider, mode));
        }
        public void GetProjectsForRulesetBinding_NoProjectsUpToDate()
        {
            // Arrange
            var allProjects = new Project[]
            {
                new ProjectMock("cs1.csproj"),
                new ProjectMock("cs2.csproj"),
                new ProjectMock("cs3.csproj")
            };

            var logger = new TestLogger();
            var finder = new ConfigurableUnboundProjectFinder
            {
                UnboundProjects = allProjects
            };

            // Act
            var result = BindingProcessImpl.GetProjectsForRulesetBinding(false, allProjects, finder, logger);

            // Assert
            result.Should().BeEquivalentTo(allProjects);
            logger.AssertOutputStringExists(Strings.Bind_Ruleset_AllProjectsNeedToBeUpdated);
        }
        public void InstallPackages_Succeeds_SuccessPropertyIsFalse()
        {
            // Arrange
            var bindingArgs = new BindCommandArgs("projectKey", "projectName", new ConnectionInformation(new Uri("http://connected")));

            var slnBindOpMock = new Mock <ISolutionBindingOperation>();
            var nugetMock     = new Mock <INuGetBindingOperation>();

            nugetMock.Setup(x => x.InstallPackages(It.IsAny <ISet <Project> >(),
                                                   It.IsAny <IProgress <FixedStepsProgress> >(),
                                                   It.IsAny <CancellationToken>())).Returns(false);
            var finder         = new ConfigurableUnboundProjectFinder();
            var configProvider = new Mock <IBindingConfigProvider>();

            var testSubject = new BindingProcessImpl(this.host, bindingArgs, slnBindOpMock.Object, nugetMock.Object, finder, configProvider.Object, SonarLintMode.Connected);

            ProjectMock project1 = new ProjectMock("project1")
            {
                ProjectKind = ProjectSystemHelper.CSharpProjectKind
            };

            testSubject.InternalState.BindingProjects.Clear();
            testSubject.InternalState.BindingProjects.Add(project1);

            var progressEvents  = new ConfigurableProgressStepExecutionEvents();
            var progressAdapter = new FixedStepsProgressAdapter(progressEvents);
            var cts             = new CancellationTokenSource();

            testSubject.InternalState.BindingOperationSucceeded = true;

            // Act
            testSubject.InstallPackages(progressAdapter, cts.Token);

            // Assert
            testSubject.InternalState.BindingOperationSucceeded.Should().BeFalse();
        }