public void SolutionBindingOperation_RegisterKnownRuleSets() { // Setup SolutionBindingOperation testSubject = this.CreateTestSubject("key"); var ruleSetMap = new Dictionary <Language, RuleSet>(); ruleSetMap[Language.CSharp] = new RuleSet("cs"); ruleSetMap[Language.VBNET] = new RuleSet("vb"); // Sanity Assert.AreEqual(0, testSubject.RuleSetsInformationMap.Count, "Not expecting any registered rulesets"); // Act testSubject.RegisterKnownRuleSets(ruleSetMap); // Verify CollectionAssert.AreEquivalent(ruleSetMap.Keys.ToArray(), testSubject.RuleSetsInformationMap.Keys.ToArray()); Assert.AreSame(ruleSetMap[Language.CSharp], testSubject.RuleSetsInformationMap[Language.CSharp].RuleSet); Assert.AreSame(ruleSetMap[Language.VBNET], testSubject.RuleSetsInformationMap[Language.VBNET].RuleSet); }
public void SolutionBindingOperation_RegisterKnownRuleSets() { // Arrange SolutionBindingOperation testSubject = this.CreateTestSubject("key"); var ruleSetMap = new Dictionary <Language, RuleSet>(); ruleSetMap[Language.CSharp] = new RuleSet("cs"); ruleSetMap[Language.VBNET] = new RuleSet("vb"); // Sanity testSubject.RuleSetsInformationMap.Should().BeEmpty("Not expecting any registered rulesets"); // Act testSubject.RegisterKnownRuleSets(ruleSetMap); // Assert CollectionAssert.AreEquivalent(ruleSetMap.Keys.ToArray(), testSubject.RuleSetsInformationMap.Keys.ToArray()); testSubject.RuleSetsInformationMap[Language.CSharp].RuleSet.Should().Be(ruleSetMap[Language.CSharp]); testSubject.RuleSetsInformationMap[Language.VBNET].RuleSet.Should().Be(ruleSetMap[Language.VBNET]); }
public void SolutionBindingOperation_Prepare_Cancellation_DuringBindersPrepare() { // 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 bool prepareCalledForBinder = false; using (CancellationTokenSource src = new CancellationTokenSource()) { testSubject.Binders.Add(new ConfigurableBindingOperation { PrepareAction = (t) => src.Cancel() }); testSubject.Binders.Add(new ConfigurableBindingOperation { PrepareAction = (t) => prepareCalledForBinder = true }); // Act testSubject.Prepare(src.Token); } // Assert testSubject.RuleSetsInformationMap[Language.CSharp].NewRuleSetFilePath.Should().Be(@"c:\solution\SonarQube\keyCSharp.ruleset"); testSubject.RuleSetsInformationMap[Language.VBNET].NewRuleSetFilePath.Should().Be(@"c:\solution\SonarQube\keyVB.ruleset"); prepareCalledForBinder.Should().BeFalse("Expected to be canceled as soon as possible i.e. after the first binder"); }