This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c7db48
commit d17e4f8
Showing
1 changed file
with
62 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,62 @@ | ||
// (c) 2024 Francesco Del Re <francesco.delre.87@gmail.com> | ||
// This code is licensed under MIT license (see LICENSE.txt for details) | ||
using PDNDClientAssertionGenerator.Utils; | ||
|
||
namespace PDNDClientAssertionGenerator.Tests | ||
{ | ||
public class TokenUtilsTests | ||
{ | ||
[Fact] | ||
public void ExtractAccessToken_ShouldReturnAccessToken_WhenValidJsonResponseIsProvided() | ||
{ | ||
// Arrange | ||
string jsonResponse = "{\"access_token\": \"abc123\", \"expires_in\": 3600}"; | ||
string expectedAccessToken = "abc123"; | ||
|
||
// Act | ||
string actualAccessToken = TokenUtils.ExtractAccessToken(jsonResponse); | ||
|
||
// Assert | ||
Assert.Equal(expectedAccessToken, actualAccessToken); | ||
} | ||
|
||
[Fact] | ||
public void ExtractAccessToken_ShouldReturnEmptyString_WhenAccessTokenIsMissing() | ||
{ | ||
// Arrange | ||
string jsonResponse = "{\"expires_in\": 3600}"; | ||
|
||
// Act | ||
string actualAccessToken = TokenUtils.ExtractAccessToken(jsonResponse); | ||
|
||
// Assert | ||
Assert.Equal(string.Empty, actualAccessToken); | ||
} | ||
|
||
[Fact] | ||
public void ExtractAccessToken_ShouldReturnEmptyString_WhenJsonIsInvalid() | ||
{ | ||
// Arrange | ||
string invalidJsonResponse = "{\"access_token\": \"abc123\", \"expires_in\": }"; // Invalid JSON | ||
|
||
// Act | ||
string actualAccessToken = TokenUtils.ExtractAccessToken(invalidJsonResponse); | ||
|
||
// Assert | ||
Assert.Equal(string.Empty, actualAccessToken); | ||
} | ||
|
||
[Fact] | ||
public void ExtractAccessToken_ShouldReturnEmptyString_WhenAccessTokenIsNull() | ||
{ | ||
// Arrange | ||
string jsonResponse = "{\"access_token\": null}"; | ||
|
||
// Act | ||
string actualAccessToken = TokenUtils.ExtractAccessToken(jsonResponse); | ||
|
||
// Assert | ||
Assert.Equal(string.Empty, actualAccessToken); | ||
} | ||
} | ||
} |