private void ExecuteCommitSolutionBindingTest(SonarLintMode bindingMode) { // Arrange var configProvider = new ConfigurableConfigurationProvider(); this.serviceProvider.RegisterService(typeof(IConfigurationProvider), configProvider); var csProject = this.solutionMock.AddOrGetProject("CS.csproj"); csProject.SetCSProjectKind(); var projects = new[] { csProject }; var connectionInformation = new ConnectionInformation(new Uri("http://xyz")); SolutionBindingOperation testSubject = this.CreateTestSubject("key", connectionInformation, bindingMode); var configFileMock = CreateMockRuleSetConfigFile("cs"); var languageToFileMap = new Dictionary <Language, IBindingConfigFile>() { { Language.CSharp, configFileMock.Object } }; testSubject.RegisterKnownConfigFiles(languageToFileMap); var profiles = GetQualityProfiles(); DateTime expectedTimeStamp = DateTime.Now; profiles[Language.CSharp] = new SonarQubeQualityProfile("expected profile Key", "", "", false, expectedTimeStamp); testSubject.Initialize(projects, profiles); testSubject.Binders.Clear(); // Ignore the real binders, not part of this test scope bool commitCalledForBinder = false; testSubject.Binders.Add(new ConfigurableBindingOperation { CommitAction = () => commitCalledForBinder = true }); testSubject.Prepare(CancellationToken.None); // Sanity configProvider.SavedConfiguration.Should().BeNull(); // Act var commitResult = testSubject.CommitSolutionBinding(); // Assert commitResult.Should().BeTrue(); commitCalledForBinder.Should().BeTrue(); configProvider.SavedConfiguration.Should().NotBeNull(); configProvider.SavedConfiguration.Mode.Should().Be(bindingMode); var savedProject = configProvider.SavedConfiguration.Project; savedProject.ServerUri.Should().Be(connectionInformation.ServerUri); savedProject.Profiles.Should().HaveCount(1); savedProject.Profiles[Language.CSharp].ProfileKey.Should().Be("expected profile Key"); savedProject.Profiles[Language.CSharp].ProfileTimestamp.Should().Be(expectedTimeStamp); }
public void SolutionBindingOperation_CommitSolutionBinding() { // Arrange var configProvider = new ConfigurableConfigurationProvider(); this.serviceProvider.RegisterService(typeof(IConfigurationProvider), configProvider); var csProject = this.solutionMock.AddOrGetProject("CS.csproj"); csProject.SetCSProjectKind(); var projects = new[] { csProject }; var connectionInformation = new ConnectionInformation(new Uri("http://xyz")); SolutionBindingOperation testSubject = this.CreateTestSubject("key", connectionInformation); var ruleSetMap = new Dictionary <Language, RuleSet>(); ruleSetMap[Language.CSharp] = new RuleSet("cs"); testSubject.RegisterKnownRuleSets(ruleSetMap); var profiles = GetQualityProfiles(); DateTime expectedTimeStamp = DateTime.Now; profiles[Language.CSharp] = new SonarQubeQualityProfile("expected profile Key", "", "", false, expectedTimeStamp); testSubject.Initialize(projects, profiles); testSubject.Binders.Clear(); // Ignore the real binders, not part of this test scope bool commitCalledForBinder = false; testSubject.Binders.Add(new ConfigurableBindingOperation { CommitAction = () => commitCalledForBinder = true }); testSubject.Prepare(CancellationToken.None); // Sanity configProvider.SavedConfiguration.Should().BeNull(); // Act var commitResult = testSubject.CommitSolutionBinding(); // Assert commitResult.Should().BeTrue(); commitCalledForBinder.Should().BeTrue(); this.solutionItemsProject.Files.ContainsKey(@"c:\solution\SonarQube\keyCSharp.ruleset").Should().BeTrue("Ruleset was expected to be added to solution items"); configProvider.SavedConfiguration.Should().NotBeNull(); configProvider.SavedConfiguration.Mode.Should().Be(SonarLintMode.LegacyConnected); var savedProject = configProvider.SavedConfiguration.Project; savedProject.ServerUri.Should().Be(connectionInformation.ServerUri); savedProject.Profiles.Should().HaveCount(1); savedProject.Profiles[Language.CSharp].ProfileKey.Should().Be("expected profile Key"); savedProject.Profiles[Language.CSharp].ProfileTimestamp.Should().Be(expectedTimeStamp); }
public void SolutionBindingOperation_CommitSolutionBinding() { // Arrange this.serviceProvider.RegisterService(typeof(Persistence.ISolutionBindingSerializer), this.solutionBinding); var csProject = this.solutionMock.AddOrGetProject("CS.csproj"); csProject.SetCSProjectKind(); var projects = new[] { csProject }; var connectionInformation = new ConnectionInformation(new Uri("http://xyz")); SolutionBindingOperation testSubject = this.CreateTestSubject("key", connectionInformation); var ruleSetMap = new Dictionary <Language, RuleSet>(); ruleSetMap[Language.CSharp] = new RuleSet("cs"); testSubject.RegisterKnownRuleSets(ruleSetMap); var profiles = GetQualityProfiles(); profiles[Language.CSharp] = new QualityProfile { Key = "C# Profile", QualityProfileTimestamp = DateTime.Now }; testSubject.Initialize(projects, profiles); testSubject.Binders.Clear(); // Ignore the real binders, not part of this test scope bool commitCalledForBinder = false; testSubject.Binders.Add(new ConfigurableBindingOperation { CommitAction = () => commitCalledForBinder = true }); testSubject.Prepare(CancellationToken.None); this.solutionBinding.WriteSolutionBindingAction = bindingInfo => { bindingInfo.ServerUri.Should().Be(connectionInformation.ServerUri); bindingInfo.Profiles.Should().HaveCount(1); QualityProfile csProfile = profiles[Language.CSharp]; bindingInfo.Profiles[Language.CSharp].ProfileKey.Should().Be(csProfile.Key); bindingInfo.Profiles[Language.CSharp].ProfileTimestamp.Should().Be(csProfile.QualityProfileTimestamp); return("Doesn't matter"); }; // Sanity this.solutionBinding.WrittenFilesCount.Should().Be(0); // Act var commitResult = testSubject.CommitSolutionBinding(); // Assert commitResult.Should().BeTrue(); commitCalledForBinder.Should().BeTrue(); this.solutionItemsProject.Files.ContainsKey(@"c:\solution\SonarQube\keyCSharp.ruleset").Should().BeTrue("Ruleset was expected to be added to solution items"); this.solutionBinding.WrittenFilesCount.Should().Be(1); }
private void ExecuteCommitSolutionBindingTest(SonarLintMode bindingMode, string expectedFilePath) { // Arrange var csProject = solutionMock.AddOrGetProject("CS.csproj"); csProject.SetCSProjectKind(); var csConfigFile = CreateMockConfigFile(expectedFilePath); var csBinder = new Mock <IProjectBinder>(); var csBinderCommitAction = new Mock <BindProject>(); projectBinderFactoryMock.Setup(x => x.Get(csProject)).Returns(csBinder.Object); csBinder .Setup(x => x.GetBindAction(csConfigFile.Object, csProject, CancellationToken.None)) .Returns(csBinderCommitAction.Object); var projects = new[] { csProject }; var connectionInformation = new ConnectionInformation(new Uri("http://xyz")); SolutionBindingOperation testSubject = this.CreateTestSubject(bindingMode); var languageToFileMap = new Dictionary <Language, IBindingConfig>() { { Language.CSharp, csConfigFile.Object } }; testSubject.RegisterKnownConfigFiles(languageToFileMap); DateTime expectedTimeStamp = DateTime.Now; testSubject.Initialize(projects); testSubject.Prepare(CancellationToken.None); // Act var commitResult = testSubject.CommitSolutionBinding(); // Assert commitResult.Should().BeTrue(); csBinderCommitAction.Verify(x => x(), Times.Once); }