Esempio n. 1
0
        public void IsBindingRequired_ProjectHasTwoLanguages_ReturnsIfAllLanguagesHaveConfigFiles(bool isFirstLanguageBound, bool isSecondLanguageBound, bool expectedResult)
        {
            var projectMock = new ProjectMock("c:\\test.csproj");

            projectMock.SetProjectKind(new Guid(ProjectSystemHelper.CppProjectKind));

            var bindingConfiguration = new BindingConfiguration(new BoundSonarQubeProject(new Uri("http://test.com"), "key", "name"),
                                                                SonarLintMode.Connected, "c:\\");

            var cppFilePath = bindingConfiguration.BuildPathUnderConfigDirectory(Language.Cpp.FileSuffixAndExtension);
            var cFilePath   = bindingConfiguration.BuildPathUnderConfigDirectory(Language.C.FileSuffixAndExtension);

            fileSystemMock
            .Setup(x => x.File.Exists(cppFilePath))
            .Returns(isFirstLanguageBound);

            if (isFirstLanguageBound)
            {
                fileSystemMock
                .Setup(x => x.File.Exists(cFilePath))
                .Returns(isSecondLanguageBound);
            }

            var result = testSubject.IsBindingRequired(bindingConfiguration, projectMock);

            result.Should().Be(expectedResult);

            fileSystemMock.VerifyAll();
        }
Esempio n. 2
0
        public void Equals_NonNullOrg_AreEqual()
        {
            // Arrange
            var projectAAA1 = new BoundSonarQubeProject(new Uri("http://localhost"), "projectAAA", "projectName",
                                                        organization: new SonarQubeOrganization("org1", "111"));
            var projectAAA2 = new BoundSonarQubeProject(new Uri("http://localhost"), "projectAAA", "projectName",
                                                        organization: new SonarQubeOrganization("org1", "222222222222222"));
            var projectAAA3 = new BoundSonarQubeProject(new Uri("http://localhost"), "projectAAA", "projectName",
                                                        organization: new SonarQubeOrganization("org1", "333333333333333333"));

            var config1 = BindingConfiguration.CreateBoundConfiguration(projectAAA1, SonarLintMode.Connected);
            var config2 = BindingConfiguration.CreateBoundConfiguration(projectAAA2, SonarLintMode.Connected);
            var config3 = BindingConfiguration.CreateBoundConfiguration(projectAAA3, SonarLintMode.Connected);

            // Act & Assert
            // Reflexive
            CheckAreEqual(config1, config1);
            CheckAreEqual(config2, config2);

            // Transitive
            CheckAreEqual(config1, config2);
            CheckAreEqual(config2, config3);
            CheckAreEqual(config3, config1);

            // Symmetric
            CheckAreEqual(config2, config3);
            CheckAreEqual(config3, config2);
        }
        private void CurrentErrorWindowInfoBar_ButtonClick(object sender, EventArgs e)
        {
            if (this.currentErrorWindowInfoBarHandlingClick)
            {
                // Info bar doesn't expose a way to disable the command
                // and since the code is asynchronous the user can click
                // on the button multiple times and get multiple binds
                return;
            }

            BindingConfiguration binding = configProvider.GetConfiguration();

            if (binding == null ||
                !binding.Mode.IsInAConnectedMode() ||
                this.infoBarBinding == null ||
                binding.Project.ServerUri != this.infoBarBinding.ServerUri ||
                !SonarQubeProject.KeyComparer.Equals(binding.Project.ProjectKey, this.infoBarBinding.ProjectKey))
            {
                // Not bound anymore, or bound to something else entirely
                this.ClearCurrentInfoBar();
                this.OutputMessage(Strings.SonarLintInfoBarUpdateCommandInvalidSolutionBindings);
            }
            else
            {
                // Prevent click handling
                this.currentErrorWindowInfoBarHandlingClick = true;
                this.ExecuteUpdate(binding.Project);
            }
        }
