Exemple #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));
        }
Exemple #2
0
        public async Task GetNotificationEventsAsync_ReturnsExpectedResult()
        {
            // Arrange
            var client = GetMockSqClientWithCredentialAndVersion("5.6");

            var expectedEvent = new NotificationsResponse
            {
                Category = "QUALITY_GATE",
                Link     = new Uri("http://foo.com"),
                Date     = new DateTimeOffset(2010, 1, 1, 14, 59, 59, TimeSpan.FromHours(2)),
                Message  = "foo",
                Project  = "test"
            };

            client
            .Setup(x => x.GetNotificationEventsAsync(It.IsAny <NotificationsRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Result.Ok(new[] { expectedEvent }));

            var service = new SonarQubeService(WrapInMockFactory(client));
            await service.ConnectAsync(new ConnectionInformation(new Uri("http://mysq.com")), CancellationToken.None);

            // Act
            var result = await service.GetNotificationEventsAsync("test", DateTimeOffset.Now, CancellationToken.None);

            // Assert
            client.VerifyAll();
            result.Should().NotBeNull();
            result.Should().HaveCount(1);

            result[0].Category.Should().Be(expectedEvent.Category);
            result[0].Link.Should().Be(expectedEvent.Link);
            result[0].Date.Should().Be(expectedEvent.Date);
            result[0].Message.Should().Be(expectedEvent.Message);
        }