示例#1
0
        public void ThrowWhenNotConnected()
        {
            // Arrange
            var client    = new Mock <ISonarQubeClient>();
            var sqService = new SonarQubeService(WrapInMockFactory(client));

            // Act & Assert
            AssertExceptionThrownWhenNotConnected(() =>
                                                  sqService.GetAllOrganizationsAsync(CancellationToken.None));

            AssertExceptionThrownWhenNotConnected(() =>
                                                  sqService.GetAllPluginsAsync(CancellationToken.None));

            AssertExceptionThrownWhenNotConnected(() =>
                                                  sqService.GetAllProjectsAsync("organizationKey", CancellationToken.None));

            AssertExceptionThrownWhenNotConnected(() =>
                                                  sqService.GetAllPropertiesAsync(CancellationToken.None));

            AssertExceptionThrownWhenNotConnected(() =>
            {
                sqService.GetProjectDashboardUrl("projectKey");
                return(Task.Delay(0));
            });

            AssertExceptionThrownWhenNotConnected(() =>
                                                  sqService.GetQualityProfileAsync("projectKey", "some org", SonarQubeLanguage.CSharp, CancellationToken.None));

            AssertExceptionThrownWhenNotConnected(() =>
                                                  sqService.GetRoslynExportProfileAsync("qualityProfileName", "some org", SonarQubeLanguage.CSharp, CancellationToken.None));

            AssertExceptionThrownWhenNotConnected(() =>
                                                  sqService.GetNotificationEventsAsync("projectKey", DateTimeOffset.Now, CancellationToken.None));
        }
示例#2
0
        public async Task GetAllPluginsAsync_ReturnsExpectedResult()
        {
            // Arrange
            var client = GetMockSqClientWithCredentialAndVersion("5.6");

            client
            .Setup(x => x.GetPluginsAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(Result.Ok(new[] { new PluginResponse {
                                                Key = "key", Version = "version"
                                            } }));

            var service = new SonarQubeService(WrapInMockFactory(client));

            await service.ConnectAsync(new ConnectionInformation(new Uri("http://mysq.com")), CancellationToken.None);

            // Act
            var result = await service.GetAllPluginsAsync(CancellationToken.None);

            // Assert
            client.VerifyAll();
            result.Should().NotBeNull();
            result.Should().HaveCount(1);
            result[0].Key.Should().Be("key");
            result[0].Version.Should().Be("version");
        }