Esempio n. 4
0
        private static void CheckAreEqual(BindingConfiguration left, BindingConfiguration right)
        {
            left.Equals(right).Should().BeTrue();         // strongly-typed Equals
            left.Equals((object)right).Should().BeTrue(); // untyped Equals

            left.GetHashCode().Should().Be(right.GetHashCode());
        }
        public static TelemetryPayload CreatePayload(TelemetryData telemetryData, DateTimeOffset now,
                                                     BindingConfiguration bindingConfiguration)
        {
            if (telemetryData == null)
            {
                throw new ArgumentNullException(nameof(telemetryData));
            }

            if (bindingConfiguration == null)
            {
                throw new ArgumentNullException(nameof(bindingConfiguration));
            }

            var isConnected  = bindingConfiguration?.Mode != NewConnectedMode.SonarLintMode.Standalone;
            var isSonarCloud = IsSonarCloud(bindingConfiguration?.Project?.ServerUri);

            return(new TelemetryPayload
            {
                SonarLintProduct = "SonarLint Visual Studio",
                SonarLintVersion = SonarLintVersion,
                VisualStudioVersion = VisualStudioHelpers.VisualStudioVersion,
                NumberOfDaysSinceInstallation = now.DaysPassedSince(telemetryData.InstallationDate),
                NumberOfDaysOfUse = telemetryData.NumberOfDaysOfUse,
                IsUsingConnectedMode = isConnected,
                IsUsingSonarCloud = isSonarCloud,
                SystemDate = now,
                InstallDate = telemetryData.InstallationDate,
            });
        }
Esempio n. 6
0
        public void Equals_NullOrg_AreEqual()
        {
            // Arrange
            var projectAAA1 = new BoundSonarQubeProject(new Uri("http://localhost"), "projectAAA", "projectName", organization: null);
            var projectAAA2 = new BoundSonarQubeProject(new Uri("http://localhost"), "projectAAA", "projectName", organization: null);
            var projectAAA3 = new BoundSonarQubeProject(new Uri("http://localhost"), "projectAAA", "projectName", organization: null);

            var config1 = BindingConfiguration.CreateBoundConfiguration(projectAAA1, isLegacy: true);
            var config2 = BindingConfiguration.CreateBoundConfiguration(projectAAA2, isLegacy: true);
            var config3 = BindingConfiguration.CreateBoundConfiguration(projectAAA3, isLegacy: true);

            // Action & Assert
            // Reflexive
            CheckAreEqual(config1, config2);
            CheckAreEqual(config2, config1);

            // Transitive
            CheckAreEqual(config1, config2);
            CheckAreEqual(config2, config3);
            CheckAreEqual(config3, config1);

            // Symmetric
            CheckAreEqual(config2, config3);
            CheckAreEqual(config3, config2);
        }
        public BindingImplementationNonGeneric To(Type implementationType)
        {
            var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateTypeBasedImplementationConfiguration(BindingConfiguration.ServiceType, implementationType);

            BindingConfiguration.AddImplementation(bindingImplementationConfiguration);
            return(new BindingImplementationNonGeneric(ServiceRegistrationBuilder, bindingImplementationConfiguration, this));
        }
