-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
478 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 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 System; | ||
using SonarLint.VisualStudio.SLCore.Common.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Common; | ||
|
||
[TestClass] | ||
public class TokenDtoTests | ||
{ | ||
[TestMethod] | ||
public void Ctor_SetsPropertiesCorrectly() | ||
{ | ||
var token = "token123"; | ||
|
||
var testSubject = new TokenDto(token); | ||
|
||
testSubject.token.Should().BeSameAs(token); | ||
} | ||
|
||
[TestMethod] | ||
public void Ctor_NullParameter_Throws() | ||
{ | ||
Action act = () => new TokenDto(null); | ||
|
||
act.Should().ThrowExactly<ArgumentNullException>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 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 System; | ||
using SonarLint.VisualStudio.SLCore.Common.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Common; | ||
|
||
[TestClass] | ||
public class UserAndPasswordDtoTests | ||
{ | ||
[TestMethod] | ||
public void Ctor_SetsPropertiesCorrectly() | ||
{ | ||
var username = "user123"; | ||
var password = "password123"; | ||
|
||
var testSubject = new UsernamePasswordDto(username, password); | ||
|
||
testSubject.username.Should().BeSameAs(username); | ||
testSubject.password.Should().BeSameAs(password); | ||
} | ||
|
||
[TestMethod] | ||
public void Ctor_NullParameter_Throws() | ||
{ | ||
Action actUsr = () => new UsernamePasswordDto(null, "password123"); | ||
Action actPwd = () => new UsernamePasswordDto("user123", null); | ||
|
||
actUsr.Should().ThrowExactly<ArgumentNullException>(); | ||
actPwd.Should().ThrowExactly<ArgumentNullException>(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/SLCore.UnitTests/Listener/Credentials/CredentialsListenerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 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 System; | ||
using System.Threading.Tasks; | ||
using SonarLint.VisualStudio.SLCore.Core; | ||
using SonarLint.VisualStudio.SLCore.Listener.Credentials; | ||
using SonarLint.VisualStudio.TestInfrastructure; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Listener.Credentials; | ||
|
||
[TestClass] | ||
public class CredentialsListenerTests | ||
{ | ||
[TestMethod] | ||
public void MefCtor_CheckIsExported() | ||
{ | ||
MefTestHelpers.CheckTypeCanBeImported<CredentialsListener, ISLCoreListener>(); | ||
} | ||
|
||
[TestMethod] | ||
public void MefCtor_CheckIsSingleton() | ||
{ | ||
MefTestHelpers.CheckIsSingletonMefComponent<CredentialsListener>(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetCredentialsAsync_StubImpl_ReturnsNoCredentials() | ||
{ | ||
var testSubject = CreateTestSubject(); | ||
|
||
var response = await testSubject.GetCredentialsAsync(new GetCredentialsParams($"randomstring-{Guid.NewGuid()}")); | ||
|
||
response.Should().BeSameAs(GetCredentialsResponse.NoCredentials); | ||
} | ||
|
||
private CredentialsListener CreateTestSubject() | ||
{ | ||
return new CredentialsListener(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/SLCore.UnitTests/Listener/Credentials/GetCredentialsParamsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 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.Listener.Credentials; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Listener.Credentials; | ||
|
||
[TestClass] | ||
public class GetCredentialsParamsTests | ||
{ | ||
[TestMethod] | ||
public void DeserializeObject_DeserializesCorrectly() | ||
{ | ||
var str = """{"connectionId":"id123"}"""; | ||
|
||
var result = JsonConvert.DeserializeObject<GetCredentialsParams>(str); | ||
|
||
result.connectionId.Should().Be("id123"); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/SLCore.UnitTests/Listener/Credentials/GetCredentialsResponseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 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 System; | ||
using Newtonsoft.Json; | ||
using SonarLint.VisualStudio.SLCore.Common.Models; | ||
using SonarLint.VisualStudio.SLCore.Listener.Credentials; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Listener.Credentials; | ||
|
||
[TestClass] | ||
public class GetCredentialsResponseTests | ||
{ | ||
[TestMethod] | ||
public void SerializeObject_ResponseWithToken_SerializedCorrectly() | ||
{ | ||
var testSubject = new GetCredentialsResponse(new TokenDto("token123")); | ||
|
||
var serializeObject = JsonConvert.SerializeObject(testSubject); | ||
serializeObject.Should().Be("""{"credentials":{"token":"token123"}}"""); | ||
} | ||
|
||
[TestMethod] | ||
public void Ctor_ResponseWithToken_CredentialsSetCorrectly() | ||
{ | ||
var tokenDto = new TokenDto("token123"); | ||
var testSubject = new GetCredentialsResponse(tokenDto); | ||
|
||
testSubject.credentials.Left.Should().BeSameAs(tokenDto); | ||
testSubject.credentials.Right.Should().BeNull(); | ||
} | ||
|
||
[TestMethod] | ||
public void Ctor_NullTokenDto_Throws() | ||
{ | ||
Action act = () => new GetCredentialsResponse(token: null); | ||
|
||
act.Should().ThrowExactly<ArgumentNullException>(); | ||
} | ||
|
||
[TestMethod] | ||
public void SerializeObject_ResponseWithUserAndPassword_SerializedCorrectly() | ||
{ | ||
var testSubject = new GetCredentialsResponse(new UsernamePasswordDto("user123", "password123")); | ||
|
||
var serializeObject = JsonConvert.SerializeObject(testSubject); | ||
serializeObject.Should().Be("""{"credentials":{"username":"user123","password":"password123"}}"""); | ||
} | ||
|
||
[TestMethod] | ||
public void Ctor_ResponseWithUserAndPassword_CredentialsSetCorrectly() | ||
{ | ||
var usernamePasswordDto = new UsernamePasswordDto("user123", "password123"); | ||
var testSubject = new GetCredentialsResponse(usernamePasswordDto); | ||
|
||
testSubject.credentials.Right.Should().BeSameAs(usernamePasswordDto); | ||
testSubject.credentials.Left.Should().BeNull(); | ||
} | ||
|
||
[TestMethod] | ||
public void Ctor_NullUserAndPasswordDto_Throws() | ||
{ | ||
Action act = () => new GetCredentialsResponse(usernamePassword: null); | ||
|
||
act.Should().ThrowExactly<ArgumentNullException>(); | ||
} | ||
|
||
[TestMethod] | ||
public void Ctor_NoCredentials_HasNullCredentialsProperty() | ||
{ | ||
GetCredentialsResponse.NoCredentials.credentials.Should().BeNull(); | ||
} | ||
|
||
[TestMethod] | ||
public void ResponseWithNoCredentials_SerializedCorrectly() | ||
{ | ||
JsonConvert.SerializeObject(GetCredentialsResponse.NoCredentials).Should().Be("""{"credentials":null}"""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 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 System; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Common.Models | ||
{ | ||
public class TokenDto | ||
{ | ||
public TokenDto(string token) | ||
{ | ||
this.token = token ?? throw new ArgumentNullException(nameof(token)); | ||
} | ||
|
||
public string token { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 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 System; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Common.Models | ||
{ | ||
public class UsernamePasswordDto | ||
{ | ||
public UsernamePasswordDto(string username, string password) | ||
{ | ||
this.username = username ?? throw new ArgumentNullException(nameof(username)); | ||
this.password = password ?? throw new ArgumentNullException(nameof(password)); | ||
} | ||
|
||
public string username { get; } | ||
public string password { get; } | ||
} | ||
} |
Oops, something went wrong.