示例#1
0
        public void ShouldExecuteRegisteredAction_WhenTreeIsNull_ReturnsFalse()
        {
            // Arrange
            var testSubject = new TestableSonarAnalyzerWorkflow(new AdhocWorkspace());

            // Act
            var result = testSubject.ShouldExecuteRegisteredAction(null);

            // Assert
            result.Should().BeFalse();
        }
示例#2
0
        public void ShouldRegisterContextAction_AlwaysReturnsNull()
        {
            // Arrange
            var testSubject = new TestableSonarAnalyzerWorkflow(new AdhocWorkspace());

            // Act
            var result1 = testSubject.ShouldRegisterContextAction(null);
            var result2 = testSubject.ShouldRegisterContextAction(Enumerable.Empty <DiagnosticDescriptor>());

            // Assert
            result1.Should().BeNull();
            result2.Should().BeNull();
        }
示例#3
0
        public void ShouldExecuteRegisteredAction_WhenTreeNotNullAndNuGetAnalyzerDifferentVersion_ReturnsFalse()
        {
            // Arrange
            var testSubject = new TestableSonarAnalyzerWorkflow(new AdhocWorkspace());

            testSubject.GetProjectNuGetAnalyzerStatusFunc = tree => ProjectAnalyzerStatus.DifferentVersion;

            // Act
            var result = testSubject.ShouldExecuteRegisteredAction(new Mock <SyntaxTree>().Object);

            // Assert
            result.Should().BeFalse();
        }
        public void ShouldExecuteRegisteredAction_WhenTreeNotNullAndNoNuGetAnalyzer_ReturnsTrue()
        {
            // Arrange
            var testSubject = new TestableSonarAnalyzerWorkflow(new AdhocWorkspace());

            testSubject.GetProjectNuGetAnalyzerStatusFunc = tree => ProjectAnalyzerStatus.NoAnalyzer;

            // Act
            var result = testSubject.ShouldExecuteRegisteredAction(Enumerable.Empty <DiagnosticDescriptor>(), new Mock <SyntaxTree>().Object);

            // Assert
            result.Should().BeTrue();
        }
示例#5
0
        public void ShouldRegisterContextActionWithFallback_WhenShouldRegisterContextActionReturnsNullAndRuleNotInSonarWay_ReturnsFalse()
        {
            // Arrange
            var testSubject = new TestableSonarAnalyzerWorkflow(new AdhocWorkspace());
            var diag1 = CreateFakeDiagnostic(false, "1");
            var diag2 = CreateFakeDiagnostic(false, "2");
            var descriptors = new[] { diag1, diag2 }.Select(x => x.Descriptor);

            // Act
            var result = testSubject.ShouldRegisterContextActionWithFallback(descriptors);

            // Assert
            result.Should().BeFalse();
        }
示例#6
0
        public void ShouldRegisterContextActionWithFallback_WhenAnyDescriptorNotConfigurable_ReturnsTrue()
        {
            // Arrange
            var testSubject = new TestableSonarAnalyzerWorkflow(new AdhocWorkspace());
            var diag1 = CreateFakeDiagnostic(false, "1", isNotConfigurable: false);
            var diag2 = CreateFakeDiagnostic(false, "2", isNotConfigurable: true);
            var descriptors = new[] { diag1, diag2 }.Select(x => x.Descriptor);

            // Act
            var result = testSubject.ShouldRegisterContextActionWithFallback(descriptors);

            // Assert
            result.Should().BeTrue();
        }
示例#7
0
        public void ShouldRegisterContextActionWithFallback_WhenShouldRegisterContextActionDoesNotReturnNull_ReturnsSameResult()
        {
            // Arrange
            var testSubject = new TestableSonarAnalyzerWorkflow(new AdhocWorkspace());
            var diag1 = CreateFakeDiagnostic(true, "1");
            var diag2 = CreateFakeDiagnostic(true, "2");
            var descriptors = new[] { diag1, diag2 }.Select(x => x.Descriptor);

            testSubject.ShouldRegisterContextActionFunc = d => false;

            // Act
            var result = testSubject.ShouldRegisterContextActionWithFallback(descriptors);

            // Assert
            result.Should().BeFalse();
        }
示例#8
0
        public void Ctor_SetsTheExpectedDelegates()
        {
            // Arrange
            Func <IEnumerable <DiagnosticDescriptor>, bool> expectedShouldRegisterContextAction = list => false;

            SonarAnalysisContext.ShouldRegisterContextAction = expectedShouldRegisterContextAction;
            Func <SyntaxTree, bool> expectedShouldExecuteRegisteredAction = tree => true;

            SonarAnalysisContext.ShouldExecuteRegisteredAction = expectedShouldExecuteRegisteredAction;

            // Act
            var testSubject = new TestableSonarAnalyzerWorkflow(new AdhocWorkspace());

            // Assert
            SonarAnalysisContext.ShouldRegisterContextAction.Should().NotBe(expectedShouldRegisterContextAction);
            SonarAnalysisContext.ShouldExecuteRegisteredAction.Should().NotBe(expectedShouldExecuteRegisteredAction);
        }