Esempio n. 8
0
        public async Task GetRules_NoData_EmptyResultReturned()
        {
            // Arrange
            var testLogger  = new TestLogger();
            var serviceMock = new Mock <ISonarQubeService>();

            serviceMock.Setup(x => x.GetRulesAsync(It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => new List <SonarQubeRule>());

            var bindingConfiguration = new BindingConfiguration(new BoundSonarQubeProject {
                ProjectKey = "test"
            }, SonarLintMode.Connected, "c:\\");

            var testSubject = new CFamilyBindingConfigProvider(serviceMock.Object, testLogger);

            // Act
            var result = await testSubject.GetConfigurationAsync(CreateQp(), Language.Cpp, bindingConfiguration, CancellationToken.None);

            // Assert
            result.Should().NotBeNull();
            result.Should().BeOfType <CFamilyBindingConfig>();

            var cfamilyConfigFile = (CFamilyBindingConfig)result;

            cfamilyConfigFile.RuleSettings.Should().NotBeNull();
            cfamilyConfigFile.RuleSettings.Rules.Should().NotBeNull();
            cfamilyConfigFile.RuleSettings.Rules.Count.Should().Be(0);

            testLogger.AssertNoOutputMessages();
        }
        private void CurrentErrorWindowInfoBar_ButtonClick(object sender, EventArgs e)
        {
            if (this.currentErrorWindowInfoBarHandlingClick)
            {
                // Info bar doesn't expose a way to disable the command
                // and since the code is asynchronous the user can click
                // on the button multiple times and get multiple binds
                return;
            }

            // Don't log unprocessed events
            var componentModel = host.GetService <SComponentModel, IComponentModel>();

            TelemetryLoggerAccessor.GetLogger(componentModel)?.ReportEvent(TelemetryEvent.ErrorListInfoBarUpdateCalled);

            BindingConfiguration binding = configProvider.GetConfiguration();

            if (binding == null ||
                binding.Mode != SonarLintMode.LegacyConnected ||
                this.infoBarBinding == null ||
                binding.Project.ServerUri != this.infoBarBinding.ServerUri ||
                !SonarQubeProject.KeyComparer.Equals(binding.Project.ProjectKey, this.infoBarBinding.ProjectKey))
            {
                // Not bound anymore, or bound to something else entirely
                this.ClearCurrentInfoBar();
                this.OutputMessage(Strings.SonarLintInfoBarUpdateCommandInvalidSolutionBindings);
            }
            else
            {
                // Prevent click handling
                this.currentErrorWindowInfoBarHandlingClick = true;
                this.ExecuteUpdate(binding.Project);
            }
        }
Esempio n. 10
0
        public void Bind(Type fromType, Type toType, BindingConfiguration configuration = null)
        {
            var bindingSetup = _container.Bind(fromType);

            if (configuration == null)
            {
                bindingSetup.To(toType).AsSingle();
                return;
            }

            if (!string.IsNullOrEmpty(configuration.WithName))
            {
                bindingSetup.WithId(configuration.WithName);
            }

            ScopeConcreteIdArgConditionCopyNonLazyBinder binding;

            if (configuration.ToInstance != null)
            {
                binding = bindingSetup.FromInstance(configuration.ToInstance);
            }
            else if (configuration.ToMethod != null)
            {
                binding = bindingSetup.FromMethodUntyped(x => configuration.ToMethod(this));
            }
            else
            {
                binding = bindingSetup.To(toType);

                if (configuration.WithNamedConstructorArgs.Count > 0)
                {
                    binding.WithArguments(configuration.WithNamedConstructorArgs.Values);
                }

                if (configuration.WithTypedConstructorArgs.Count > 0)
                {
                    var typePairs = configuration.WithTypedConstructorArgs.Select(x => new TypeValuePair(x.Key, x.Value));
                    binding.WithArgumentsExplicit(typePairs);
                }
            }

            if (configuration.AsSingleton)
            {
                binding.AsSingle();
            }
            else
            {
                binding.AsTransient();
            }

            if (configuration.OnActivation != null)
            {
                binding.OnInstantiated((context, instance) => { configuration.OnActivation(this, instance); });
            }

            if (configuration.WhenInjectedInto != null && configuration.WhenInjectedInto.Count > 0)
            {
                binding.WhenInjectedInto(configuration.WhenInjectedInto.ToArray());
            }
        }
        private bool IsFullyBoundProject(ISolutionRuleSetsInformationProvider ruleSetInfoProvider, IRuleSetSerializer ruleSetSerializer,
                                         BindingConfiguration binding, Project project)
        {
            var languages = ProjectToLanguageMapper.GetAllBindingLanguagesForProject(project);

            return(languages.All(l => IsFullyBoundProject(ruleSetInfoProvider, ruleSetSerializer, binding, project, l)));
        }
        private IEnumerable <Project> GetUnboundProjects(BindingConfiguration binding)
        {
            Debug.Assert(binding.Mode.IsInAConnectedMode());
            Debug.Assert(binding.Project != null);

            var projectSystem = this.serviceProvider.GetService <IProjectSystemHelper>();

            projectSystem.AssertLocalServiceIsNotNull();

            var rulesetSerializer = this.serviceProvider.GetService <IRuleSetSerializer>();

            rulesetSerializer.AssertLocalServiceIsNotNull();

            // Projects will be using the same solution ruleset in most of the cases,
            // projects could have multiple configurations all of which using the same rule set,
            // we want to minimize the number of disk operations since the
            // method can be called from the UI thread, hence this short-lived cache
            var cachingSerializer = new CachingRulesetSerializer(rulesetSerializer);

            // Note: we will still may end up analyzing the same project rule set
            // but that should in marginal since it will be already loaded into memory

            // Reuse the binding information passed in to avoid reading it more than once
            return(projectSystem.GetFilteredSolutionProjects()
                   .Where(p => !IsFullyBoundProject(ruleSetInfoProvider, cachingSerializer, binding, p))
                   .ToArray());
        }
Esempio n. 13
0
        /// <summary>
        /// Will bend add/edit the binding information for next time usage
        /// </summary>
        private void PendBindingInformation(ConnectionInformation connInfo)
        {
            Debug.Assert(this.qualityProfileMap != null, "Initialize was expected to be called first");

            var bindingSerializer = this.serviceProvider.GetService <IConfigurationProvider>();

            bindingSerializer.AssertLocalServiceIsNotNull();

            BasicAuthCredentials credentials = connection.UserName == null ? null : new BasicAuthCredentials(connInfo.UserName, connInfo.Password);

            Dictionary <Language, ApplicableQualityProfile> map = new Dictionary <Language, ApplicableQualityProfile>();

            foreach (var keyValue in this.qualityProfileMap)
            {
                map[keyValue.Key] = new ApplicableQualityProfile
                {
                    ProfileKey       = keyValue.Value.Key,
                    ProfileTimestamp = keyValue.Value.TimeStamp
                };
            }

            var bound = new BoundSonarQubeProject(connInfo.ServerUri, this.ProjectKey, credentials,
                                                  connInfo.Organization);

            bound.Profiles = map;

            var config = new BindingConfiguration(bound, this.bindingMode);

            bindingSerializer.WriteConfiguration(config);
        }
        public ActiveSolutionBoundTracker(IHost host, IActiveSolutionTracker activeSolutionTracker, ILogger logger)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }
            if (activeSolutionTracker == null)
            {
                throw new ArgumentNullException(nameof(activeSolutionTracker));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            this.extensionHost   = host;
            this.solutionTracker = activeSolutionTracker;
            this.logger          = logger;

            this.configurationProvider = this.extensionHost.GetService <IConfigurationProvider>();
            this.configurationProvider.AssertLocalServiceIsNotNull();

            this.errorListInfoBarController = this.extensionHost.GetService <IErrorListInfoBarController>();
            this.errorListInfoBarController.AssertLocalServiceIsNotNull();

            // The user changed the binding through the Team Explorer
            this.extensionHost.VisualStateManager.BindingStateChanged += this.OnBindingStateChanged;

            // The solution changed inside the IDE
            this.solutionTracker.ActiveSolutionChanged += this.OnActiveSolutionChanged;

            CurrentConfiguration = this.configurationProvider.GetConfiguration();
        }
        /// <summary>
        /// This will bind any ISystem implementations that are found within the assembly provided
        /// </summary>
        /// <remarks>
        /// This can save you time but is not advised in most cases
        /// </remarks>
        /// <param name="application">The application to act on</param>
        /// <param name="assemblies">The assemblies to scan for systems</param>
        public static void BindAllSystemsInAssemblies(this IEcsRxApplication application, params Assembly[] assemblies)
        {
            var systemType = typeof(ISystem);

            var applicableSystems = assemblies.SelectMany(x => x.GetTypes())
                                    .Where(x =>
            {
                if (x.IsInterface || x.IsAbstract)
                {
                    return(false);
                }

                return(systemType.IsAssignableFrom(x));
            })
                                    .ToList();

            if (!applicableSystems.Any())
            {
                return;
            }

            foreach (var applicableSystemType in applicableSystems)
            {
                var bindingConfiguration = new BindingConfiguration
                {
                    AsSingleton = true,
                    WithName    = applicableSystemType.Name
                };

                application.Container.Bind(systemType, applicableSystemType, bindingConfiguration);
            }
        }
        public ActiveSolutionBoundTracker(IHost host, IActiveSolutionTracker activeSolutionTracker, ILogger logger)
        {
            extensionHost   = host ?? throw new ArgumentNullException(nameof(host));
            solutionTracker = activeSolutionTracker ?? throw new ArgumentNullException(nameof(activeSolutionTracker));
            this.logger     = logger ?? throw new ArgumentNullException(nameof(logger));

            vsMonitorSelection = host.GetService <SVsShellMonitorSelection, IVsMonitorSelection>();
            vsMonitorSelection.GetCmdUIContextCookie(ref BoundSolutionUIContext.Guid, out boundSolutionContextCookie);

            configurationProvider = extensionHost.GetService <IConfigurationProviderService>();
            configurationProvider.AssertLocalServiceIsNotNull();

            errorListInfoBarController = extensionHost.GetService <IErrorListInfoBarController>();
            errorListInfoBarController.AssertLocalServiceIsNotNull();

            // The user changed the binding through the Team Explorer
            extensionHost.VisualStateManager.BindingStateChanged += OnBindingStateChanged;

            // The solution changed inside the IDE
            solutionTracker.ActiveSolutionChanged += OnActiveSolutionChanged;

            CurrentConfiguration = configurationProvider.GetConfiguration();

            SetBoundSolutionUIContext();
        }
        private void RefreshWorkflow(BindingConfiguration configuration)
        {
            // There might be some race condition here if an analysis is triggered while the delegates are reset and set back
            // to the new workflow behavior. This race condition would lead to some issues being reported using the old mode
            // instead of the new one but everything will be fixed on the next analysis.
            ResetState();

            switch (configuration?.Mode)
            {
            case SonarLintMode.Standalone:
                this.logger.WriteLine(Resources.Strings.AnalyzerManager_InStandaloneMode);
                this.currentWorklow = new SonarAnalyzerStandaloneWorkflow(this.workspace);
                break;

            case SonarLintMode.LegacyConnected:
            case SonarLintMode.Connected:
                this.logger.WriteLine(Resources.Strings.AnalyzerManager_InConnectedMode);
                var sonarQubeIssueProvider = new SonarQubeIssuesProvider(sonarQubeService, configuration.Project.ProjectKey,
                                                                         new TimerFactory(), this.logger);
                this.disposableObjects.Add(sonarQubeIssueProvider);
                var liveIssueFactory   = new LiveIssueFactory(workspace, vsSolution);
                var suppressionHandler = new SuppressionHandler(liveIssueFactory, sonarQubeIssueProvider);

                if (configuration.Mode == SonarLintMode.Connected)
                {
                    this.currentWorklow = new SonarAnalyzerConnectedWorkflow(this.workspace, suppressionHandler);
                }
                else     // Legacy
                {
                    this.currentWorklow = new SonarAnalyzerLegacyConnectedWorkflow(this.workspace, suppressionHandler,
                                                                                   this.logger);
                }
                break;
            }
        }
        private bool IsFullyBoundProject(ISolutionRuleSetsInformationProvider ruleSetInfoProvider, IRuleSetSerializer ruleSetSerializer,
                                         BindingConfiguration binding, Project project, Core.Language language)
        {
            Debug.Assert(binding != null);
            Debug.Assert(project != null);

            // If solution is not bound/is missing a rules configuration file, no need to go further
            var slnLevelBindingConfigFilepath = CalculateSonarQubeSolutionBindingConfigPath(ruleSetInfoProvider, binding, language);

            if (!fileSystem.File.Exists(slnLevelBindingConfigFilepath))
            {
                return(false);
            }

            if (!BindingRefactoringDumpingGround.IsProjectLevelBindingRequired(project))
            {
                return(true); // nothing else to check
            }

            // Projects that required project-level binding should be using RuleSets for configuration,
            // so we assume that the solution-level config file is a ruleset.
            RuleSet sonarQubeRuleSet = ruleSetSerializer.LoadRuleSet(slnLevelBindingConfigFilepath);

            if (sonarQubeRuleSet == null)
            {
                return(false);
            }

            RuleSetDeclaration[] declarations = ruleSetInfoProvider.GetProjectRuleSetsDeclarations(project).ToArray();
            return(declarations.Length > 0 && // Need at least one
                   declarations.All(declaration => this.IsRuleSetBound(ruleSetSerializer, project, declaration, sonarQubeRuleSet)));
        }
        public BindingImplementationNonGeneric To(Func <IDiContainer, object> resolverFunc)
        {
            var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateDelegateBasedImplementationConfiguration(BindingConfiguration.ServiceType, resolverFunc);

            BindingConfiguration.AddImplementation(bindingImplementationConfiguration);
            return(new BindingImplementationNonGeneric(ServiceRegistrationBuilder, bindingImplementationConfiguration, this));
        }
