Beispiel #1
0
        public void DeleteCredentials_RegularException_ExceptionIsRethrownAndNotLogged()
        {
            mockCredentialStore
            .Setup(x => x.DeleteCredentials(wellKnownTargetUri))
            .Throws(new FileFormatException());

            Action action = () => testSubject.DeleteCredentials(wellKnownTargetUri);

            action.Should().ThrowExactly <FileFormatException>();

            logger.AssertNoOutputMessages();
        }
        public async Task Analyze_EslintBridgeClientNotInitializedResponse_FollowedByValidResponse_ConvertedIssuesReturnedAndParsingErrorNotLogged()
        {
            var linterNotInitializedResponse = CreateLinterNotInitializedResponse();
            var validResponse = new AnalysisResponse {
                Issues = new List <Issue> {
                    new Issue()
                }
            };
            var logger = new TestLogger();
            var client = new Mock <IEslintBridgeClient>();

            client
            .SetupSequence(x => x.Analyze("some path", "some config", CancellationToken.None))
            .ReturnsAsync(linterNotInitializedResponse)
            .ReturnsAsync(validResponse);

            var convertedIssues = new[] { Mock.Of <IAnalysisIssue>() };
            var issueConverter  = new Mock <IEslintBridgeIssueConverter>();

            SetupConvertedIssue(issueConverter, "some path", validResponse.Issues.First(), convertedIssues[0]);

            var testSubject = CreateTestSubject(client.Object, issueConverter: issueConverter.Object, logger: logger);
            var result      = await testSubject.Analyze("some path", "some config", CancellationToken.None);

            result.Should().BeEquivalentTo(convertedIssues);
            logger.AssertNoOutputMessages();
            client.Verify(x => x.Analyze("some path", "some config", CancellationToken.None), Times.Exactly(2));
        }
        public void GetIssues_NotConnected_NoErrors()
        {
            // Arrange
            SetupSolutionBinding(isConnected: false, issues: null);

            int callCount = 0;

            // This time we want the test to pause until IsConnected is called by the inital fetch task
            mockSqService.Setup(x => x.IsConnected)
            .Returns(false)
            .Callback(() => { InitialFetchWaitHandle.Set(); callCount++; })      // signal so the test can continue
            .Verifiable();

            // 1. Initialise the class
            var issuesProvider = new SonarQubeIssuesProvider(mockSqService.Object, "sqKey",
                                                             mockTimerFactory.Object, testLogger);

            WaitForInitialFetchTaskToStart();

            // 2. Now dispose. Should stop the background fetching
            int callsBeforeDispose = callCount;

            issuesProvider.Dispose();

            // 3. Now try to fetch - should block until the background task has completed
            var issues = issuesProvider.GetSuppressedIssues("dummy guid", "dummy file path");

            issues.Should().BeEmpty();
            VerifyServiceGetIssues(Times.Never());

            // Timing: increment could have afer dispose called but before the cancellation token was set
            callCount.Should().BeLessOrEqualTo(callsBeforeDispose + 1);

            testLogger.AssertNoOutputMessages();
        }
        public async Task GetRules_NoData_EmptyResultReturned()
        {
            // Arrange
            var testLogger  = new TestLogger();
            var serviceMock = new Mock <ISonarQubeService>();

            serviceMock.Setup(x => x.GetRulesAsync(It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => new List <SonarQubeRule>());

            var testSubject = new CFamilyBindingConfigProvider(serviceMock.Object, testLogger);

            // Act
            var result = await testSubject.GetConfigurationAsync(CreateQp(), null, Language.Cpp, CancellationToken.None);

            // Assert
            result.Should().NotBeNull();
            result.Should().BeOfType <CFamilyBindingConfigFile>();

            var cfamilyConfigFile = (CFamilyBindingConfigFile)result;

            cfamilyConfigFile.RuleSettings.Should().NotBeNull();
            cfamilyConfigFile.RuleSettings.Rules.Should().NotBeNull();
            cfamilyConfigFile.RuleSettings.Rules.Count.Should().Be(0);

            testLogger.AssertNoOutputMessages();
        }
Beispiel #5
0
        public async Task GetRules_Success()
        {
            // Arrange
            var testLogger = new TestLogger();
            var rules      = new List <SonarQubeRule>
            {
                CreateRule("key1", "repo1", true, SonarQubeIssueSeverity.Major),
                CreateRule("key2", "repo2", false, SonarQubeIssueSeverity.Info,
                           new Dictionary <string, string>
                {
                    { "p1", "v1" },
                    { "p2", "v2" }
                })
            };

            var serviceMock = new Mock <ISonarQubeService>();

            serviceMock.Setup(x => x.GetRulesAsync(true, It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => rules);

            var bindingConfiguration = new BindingConfiguration(new BoundSonarQubeProject {
                ProjectKey = "test"
            }, SonarLintMode.Connected, "c:\\");

            var testSubject = new CFamilyBindingConfigProvider(serviceMock.Object, testLogger);

            // Act
            var result = await testSubject.GetConfigurationAsync(CreateQp(), Language.Cpp, bindingConfiguration, CancellationToken.None);

            // Assert
            result.Should().NotBeNull();
            result.Should().BeOfType <CFamilyBindingConfig>();

            var cfamilyConfigFile = (CFamilyBindingConfig)result;

            cfamilyConfigFile.RuleSettings.Should().NotBeNull();

            var slvsRules = cfamilyConfigFile.RuleSettings.Rules;

            slvsRules.Should().NotBeNull();
            slvsRules.Keys.Should().BeEquivalentTo("repo1:key1", "repo2:key2");
            slvsRules["repo1:key1"].Level.Should().Be(RuleLevel.On);
            slvsRules["repo2:key2"].Level.Should().Be(RuleLevel.Off);

            slvsRules["repo1:key1"].Severity.Should().Be(IssueSeverity.Major);
            slvsRules["repo2:key2"].Severity.Should().Be(IssueSeverity.Info);

            slvsRules["repo1:key1"].Parameters.Should().BeNull();

            var rule2Params = slvsRules["repo2:key2"].Parameters;

            rule2Params.Should().NotBeNull();
            rule2Params.Keys.Should().BeEquivalentTo("p1", "p2");
            rule2Params["p1"].Should().Be("v1");
            rule2Params["p2"].Should().Be("v2");

            testLogger.AssertNoOutputMessages();
        }
        public void NoListeners_NoError()
        {
            var logger      = new TestLogger();
            var testSubject = new AnalysisRequester(logger);

            testSubject.RequestAnalysis();

            logger.AssertNoOutputMessages();
        }
        public void CanHandleOpenInIDERequest_CorrectConnection_True()
        {
            var configProvider = SetupConfigurationProvider(CreateBindingConfiguration(RequestConfiguration));
            var logger         = new TestLogger();

            var testSubject = new OpenInIdeStateValidator(configProvider, logger);
            var result      = testSubject.CanHandleOpenInIDERequest(new Uri(RequestConfiguration.ServerUrl), RequestConfiguration.ProjectKey, RequestConfiguration.OrganizationKey);

            result.Should().BeTrue();
            logger.AssertNoOutputMessages();
        }
        public void CriticalErrorInListener_IsNotSuppressedORLogged()
        {
            var logger      = new TestLogger();
            var testSubject = new AnalysisRequester(logger);

            testSubject.AnalysisRequested += (s, e) => throw new StackOverflowException("XXX overflow");

            Action act = () => testSubject.RequestAnalysis();

            // Act
            act.Should().ThrowExactly <StackOverflowException>().And.Message.Should().Be("XXX overflow");
            logger.AssertNoOutputMessages();
        }
Beispiel #9
0
        async public Task CallSucceeds()
        {
            // Arrange
            var testLogger = new TestLogger();

            // Act
            var result = await WebServiceHelper.SafeServiceCallAsync <bool>(async() => true,
                                                                            testLogger).ConfigureAwait(false);

            // Assert
            result.Should().BeTrue();
            testLogger.AssertNoOutputMessages();
        }
        public void Execute_ServiceCalled()
        {
            var logger = new TestLogger(logToConsole: true);
            var toolwindowServiceMock = new Mock <IToolWindowService>();

            var testSubject = new ShowToolWindowCommand(ValidCommandId, ValidToolWindowId, toolwindowServiceMock.Object, Mock.Of <IMenuCommandService>(), logger);

            // Act
            testSubject.Execute(null, null);

            toolwindowServiceMock.Verify(x => x.Show(ValidToolWindowId), Times.Once);
            logger.AssertNoOutputMessages();
        }
Beispiel #11
0
        public void CriticalException_IsNotSuppressed()
        {
            // Arrange
            var    testLogger = new TestLogger();
            Action act        = () => WebServiceHelper.SafeServiceCallAsync(
                () => throw new StackOverflowException("should be suppressed"), testLogger).Wait();

            // Act
            act.Should().ThrowExactly <AggregateException>()
            .And.InnerException.Should().BeOfType <StackOverflowException>();

            // Assert
            testLogger.AssertNoOutputMessages();
        }
Beispiel #12
0
        public void Execute_ServiceCalled()
        {
            var logger = new TestLogger(logToConsole: true);
            var toolwindowServiceMock = new Mock <IToolWindowService>();

            var testSubject = new IssueVisualizationToolWindowCommand(toolwindowServiceMock.Object,
                                                                      Mock.Of <IMenuCommandService>(), Mock.Of <IVsMonitorSelection>(), logger);

            // Act
            testSubject.Execute(null, null);

            toolwindowServiceMock.Verify(x => x.Show(IssueVisualizationToolWindow.ToolWindowId), Times.Once);
            logger.AssertNoOutputMessages();
        }
        public void Execute_CriticalException_IsNotSuppressed()
        {
            var logger = new TestLogger(logToConsole: true);
            var toolwindowServiceMock = new Mock <IToolWindowService>();

            toolwindowServiceMock.Setup(x => x.Show(ValidToolWindowId)).Throws(new StackOverflowException("thrown by test"));

            var testSubject = new ShowToolWindowCommand(ValidCommandId, ValidToolWindowId, toolwindowServiceMock.Object, Mock.Of <IMenuCommandService>(), logger);

            // Act
            Action act = () => testSubject.Execute(null, null);

            act.Should().ThrowExactly <StackOverflowException>().And.Message.Should().Be("thrown by test");
            logger.AssertNoOutputMessages();
        }