public void SolutionBindingOperation_Prepare() { // Arrange var csProject = this.solutionMock.AddOrGetProject("CS.csproj"); csProject.SetCSProjectKind(); var vbProject = this.solutionMock.AddOrGetProject("VB.vbproj"); vbProject.SetVBProjectKind(); var projects = new[] { csProject, vbProject }; SolutionBindingOperation testSubject = this.CreateTestSubject("key"); var csConfigFile = CreateMockRuleSetConfigFile("cs"); var vbConfigFile = CreateMockRuleSetConfigFile("vb"); var ruleSetMap = new Dictionary <Language, IBindingConfigFile>(); ruleSetMap[Language.CSharp] = csConfigFile.Object; ruleSetMap[Language.VBNET] = vbConfigFile.Object; testSubject.RegisterKnownConfigFiles(ruleSetMap); testSubject.Initialize(projects, GetQualityProfiles()); testSubject.Binders.Clear(); // Ignore the real binders, not part of this test scope var binder = new ConfigurableBindingOperation(); testSubject.Binders.Add(binder); bool prepareCalledForBinder = false; binder.PrepareAction = (ct) => prepareCalledForBinder = true; string sonarQubeRulesDirectory = Path.Combine(SolutionRoot, ConfigurableSolutionRuleSetsInformationProvider.DummyLegacyModeFolderName); var csharpRulesetPath = Path.Combine(sonarQubeRulesDirectory, "keycsharp.ruleset"); var vbRulesetPath = Path.Combine(sonarQubeRulesDirectory, "keyvb.ruleset"); // Sanity this.sccFileSystem.directories.Should().NotContain(sonarQubeRulesDirectory); testSubject.RuleSetsInformationMap[Language.CSharp].NewFilePath.Should().Be(csharpRulesetPath); testSubject.RuleSetsInformationMap[Language.VBNET].NewFilePath.Should().Be(vbRulesetPath); // Act testSubject.Prepare(CancellationToken.None); // Assert this.sccFileSystem.directories.Should().NotContain(sonarQubeRulesDirectory); prepareCalledForBinder.Should().BeTrue("Expected to propagate the prepare call to binders"); CheckSaveWasNotCalled(csConfigFile); CheckSaveWasNotCalled(vbConfigFile); // Act (write pending) this.sccFileSystem.WritePendingNoErrorsExpected(); // Assert CheckRuleSetFileWasSaved(csConfigFile, csharpRulesetPath); CheckRuleSetFileWasSaved(vbConfigFile, vbRulesetPath); this.sccFileSystem.directories.Should().Contain(sonarQubeRulesDirectory); }
public void SolutionBindingOperation_Prepare() { // Arrange var csProject = this.solutionMock.AddOrGetProject("CS.csproj"); csProject.SetCSProjectKind(); var vbProject = this.solutionMock.AddOrGetProject("VB.vbproj"); vbProject.SetVBProjectKind(); var projects = new[] { csProject, vbProject }; SolutionBindingOperation testSubject = this.CreateTestSubject("key"); var ruleSetMap = new Dictionary <Language, RuleSet>(); ruleSetMap[Language.CSharp] = new RuleSet("cs"); ruleSetMap[Language.VBNET] = new RuleSet("vb"); testSubject.RegisterKnownRuleSets(ruleSetMap); testSubject.Initialize(projects, GetQualityProfiles()); testSubject.Binders.Clear(); // Ignore the real binders, not part of this test scope var binder = new ConfigurableBindingOperation(); testSubject.Binders.Add(binder); bool prepareCalledForBinder = false; binder.PrepareAction = (ct) => prepareCalledForBinder = true; string sonarQubeRulesDirectory = Path.Combine(SolutionRoot, Constants.SonarQubeManagedFolderName); // Sanity this.sccFileSystem.directories.Should().NotContain(sonarQubeRulesDirectory); testSubject.RuleSetsInformationMap[Language.CSharp].NewRuleSetFilePath.Should().Be(@"c:\solution\SonarQube\keyCSharp.ruleset"); testSubject.RuleSetsInformationMap[Language.VBNET].NewRuleSetFilePath.Should().Be(@"c:\solution\SonarQube\keyVB.ruleset"); // Act testSubject.Prepare(CancellationToken.None); // Assert this.sccFileSystem.directories.Should().NotContain(sonarQubeRulesDirectory); prepareCalledForBinder.Should().BeTrue("Expected to propagate the prepare call to binders"); this.sccFileSystem.files.Should().NotContainKey(@"c:\solution\SonarQube\keyCSharp.ruleset"); this.sccFileSystem.files.Should().NotContainKey(@"c:\solution\SonarQube\keyVB.ruleset"); // Act (write pending) this.sccFileSystem.WritePendingNoErrorsExpected(); // Assert this.sccFileSystem.files.Should().ContainKey(@"c:\solution\SonarQube\keyCSharp.ruleset"); this.sccFileSystem.files.Should().ContainKey(@"c:\solution\SonarQube\keyVB.ruleset"); this.sccFileSystem.directories.Should().Contain(sonarQubeRulesDirectory); }
public void SolutionBindingOperation_Prepare() { // Setup var csProject = this.solutionMock.AddOrGetProject("CS.csproj"); csProject.SetCSProjectKind(); var vbProject = this.solutionMock.AddOrGetProject("VB.vbproj"); vbProject.SetVBProjectKind(); var projects = new[] { csProject, vbProject }; SolutionBindingOperation testSubject = this.CreateTestSubject("key"); var ruleSetMap = new Dictionary<Language, RuleSet>(); ruleSetMap[Language.CSharp] = new RuleSet("cs"); ruleSetMap[Language.VBNET] = new RuleSet("vb"); testSubject.RegisterKnownRuleSets(ruleSetMap); testSubject.Initialize(projects, GetQualityProfiles()); testSubject.Binders.Clear(); // Ignore the real binders, not part of this test scope var binder = new ConfigurableBindingOperation(); testSubject.Binders.Add(binder); bool prepareCalledForBinder = false; binder.PrepareAction = (ct) => prepareCalledForBinder = true; string sonarQubeRulesDirectory = Path.Combine(SolutionRoot, Constants.SonarQubeManagedFolderName); // Sanity this.sccFileSystem.AssertDirectoryNotExists(sonarQubeRulesDirectory); Assert.AreEqual(@"c:\solution\SonarQube\keyCSharp.ruleset", testSubject.RuleSetsInformationMap[Language.CSharp].NewRuleSetFilePath); Assert.AreEqual(@"c:\solution\SonarQube\keyVB.ruleset", testSubject.RuleSetsInformationMap[Language.VBNET].NewRuleSetFilePath); // Act testSubject.Prepare(CancellationToken.None); // Verify this.sccFileSystem.AssertDirectoryNotExists(sonarQubeRulesDirectory); Assert.IsTrue(prepareCalledForBinder, "Expected to propagate the prepare call to binders"); this.sccFileSystem.AssertFileNotExists(@"c:\solution\SonarQube\keyCSharp.ruleset"); this.sccFileSystem.AssertFileNotExists(@"c:\solution\SonarQube\keyVB.ruleset"); // Act (write pending) this.sccFileSystem.WritePendingNoErrorsExpected(); // Verify this.sccFileSystem.AssertFileExists(@"c:\solution\SonarQube\keyCSharp.ruleset"); this.sccFileSystem.AssertFileExists(@"c:\solution\SonarQube\keyVB.ruleset"); this.sccFileSystem.AssertDirectoryExists(sonarQubeRulesDirectory); }