Esempio n. 20
0
        /// <summary>
        ///     Bind service <typeparamref name="TService" /> to implementation <typeparamref name="TImplementation" />.
        /// </summary>
        /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
        /// <returns>
        ///     Returns <see cref="T:IoC.Configuration.DiContainer.BindingsForCode.IBindingImplementationGeneric`2" />
        /// </returns>
        public IBindingImplementationGeneric <TService, TImplementation> To <TImplementation>() where TImplementation : TService
        {
            var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateTypeBasedImplementationConfiguration(BindingConfiguration.ServiceType, typeof(TImplementation));

            BindingConfiguration.AddImplementation(bindingImplementationConfiguration);
            return(new BindingImplementationGeneric <TService, TImplementation>(ServiceRegistrationBuilder, bindingImplementationConfiguration, this));
        }
Esempio n. 21
0
        /// <summary>
        ///     Bind service <typeparamref name="TService" /> to itself.
        /// </summary>
        /// <returns>
        ///     Returns <see cref="T:IoC.Configuration.DiContainer.BindingsForCode.IBindingImplementationGeneric`2" />
        /// </returns>
        public IBindingImplementationGeneric <TService, TService> ToSelf()
        {
            var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateSelfImplementationConfiguration(BindingConfiguration.ServiceType);

            BindingConfiguration.AddImplementation(bindingImplementationConfiguration);
            return(new BindingImplementationGeneric <TService, TService>(ServiceRegistrationBuilder, bindingImplementationConfiguration, this));
        }
