public void QualityProfileBackgroundProcessor_BackgroundTask_SameTimestampDifferentProfile_RequiresUpdate() { // Setup string qpKey = "Profile1"; var testSubject = this.GetTestSubject(); this.SetFilteredProjects(Language.CSharp, Language.CSharp); this.bindingSerializer.CurrentBinding = new BoundSonarQubeProject { ServerUri = new Uri("http://server"), ProjectKey = "ProjectKey", Profiles = new Dictionary <Language, ApplicableQualityProfile>() }; DateTime sameTimestamp = DateTime.Now; this.bindingSerializer.CurrentBinding.Profiles[Language.CSharp] = new ApplicableQualityProfile { ProfileKey = SonarQubeServiceWrapper.GetServerLanguageKey(Language.CSharp) + "Old", // Different profile key ProfileTimestamp = sameTimestamp }; this.ConfigureValidSonarQubeServiceWrapper(this.bindingSerializer.CurrentBinding, sameTimestamp, qpKey, Language.CSharp); // Act + Verify VerifyBackgroundExecution(true, testSubject, Strings.SonarLintProfileCheck, Strings.SonarLintProfileCheckDifferentProfile); }
public async Task SonarQubeServiceWrapper_DownloadQualityProfile_ProjectWithAnalysis() { using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider)) { // Setup HttpClient httpClient = testSubject.CreateHttpClient(); var language = Language.CSharp; QualityProfile expectedProfile = CreateRandomQualityProfile(language); var project = new ProjectInformation { Key = "awesome1", Name = "My Awesome Project" }; ConfigureValidConnection(testSubject, new[] { project }); // Setup test server RegisterQualityProfileQueryValidator(testSubject); RequestHandler handler = testSubject.RegisterRequestHandler( SonarQubeServiceWrapper.CreateQualityProfileUrl(language, project), ctx => ServiceQualityProfiles(ctx, new[] { expectedProfile }) ); // Act QualityProfile actualProfile = await SonarQubeServiceWrapper.DownloadQualityProfile(httpClient, project, language, CancellationToken.None); // Verify Assert.IsNotNull(actualProfile, "Expected a quality profile"); Assert.AreEqual(expectedProfile.Key, actualProfile.Key, "Unexpected quality profile returned"); handler.AssertHandlerCalled(1); } }
public void LatestServer_APICompatibility() { // Setup the service used to interact with SQ var s = new SonarQubeServiceWrapper(this.serviceProvider); var connection = new ConnectionInformation(new Uri("http://nemo.sonarqube.org")); // Step 1: Connect anonymously ProjectInformation[] projects = null; RetryAction(() => s.TryGetProjects(connection, CancellationToken.None, out projects), "Get projects from SonarQube server"); Assert.AreNotEqual(0, projects.Length, "No projects were returned"); // Step 2: Get quality profile for the first project var project = projects.FirstOrDefault(); QualityProfile profile = null; RetryAction(() => s.TryGetQualityProfile(connection, project, Language.CSharp, CancellationToken.None, out profile), "Get quality profile from SonarQube server"); Assert.IsNotNull(profile, "No quality profile was returned"); // Step 3: Get quality profile export for the quality profile RoslynExportProfile export = null; RetryAction(() => s.TryGetExportProfile(connection, profile, Language.CSharp, CancellationToken.None, out export), "Get quality profile export from SonarQube server"); Assert.IsNotNull(export, "No quality profile export was returned"); // Errors are logged to output window pane and we don't expect any this.outputWindowPane.AssertOutputStrings(0); }
public void LatestServer_APICompatibility() { // Arrange the service used to interact with SQ var s = new SonarQubeServiceWrapper(this.serviceProvider); var connection = new ConnectionInformation(new Uri("https://sonarqube.com")); // Step 1: Connect anonymously ProjectInformation[] projects = null; RetryAction(() => s.TryGetProjects(connection, CancellationToken.None, out projects), "Get projects from SonarQube server"); projects.Should().NotBeEmpty("No projects were returned"); // Step 2: Get quality profile for the first project var project = projects.FirstOrDefault(); QualityProfile profile = null; RetryAction(() => s.TryGetQualityProfile(connection, project, Language.CSharp, CancellationToken.None, out profile), "Get quality profile from SonarQube server"); profile.Should().NotBeNull("No quality profile was returned"); // Step 3: Get quality profile export for the quality profile RoslynExportProfile export = null; RetryAction(() => s.TryGetExportProfile(connection, profile, Language.CSharp, CancellationToken.None, out export), "Get quality profile export from SonarQube server"); export.Should().NotBeNull("No quality profile export was returned"); // Errors are logged to output window pane and we don't expect any this.outputWindowPane.AssertOutputStrings(0); }
private void SonarQubeServiceWrapper_TryGetExportProfile(Language language) { using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider)) { // Setup QualityProfile profile = CreateRandomQualityProfile(language); var project = new ProjectInformation { Key = "awesome1", Name = "My Awesome Project" }; var expectedExport = RoslynExportProfileHelper.CreateExport(ruleSet: TestRuleSetHelper.CreateTestRuleSet(3)); var roslynExporter = SonarQubeServiceWrapper.CreateRoslynExporterName(language); ConnectionInformation conn = ConfigureValidConnection(testSubject, new[] { project }); // Setup test server RegisterProfileExportQueryValidator(testSubject); RequestHandler getExportHandler = testSubject.RegisterRequestHandler( SonarQubeServiceWrapper.CreateQualityProfileExportUrl(profile, language, roslynExporter), ctx => ServiceProfileExport(ctx, expectedExport) ); // Act RoslynExportProfile actualExport; Assert.IsTrue(testSubject.TryGetExportProfile(conn, profile, language, CancellationToken.None, out actualExport), "TryGetExportProfile failed unexpectedly"); // Verify Assert.IsNotNull(actualExport, "Expected a profile export to be returned"); RoslynExportProfileHelper.AssertAreEqual(expectedExport, actualExport); getExportHandler.AssertHandlerCalled(1); } }
private static QualityProfile CreateRandomQualityProfile(Language language, bool isDefault = false) { var languageKey = SonarQubeServiceWrapper.GetServerLanguageKey(language); return(new QualityProfile { Key = Guid.NewGuid().ToString("N"), Language = languageKey, IsDefault = isDefault }); }
public void SonarQubeServiceWrapper_CreateRequestUrl_HostNameAndPathBaseAddress() { // Act var result = SonarQubeServiceWrapper.CreateRequestUrl( client: CreateClientWithAddress("http://hostname/and/path/"), apiUrl: "foo/bar/baz"); // Verify Assert.AreEqual("http://hostname/and/path/foo/bar/baz", result.ToString(), "Unexpected request URL for base address with host name and path"); }
public void SonarQubeServiceWrapper_TryGetProperties_ArgChecks() { // Setup var testSubject = new SonarQubeServiceWrapper(this.serviceProvider); ServerProperty[] properties; // Act + Verify Exceptions.Expect <ArgumentNullException>(() => testSubject.TryGetProperties(null, CancellationToken.None, out properties)); }
public void SonarQubeServiceWrapper_AppendQuery_MultipleQueryParameters_ReturnsCorrectQueryString() { // Act var result = SonarQubeServiceWrapper.AppendQueryString( urlBase: "api/foobar", queryFormat: "?a={0}&b={2}&c={1}", args: new[] { "1", "3", "2" }); // Verify Assert.AreEqual("api/foobar?a=1&b=2&c=3", result); }
private QualityProfile ConfigureProfileExport(RoslynExportProfile export, Language language) { var profile = new QualityProfile { Language = SonarQubeServiceWrapper.GetServerLanguageKey(language) }; this.sonarQubeService.ReturnProfile[language] = profile; this.sonarQubeService.ReturnExport[profile] = export; return(profile); }
public void SonarQubeServiceWrapper_TryGetQualityProfile_FullFunctionality() { using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider)) { // Setup Language language = Language.CSharp; QualityProfile profile = CreateRandomQualityProfile(language); var project = new ProjectInformation { Key = "awesome1", Name = "My Awesome Project" }; var changeLog = new QualityProfileChangeLog { Page = 1, PageSize = 1, Total = 1, Events = new QualityProfileChangeLogEvent[] { new QualityProfileChangeLogEvent { Date = DateTime.Now } } }; ConnectionInformation conn = ConfigureValidConnection(testSubject, new[] { project }); // Setup test server RegisterQualityProfileChangeLogValidator(testSubject); RequestHandler getProfileHandler = testSubject.RegisterRequestHandler( SonarQubeServiceWrapper.CreateQualityProfileUrl(language, project), ctx => ServiceQualityProfiles(ctx, new[] { profile }) ); RequestHandler changeLogHandler = testSubject.RegisterRequestHandler( SonarQubeServiceWrapper.CreateQualityProfileChangeLogUrl(profile), ctx => ServiceChangeLog(ctx, changeLog) ); // Act QualityProfile actualProfile; Assert.IsTrue(testSubject.TryGetQualityProfile(conn, project, language, CancellationToken.None, out actualProfile), "TryGetExportProfile failed unexpectedly"); // Verify Assert.IsNotNull(actualProfile, "Expected a profile to be returned"); Assert.AreEqual(profile.Key, actualProfile.Key); Assert.AreEqual(profile.Name, actualProfile.Name); Assert.AreEqual(changeLog.Events[0].Date, actualProfile.QualityProfileTimestamp); getProfileHandler.AssertHandlerCalled(1); changeLogHandler.AssertHandlerCalled(1); this.outputWindowPane.AssertOutputStrings(0); } }
public void SonarQubeServiceWrapper_CreateProjectDashboardUrl_ArgChecks() { // Setup var testSubject = new SonarQubeServiceWrapper(this.serviceProvider); var connectionInfo = new ConnectionInformation(new Uri("http://my-sonar-server:5555")); var projectInfo = new ProjectInformation { Key = "p1" }; // Act + Verify Exceptions.Expect <ArgumentNullException>(() => testSubject.CreateProjectDashboardUrl(null, projectInfo)); Exceptions.Expect <ArgumentNullException>(() => testSubject.CreateProjectDashboardUrl(connectionInfo, null)); }
public void SonarQubeServiceWrapper_TryGetQualityProfile_ArgChecks() { // Setup var testSubject = new SonarQubeServiceWrapper(this.serviceProvider); QualityProfile profile; var validConnection = new ConnectionInformation(new Uri("http://valid")); var validProject = new ProjectInformation(); var validLanguage = Language.CSharp; var cppLanguage = new Language("Cpp", "C++", Guid.NewGuid()); // Act + Verify Exceptions.Expect <ArgumentNullException>(() => testSubject.TryGetQualityProfile(null, validProject, validLanguage, CancellationToken.None, out profile)); Exceptions.Expect <ArgumentNullException>(() => testSubject.TryGetQualityProfile(validConnection, null, validLanguage, CancellationToken.None, out profile)); Exceptions.Expect <ArgumentNullException>(() => testSubject.TryGetQualityProfile(validConnection, validProject, null, CancellationToken.None, out profile)); Exceptions.Expect <ArgumentOutOfRangeException>(() => testSubject.TryGetQualityProfile(validConnection, validProject, cppLanguage, CancellationToken.None, out profile)); this.outputWindowPane.AssertOutputStrings(0); }
public void SonarQubeServiceWrapper_CreateProjectDashboardUrl() { // Setup var testSubject = new SonarQubeServiceWrapper(this.serviceProvider); var serverUrl = new Uri("http://my-sonar-server:5555"); var connectionInfo = new ConnectionInformation(serverUrl); var projectInfo = new ProjectInformation { Key = "p1" }; Uri expectedUrl = new Uri("http://my-sonar-server:5555/dashboard/index/p1"); // Act var actualUrl = testSubject.CreateProjectDashboardUrl(connectionInfo, projectInfo); // Verify Assert.AreEqual(expectedUrl, actualUrl, "Unexpected project dashboard URL"); }
private void ConfigureValidSonarQubeServiceWrapper(BoundSonarQubeProject binding, DateTime?timestamp, string qualityProfileKey, params Language[] expectedLanguageProfiles) { var sqService = new ConfigurableSonarQubeServiceWrapper(); this.host.SonarQubeService = sqService; sqService.AllowConnections = true; sqService.ExpectedConnection = binding.CreateConnectionInformation(); sqService.ExpectedProjectKey = binding.ProjectKey; foreach (Language language in expectedLanguageProfiles) { sqService.ReturnProfile[language] = new QualityProfile { Key = qualityProfileKey, Language = SonarQubeServiceWrapper.GetServerLanguageKey(language), QualityProfileTimestamp = timestamp }; } }
public void SonarQubeServiceWrapper_CreateRequestUrl_LeadingAndTrailingSlashes() { using (new AssertIgnoreScope()) { // Test case 1: base => no slash; api => with slash // Act var result1 = SonarQubeServiceWrapper.CreateRequestUrl( client: CreateClientWithAddress("http://localhost/no/trailing/slash"), apiUrl: "/has/starting/slash"); // Verify Assert.AreEqual("http://localhost/no/trailing/slash/has/starting/slash", result1.ToString()); // Test case 2: base => with slash; api => no slash // Act var result2 = SonarQubeServiceWrapper.CreateRequestUrl( client: CreateClientWithAddress("http://localhost/with/trailing/slash/"), apiUrl: "no/starting/slash"); // Verify Assert.AreEqual("http://localhost/with/trailing/slash/no/starting/slash", result2.ToString()); // Test case 3: base => no slash; api => no slash // Act var result3 = SonarQubeServiceWrapper.CreateRequestUrl( client: CreateClientWithAddress("http://localhost/no/trailing/slash"), apiUrl: "no/starting/slash"); // Verify Assert.AreEqual("http://localhost/no/trailing/slash/no/starting/slash", result3.ToString()); // Test case 3: base => with slash; api => with slash // Act var result4 = SonarQubeServiceWrapper.CreateRequestUrl( client: CreateClientWithAddress("http://localhost/with/trailing/slash/"), apiUrl: "/with/starting/slash"); // Verify Assert.AreEqual("http://localhost/with/trailing/slash/with/starting/slash", result4.ToString()); } }
private void SonarQubeServiceWrapper_TryGetQualityProfile_ReducedFunctionality(Language language) { using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider)) { // Setup QualityProfile profile = CreateRandomQualityProfile(language); var project = new ProjectInformation { Key = "awesome1", Name = "My Awesome Project" }; ConnectionInformation conn = ConfigureValidConnection(testSubject, new[] { project }); // Setup test server RegisterQualityProfileChangeLogValidator(testSubject); RequestHandler getProfileHandler = testSubject.RegisterRequestHandler( SonarQubeServiceWrapper.CreateQualityProfileUrl(language, project), ctx => ServiceQualityProfiles(ctx, new[] { profile }) ); RequestHandler changeLogHandler = testSubject.RegisterRequestHandler( SonarQubeServiceWrapper.CreateQualityProfileChangeLogUrl(profile), ctx => ServiceChangeLog(ctx, null, simulateFault: true) ); // Act QualityProfile actualProfile; Assert.IsTrue(testSubject.TryGetQualityProfile(conn, project, language, CancellationToken.None, out actualProfile), "TryGetExportProfile failed unexpectedly"); // Verify Assert.IsNotNull(actualProfile, "Expected a profile to be returned"); Assert.AreEqual(profile.Key, actualProfile.Key); Assert.AreEqual(profile.Name, actualProfile.Name); Assert.IsNull(actualProfile.QualityProfileTimestamp); getProfileHandler.AssertHandlerCalled(1); changeLogHandler.AssertHandlerCalled(1); this.outputWindowPane.AssertOutputStrings(1); } }
public void QualityProfileBackgroundProcessor_BackgroundTask_ServiceErrors_DoesNotRequireUpdate() { // Setup var testSubject = this.GetTestSubject(); this.SetFilteredProjects(Language.VBNET, Language.VBNET); this.bindingSerializer.CurrentBinding = new BoundSonarQubeProject { ServerUri = new Uri("http://server"), ProjectKey = "ProjectKey", Profiles = new Dictionary <Language, ApplicableQualityProfile>() }; this.bindingSerializer.CurrentBinding.Profiles[Language.VBNET] = new ApplicableQualityProfile { ProfileKey = SonarQubeServiceWrapper.GetServerLanguageKey(Language.VBNET), ProfileTimestamp = DateTime.Now }; this.ConfigureSonarQubeServiceWrapperWithServiceError(); // Act + Verify VerifyBackgroundExecution(false, testSubject, Strings.SonarLintProfileCheck, Strings.SonarLintProfileCheckFailed); }
public VsSessionHost([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, SonarQubeServiceWrapper sonarQubeService, IActiveSolutionTracker solutionTacker) : this(serviceProvider, null, null, sonarQubeService, solutionTacker, Dispatcher.CurrentDispatcher) { Debug.Assert(ThreadHelper.CheckAccess(), "Expected to be created on the UI thread"); }
public void SonarQubeServiceWrapper_AppendQuery_NoQueryParameters_ReturnsBaseUrl() { // Act + Verify Assert.AreEqual("api/foobar", SonarQubeServiceWrapper.AppendQueryString("api/foobar", "")); }