Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Feb 4, 2025
1 parent 2b0afa6 commit 92bcf82
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/SLCore.IntegrationTests/InitializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public void Serialize_WithSonarCloudToken_AsExpected()
"organization": "my-org",
"credentials": {
"token": "super-secret-token"
}
},
"region": "EU"
}
}
""";
Expand Down Expand Up @@ -131,7 +132,8 @@ public void Serialize_WithSonarCloudUsernamePassword_AsExpected()
"credentials": {
"username": "[email protected]",
"password": "betwEEn-me-and-U"
}
},
"region": "EU"
}
}
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public void Serialize_WithSonarCloudToken_AsExpected()
"organization": "my-org",
"credentials": {
"token": "super-secret-token"
}
},
"region": "EU"
},
"projectKeys": [
"project-key-1",
Expand Down Expand Up @@ -149,7 +150,8 @@ public void Serialize_WithSonarCloudUsernamePassword_AsExpected()
"credentials": {
"username": "[email protected]",
"password": "betwEEn-me-and-U"
}
},
"region": "EU"
},
"projectKeys": [
"project-key-1",
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<TokenDto, UsernamePasswordDto>.CreateLeft(new TokenDto("myToken")), region));

var serializedString = JsonConvert.SerializeObject(testSubject, Formatting.Indented);

serializedString.Should().Be(expectedString);
}
}

0 comments on commit 92bcf82

Please sign in to comment.