Esempio n. 22
0
        public void StaticCreator_InvalidArgs_NullProject_Throws()
        {
            // Arrange
            Action act = () => BindingConfiguration.CreateBoundConfiguration(null, false);

            // Act & Assert
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("project");
        }
Esempio n. 23
0
        private static IActiveSolutionBoundTracker CreateSolutionTracker(SonarLintMode bindingMode)
        {
            var bindingConfiguration = new BindingConfiguration(new BoundSonarQubeProject(), bindingMode, null);
            var tracker = new Mock <IActiveSolutionBoundTracker>();

            tracker.Setup(x => x.CurrentConfiguration).Returns(bindingConfiguration);
            return(tracker.Object);
        }
        public void SolutionBindingEvent_Standalone_SonarQubeIssuesProviderNotCreated(SolutionBindingEventType eventType)
        {
            var configuration = new BindingConfiguration(new BoundSonarQubeProject(), SonarLintMode.Standalone, null);

            SimulateBindingEvent(eventType, configuration);

            createProviderFunc.VerifyNoOtherCalls();
        }
Esempio n. 25
0
        private void VerifySolutionRulesetNotChecked(BindingConfiguration bindingConfiguration)
        {
            var rulesetFilePath = GetSolutionRulesetPath(bindingConfiguration);

            fileSystemMock.Verify(x => x.File.Exists(rulesetFilePath), Times.Never);

            VerifySolutionRulesetNotLoaded();
        }
