Ejemplo n.º 1
0
        public void ShouldReport_LocationNotInSource_ReturnsTrue()
        {
            // Arrange
            Diagnostic diag = CreateDiagnostic("dummy rule ID", CreateNonSourceLocation());

            SuppressionHandler handler = new SuppressionHandler(issueFactoryMock.Object, issueProviderMock.Object);

            // Act
            bool result = handler.ShouldIssueBeReported(new Mock <SyntaxTree>().Object, diag);

            // Assert
            result.Should().BeTrue();

            // Should early-out
            VerifyLiveIssueCreated(Times.Never());
            VerifyServerIssuesRequested(Times.Never());
        }
Ejemplo n.º 2
0
        public void ShouldReport_CannotCreateLiveIssue_ReturnsTrue()
        {
            // Arrange
            Diagnostic diag = CreateDiagnostic("dummy rule id", CreateSourceLocation());

            SetLiveIssue(null);

            SuppressionHandler handler = new SuppressionHandler(issueFactoryMock.Object, issueProviderMock.Object);

            // Act
            bool result = handler.ShouldIssueBeReported(syntaxTreeMock.Object, diag);

            // Assert
            VerifyLiveIssueCreated(Times.Once());
            VerifyServerIssuesRequested(Times.Never());
            result.Should().BeTrue();
        }
Ejemplo n.º 3
0
        public void ShouldReport_NoServerIssues_ReturnsTrue()
        {
            // Arrange
            Diagnostic diag = CreateDiagnostic("dummy rule id", CreateSourceLocation());

            SetLiveIssue(diag, startLine: 1, wholeLineText: "text");
            SetServerIssues(Array.Empty <SonarQubeIssue>());

            SuppressionHandler handler = new SuppressionHandler(issueFactoryMock.Object, issueProviderMock.Object);

            // Act
            bool result = handler.ShouldIssueBeReported(syntaxTreeMock.Object, diag);

            // Assert
            VerifyLiveIssueCreated(Times.Once());
            VerifyServerIssuesRequested(Times.Once());
            result.Should().BeTrue();
        }
Ejemplo n.º 4
0
        public void ShouldReport_FileOrProjectIssue_MatchExists_ReturnsFalse()
        {
            // Arrange
            Diagnostic diag = CreateDiagnostic("RightRuleId", CreateSourceLocation());

            SetLiveIssue(diag, startLine: 0, wholeLineText: "");

            var serverIssue1 = CreateServerIssue("WrongRuleId", 0, "");
            var serverIssue2 = CreateServerIssue("RightRuleId", 0, "wrong hash"); // wrong hash
            var serverIssue3 = CreateServerIssue("RightRuleId", 0, "");

            SetServerIssues(serverIssue1, serverIssue2, serverIssue3);

            SuppressionHandler handler = new SuppressionHandler(issueFactoryMock.Object, issueProviderMock.Object);

            // Act
            bool result = handler.ShouldIssueBeReported(new Mock <SyntaxTree>().Object, diag);

            // Assert
            result.Should().BeFalse();
        }
Ejemplo n.º 5
0
        public void ShouldReport_ServerIssueMatchesOnLine_ReturnsFalse()
        {
            // Arrange
            string wholeLineText = "whole line text";

            Diagnostic diag = CreateDiagnostic("RightRuleId", CreateSourceLocation());

            SetLiveIssue(diag, startLine: 101, wholeLineText: wholeLineText);

            var serverIssue = CreateServerIssue("RightRuleId", 101, "wrong hash");

            SetServerIssues(serverIssue);

            SuppressionHandler handler = new SuppressionHandler(issueFactoryMock.Object, issueProviderMock.Object);

            // Act
            bool result = handler.ShouldIssueBeReported(syntaxTreeMock.Object, diag);

            // Assert
            result.Should().BeFalse();
        }
Ejemplo n.º 6
0
        public void ShouldReport_ServerIssueMatchesOnLineHash_ReturnsFalse()
        {
            // Arrange
            string wholeLineText = "whole line text";
            string lineHash      = ChecksumCalculator.Calculate(wholeLineText);

            Diagnostic diag = CreateDiagnostic("RightRuleId", CreateSourceLocation());

            SetLiveIssue(diag, startLine: 101, wholeLineText: wholeLineText);

            var serverIssue = CreateServerIssue("RIGHTRULEID", 999, lineHash); // rule id comparison is case-insensitive

            SetServerIssues(serverIssue);

            SuppressionHandler handler = new SuppressionHandler(issueFactoryMock.Object, issueProviderMock.Object);

            // Act
            bool result = handler.ShouldIssueBeReported(syntaxTreeMock.Object, diag);

            // Assert
            result.Should().BeFalse();
        }
Ejemplo n.º 7
0
        public void ShouldReport_NoMatchingServerIssues_ReturnsTrue()
        {
            // Arrange
            string wholeLineText = "whole line text";
            string lineHash      = ChecksumCalculator.Calculate(wholeLineText);

            Diagnostic diag = CreateDiagnostic("RuleId 1", CreateSourceLocation());

            SetLiveIssue(diag, startLine: 10, wholeLineText: wholeLineText);

            var serverIssue1 = CreateServerIssue("Wrong rule id", 10, lineHash);                // wrong rule id
            var serverIssue2 = CreateServerIssue("RuleId 1", 999, "wrong hash");                // wrong line and hash
            var serverIssue3 = CreateServerIssue("RuleId 1", 999, lineHash.ToUpperInvariant()); // wrong line and wrong-case hash

            SetServerIssues(serverIssue1, serverIssue2, serverIssue3);

            SuppressionHandler handler = new SuppressionHandler(issueFactoryMock.Object, issueProviderMock.Object);

            // Act
            bool result = handler.ShouldIssueBeReported(syntaxTreeMock.Object, diag);

            // Assert
            result.Should().BeTrue();
        }