diff --git a/src/SLCore.IntegrationTests/InitializationTests.cs b/src/SLCore.IntegrationTests/InitializationTests.cs index 10880a171..8ca55c66f 100644 --- a/src/SLCore.IntegrationTests/InitializationTests.cs +++ b/src/SLCore.IntegrationTests/InitializationTests.cs @@ -46,7 +46,8 @@ public async Task Sloop_StartedAndStoppedWithoutErrors() VerifyNoErrorsInLogs(testLogger); VerifyNoErrorsInLogs(slCoreErrorLogger); VerifyLogMessagesReceived(slCoreLogger); - slCoreLogger.AssertPartialOutputStringExists("SonarLint backend started"); + slCoreLogger.AssertPartialOutputStringExists("Telemetry disabled on server startup"); + slCoreLogger.AssertPartialOutputStringDoesNotExist("Internal error"); } [TestMethod] diff --git a/src/SLCore.UnitTests/Service/Connection/GetAllProjectsParamsTests.cs b/src/SLCore.UnitTests/Service/Connection/GetAllProjectsParamsTests.cs index dfadb7cd7..bf6a46020 100644 --- a/src/SLCore.UnitTests/Service/Connection/GetAllProjectsParamsTests.cs +++ b/src/SLCore.UnitTests/Service/Connection/GetAllProjectsParamsTests.cs @@ -102,7 +102,8 @@ public void Serialize_WithSonarCloudToken_AsExpected() "organization": "my-org", "credentials": { "token": "super-secret-token" - } + }, + "region": "EU" } } """; @@ -131,7 +132,8 @@ public void Serialize_WithSonarCloudUsernamePassword_AsExpected() "credentials": { "username": "jeff@thiscompany.com", "password": "betwEEn-me-and-U" - } + }, + "region": "EU" } } """; diff --git a/src/SLCore.UnitTests/Service/Connection/GetProjectNamesByKeyParamsTests.cs b/src/SLCore.UnitTests/Service/Connection/GetProjectNamesByKeyParamsTests.cs index 8c1ccc02d..75c83196d 100644 --- a/src/SLCore.UnitTests/Service/Connection/GetProjectNamesByKeyParamsTests.cs +++ b/src/SLCore.UnitTests/Service/Connection/GetProjectNamesByKeyParamsTests.cs @@ -115,7 +115,8 @@ public void Serialize_WithSonarCloudToken_AsExpected() "organization": "my-org", "credentials": { "token": "super-secret-token" - } + }, + "region": "EU" }, "projectKeys": [ "project-key-1", @@ -149,7 +150,8 @@ public void Serialize_WithSonarCloudUsernamePassword_AsExpected() "credentials": { "username": "jeff@thiscompany.com", "password": "betwEEn-me-and-U" - } + }, + "region": "EU" }, "projectKeys": [ "project-key-1", diff --git a/src/SLCore.UnitTests/Service/Connection/Models/SonarCloudConnectionConfigurationDtoTests.cs b/src/SLCore.UnitTests/Service/Connection/Models/SonarCloudConnectionConfigurationDtoTests.cs new file mode 100644 index 000000000..c7860f10f --- /dev/null +++ b/src/SLCore.UnitTests/Service/Connection/Models/SonarCloudConnectionConfigurationDtoTests.cs @@ -0,0 +1,73 @@ +/* + * SonarLint for Visual Studio + * Copyright (C) 2016-2025 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using Newtonsoft.Json; +using SonarLint.VisualStudio.SLCore.Service.Connection.Models; + +namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Connection.Models; + +[TestClass] +public class SonarCloudConnectionConfigurationDtoTests +{ + + [DataRow("id", true, "org", SonarCloudRegion.EU, """ + { + "organization": "org", + "region": "EU", + "connectionId": "id", + "disableNotification": true + } + """)] + [DataRow("id id id", true, "org", SonarCloudRegion.EU, """ + { + "organization": "org", + "region": "EU", + "connectionId": "id id id", + "disableNotification": true + } + """)] + [DataRow("id", false, "org", SonarCloudRegion.EU, """ + { + "organization": "org", + "region": "EU", + "connectionId": "id", + "disableNotification": false + } + """)] + [DataRow("id", true, "org org org", SonarCloudRegion.EU, """ + { + "organization": "org org org", + "region": "EU", + "connectionId": "id", + "disableNotification": true + } + """)] + [DataRow("id", true, "org", SonarCloudRegion.US, """ + { + "organization": "org", + "region": "US", + "connectionId": "id", + "disableNotification": true + } + """)] + [DataTestMethod] + public void Serialize_AsExpected(string id, bool notificationEnabled, string organization, SonarCloudRegion region, string expected) => + JsonConvert.SerializeObject(new SonarCloudConnectionConfigurationDto(id, notificationEnabled, organization, region), Formatting.Indented).Should().Be(expected); +} diff --git a/src/SLCore.UnitTests/Service/Connection/Models/TransientSonarCloudConnectionDtoTests.cs b/src/SLCore.UnitTests/Service/Connection/Models/TransientSonarCloudConnectionDtoTests.cs new file mode 100644 index 000000000..91662f4e9 --- /dev/null +++ b/src/SLCore.UnitTests/Service/Connection/Models/TransientSonarCloudConnectionDtoTests.cs @@ -0,0 +1,75 @@ +/* + * SonarLint for Visual Studio + * Copyright (C) 2016-2025 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using Newtonsoft.Json; +using SonarLint.VisualStudio.SLCore.Common.Models; +using SonarLint.VisualStudio.SLCore.Service.Connection.Models; + +namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Connection.Models; + +[TestClass] +public class TransientSonarCloudConnectionDtoTests +{ + [DataRow("my org", SonarCloudRegion.US, """ + { + "organization": "my org", + "credentials": { + "token": "abctoken" + }, + "region": "US" + } + """)] + [DataRow("my org two", SonarCloudRegion.EU, """ + { + "organization": "my org two", + "credentials": { + "token": "abctoken" + }, + "region": "EU" + } + """)] + [DataTestMethod] + public void Serialized_Token_AsExpected(string organization, SonarCloudRegion region, string expected) => + JsonConvert.SerializeObject(new TransientSonarCloudConnectionDto(organization, new TokenDto("abctoken"), region), Formatting.Indented).Should().Be(expected); + + [DataRow("my org", SonarCloudRegion.US, """ + { + "organization": "my org", + "credentials": { + "username": "usr", + "password": "pwd" + }, + "region": "US" + } + """)] + [DataRow("my org two", SonarCloudRegion.EU, """ + { + "organization": "my org two", + "credentials": { + "username": "usr", + "password": "pwd" + }, + "region": "EU" + } + """)] + [DataTestMethod] + public void Serialized_UsernameAndPassword_AsExpected(string organization, SonarCloudRegion region, string expected) => + JsonConvert.SerializeObject(new TransientSonarCloudConnectionDto(organization, new UsernamePasswordDto("usr", "pwd"), region), Formatting.Indented).Should().Be(expected); +} diff --git a/src/SLCore.UnitTests/Service/Connection/ValidateConnectionParamsTests.cs b/src/SLCore.UnitTests/Service/Connection/ValidateConnectionParamsTests.cs index c23deda61..bdb657ffc 100644 --- a/src/SLCore.UnitTests/Service/Connection/ValidateConnectionParamsTests.cs +++ b/src/SLCore.UnitTests/Service/Connection/ValidateConnectionParamsTests.cs @@ -116,37 +116,4 @@ public void Ctor_TransientSonarCloudConnectionDtoDtoWithToken_SerializeAsExpecte serializedString.Should().Be(expectedString); } - - - [DataRow(SonarCloudRegion.EU, """ - { - "transientConnection": { - "organization": "myOrg", - "credentials": { - "token": "myToken" - }, - "region": "EU" - } - } - """)] - [DataRow(SonarCloudRegion.US, """ - { - "transientConnection": { - "organization": "myOrg", - "credentials": { - "token": "myToken" - }, - "region": "US" - } - } - """)] - [DataTestMethod] - public void Ctor_TransientSonarCloudConnectionWithRegion_SerializeAsExpected(SonarCloudRegion region, string expectedString) - { - var testSubject = new ValidateConnectionParams(new TransientSonarCloudConnectionDto("myOrg", Either.CreateLeft(new TokenDto("myToken")), region)); - - var serializedString = JsonConvert.SerializeObject(testSubject, Formatting.Indented); - - serializedString.Should().Be(expectedString); - } }