Esempio n. 26
0
        /// <summary>
        ///     Bind service <typeparamref name="TService" /> to the result of function call <paramref name="resolverFunc" />(
        ///     <see cref="T:IoC.Configuration.DiContainer.IDiContainer" />).
        ///     TImplementation should be either <typeparamref name="TService" />, or a type that implements or derives from
        ///     <typeparamref name="TService" />.
        ///     Note, we can use value of <typeparamref name="TService" /> for <typeparamref name="TImplementation" /> not to
        ///     restrict what the function
        ///     <paramref name="resolverFunc" /> returns. In other words to enforce that the implementation returns
        ///     <typeparamref name="TService" />
        ///     or a subclass or implementation of <typeparamref name="TService" />.
        /// </summary>
        /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
        /// <param name="resolverFunc">The resolver function.</param>
        /// <returns>
        ///     Returns <see cref="T:IoC.Configuration.DiContainer.BindingsForCode.IBindingImplementationGeneric`2" />
        /// </returns>
        public IBindingImplementationGeneric <TService, TImplementation> To <TImplementation>(Func <IDiContainer, TImplementation> resolverFunc) where TImplementation : TService
        {
            var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateDelegateBasedImplementationConfiguration(BindingConfiguration.ServiceType,
                                                                                                                                              typeResolver => resolverFunc(typeResolver));

            BindingConfiguration.AddImplementation(bindingImplementationConfiguration);
            return(new BindingImplementationGeneric <TService, TImplementation>(ServiceRegistrationBuilder, bindingImplementationConfiguration, this));
        }
