internal static /* for testing purposes */ IBindingProcess CreateBindingProcess(IHost host, BindCommandArgs bindingArgs)
        {
            // Choose the type of binding
            var configProvider = host.GetService <IConfigurationProvider>();

            configProvider.AssertLocalServiceIsNotNull();

            var currentConfiguration = configProvider.GetConfiguration();

            SonarLintMode          modeToBind;
            INuGetBindingOperation nugetBindingOp;

            // If we are currently in standalone then the project is being bound for the first time.
            // Otherwise, we are updating an existing binding
            var isFirstBinding = currentConfiguration.Mode == SonarLintMode.Standalone;

            if (currentConfiguration.Mode == SonarLintMode.LegacyConnected)
            {
                host.Logger.WriteLine(Strings.Bind_UpdatingLegacyBinding);
                modeToBind     = SonarLintMode.LegacyConnected;
                nugetBindingOp = new NuGetBindingOperation(host, host.Logger);
            }
            else
            {
                host.Logger.WriteLine(
                    isFirstBinding ?
                    Strings.Bind_FirstTimeBinding :
                    Strings.Bind_UpdatingNewStyleBinding);

                modeToBind     = SonarLintMode.Connected;
                nugetBindingOp = new NoOpNuGetBindingOperation(host.Logger);
            }

            var solutionBindingOp = new SolutionBindingOperation(
                host,
                bindingArgs.Connection,
                bindingArgs.ProjectKey,
                bindingArgs.ProjectName,
                modeToBind,
                host.Logger);

            var unboundProjectFinder = new UnboundProjectFinder(host);

            var dotNetConfigProvider = new DotNetBindingConfigProvider(host.SonarQubeService, nugetBindingOp,
                                                                       bindingArgs.Connection.ServerUri.ToString(), bindingArgs.ProjectName,
                                                                       host.Logger);

            var cppConfigProvider  = new CFamilyBindingConfigProvider(host.SonarQubeService, host.Logger);
            var ruleConfigProvider = new CompositeBindingConfigProvider(dotNetConfigProvider, cppConfigProvider);

            var bindingProcess = new BindingProcessImpl(host, bindingArgs, solutionBindingOp, nugetBindingOp, unboundProjectFinder, ruleConfigProvider, isFirstBinding);

            return(bindingProcess);
        }
Ejemplo n.º 2
0
        public void GetConfiguration_NoMatchingProvider_Throws()
        {
            // Arrange
            var otherProvider = new DummyProvider(Language.VBNET);
            var qp            = new SonarQubeQualityProfile("key", "name", "language", false, DateTime.UtcNow);

            var testSubject = new CompositeBindingConfigProvider(otherProvider);

            // 1. Multiple matching providers -> config from the first matching provider returned
            Action act = () => testSubject.GetConfigurationAsync(qp, "org", Language.Cpp, CancellationToken.None).Wait();

            act.Should().ThrowExactly <AggregateException>().And.InnerException.Should().BeOfType <ArgumentOutOfRangeException>();
        }
Ejemplo n.º 3
0
        public void Ctor_ValidArgs()
        {
            // Arrange
            var providerMock1 = new Mock <IBindingConfigProvider>();
            var providerMock2 = new Mock <IBindingConfigProvider>();

            // Act
            var testSubject = new CompositeBindingConfigProvider(
                providerMock1.Object,
                providerMock2.Object, providerMock2.Object); // duplicate should be ignored

            // Assert
            testSubject.Providers.Count().Should().Be(2);
            testSubject.Providers.Should().BeEquivalentTo(providerMock1.Object, providerMock2.Object);
        }
Ejemplo n.º 4
0
        public async Task GetConfiguration_WithMatchingProvider_ExpectedConfigReturned()
        {
            // Arrange
            var otherProvider = new DummyProvider(Language.VBNET);
            var cppProvider1  = new DummyProvider(Language.Cpp);
            var cppProvider2  = new DummyProvider(Language.Cpp);

            var qp = new SonarQubeQualityProfile("key", "name", "language", false, DateTime.UtcNow);

            var testSubject = new CompositeBindingConfigProvider(otherProvider, cppProvider1, cppProvider2);

            // Act. Multiple matching providers -> config from the first matching provider returned
            var actualConfig = await testSubject.GetConfigurationAsync(qp, "org", Language.Cpp, CancellationToken.None);

            actualConfig.Should().Be(cppProvider1.ConfigToReturn);
        }
Ejemplo n.º 5
0
        public void IsSupported_ReturnsTrueIfSupportedByAny()
        {
            // Arrange
            var p1 = new DummyProvider(Language.C);
            var p2 = new DummyProvider(Language.VBNET);
            var p3 = new DummyProvider(Language.CSharp);

            var testSubject = new CompositeBindingConfigProvider(p1, p2, p3);

            // 1. Supported languages
            testSubject.IsLanguageSupported(Language.C).Should().BeTrue();
            testSubject.IsLanguageSupported(Language.VBNET).Should().BeTrue();
            testSubject.IsLanguageSupported(Language.CSharp).Should().BeTrue();

            // 2. Unsupported langauge
            testSubject.IsLanguageSupported(Language.Cpp).Should().BeFalse();
        }