예제 #1
0
        public void GetQualityProfile_WhenHasNullArgs_Throws()
        {
            var testSubject = new SonarQubeQualityProfileProvider(serviceMock.Object, loggerMock.Object);

            // 1. Null project
            Action act = () => testSubject.GetQualityProfile(null, Language.CSharp);

            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("project");

            // 2. Null language
            act = () => testSubject.GetQualityProfile(new BoundSonarQubeProject(), null);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("language");
        }
예제 #2
0
        public void GetQualityProfile_WhenHasExportResponse_ReturnsExportResponse()
        {
            // Arrange
            XmlDocument rulesetDoc = new XmlDocument();

            var rulesXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<RuleSet Name=""Rules for SonarQube"" Description=""This rule set was automatically generated from SonarQube."" ToolsVersion=""14.0"">
  <Rules AnalyzerId=""SonarAnalyzer.CSharp"" RuleNamespace=""SonarAnalyzer.CSharp"">
    <Rule Id=""S121"" Action=""Warning"" />
    <Rule Id=""S122"" Action=""Warning"" />
  </Rules>
</RuleSet>";

            rulesetDoc.LoadXml(rulesXml);
            var exportResponse = new RoslynExportProfileResponse
            {
                Configuration = new ConfigurationResponse
                {
                    RuleSet = rulesetDoc.DocumentElement
                }
            };

            SetupServiceResponses(ValidQualityProfileResponse, exportResponse);
            var testSubject = new SonarQubeQualityProfileProvider(serviceMock.Object, loggerMock.Object);

            // Act
            var result = testSubject.GetQualityProfile(new BoundSonarQubeProject(), Language.VBNET);

            // Assert
            result.Should().NotBeNull();
            result.Rules.Count().Should().Be(2);
        }
예제 #3
0
        public void GetQualityProfile_WhenHasUnrecognisedLanguage_ReturnsNull()
        {
            // Arrange
            var testSubject = new SonarQubeQualityProfileProvider(serviceMock.Object, loggerMock.Object);

            // Act
            var result = testSubject.GetQualityProfile(new BoundSonarQubeProject(), Language.Unknown);

            // Assert
            result.Should().BeNull();
        }
예제 #4
0
        public void GetQualityProfile_WhenHasNullExportResponse_ReturnsNull()
        {
            // Arrange
            SetupServiceResponses(ValidQualityProfileResponse, null);
            var testSubject = new SonarQubeQualityProfileProvider(serviceMock.Object, loggerMock.Object);

            // Act
            var result = testSubject.GetQualityProfile(new BoundSonarQubeProject(), Language.Unknown);

            // Assert
            result.Should().BeNull();
        }
예제 #5
0
        public void GetQualityProfile_WhenHasNoQualityProfile_ReturnsNull()
        {
            // Arrange
            serviceMock
            .Setup(x => x.GetQualityProfileAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SonarQubeLanguage>(), It.IsAny <CancellationToken>()))
            .Throws(new InvalidOperationException("The SonarC# plugin is not installed on the connected SonarQube."));

            var testSubject = new SonarQubeQualityProfileProvider(serviceMock.Object, loggerMock.Object);

            // Act
            var result = testSubject.GetQualityProfile(new BoundSonarQubeProject(), Language.CSharp);

            // Assert
            result.Should().BeNull();
            loggerMock.Verify(
                x => x.WriteLine("SonarQube request failed: {0} {1}", "The SonarC# plugin is not installed on the connected SonarQube.", null),
                Times.Once());
        }