Esempio n. 27
0
        private static BindingConfiguration GetBindingConfiguration()
        {
            var bindingConfiguration =
                new BindingConfiguration(new BoundSonarQubeProject(new Uri("http://a.com"), "key", "name"),
                                         SonarLintMode.Connected, "dummy directory");

            return(bindingConfiguration);
        }
Esempio n. 28
0
        private static string GetBindingAsText(BindingConfiguration configuration)
        {
            string project = configuration.Project?.ProjectKey ?? "{empty}";
            string org     = configuration.Project?.Organization?.Key ?? "{empty}";
            string uri     = configuration.Project.ServerUri?.ToString();

            return($"    Mode={configuration.Mode}, project={project}, organization={org}, server={uri}");
        }
        public BindingConfiguration GetConfiguration()
        {
            GetConfigurationAction?.Invoke();

            return(ModeToReturn == SonarLintMode.Standalone
                ? BindingConfiguration.Standalone
                : BindingConfiguration.CreateBoundConfiguration(ProjectToReturn, ModeToReturn, FolderPathToReturn));
        }
Esempio n. 30
0
        private string SetupSolutionAdditionalFileExists(BindingConfiguration bindingConfiguration)
        {
            var solutionAdditionalFilePath = GetSolutionAdditionalFilePath(bindingConfiguration);

            fileSystemMock.Setup(x => x.File.Exists(solutionAdditionalFilePath)).Returns(true);

            return(solutionAdditionalFilePath);
        }