Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Add Token Unit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
engineering87 committed Sep 27, 2024
1 parent 6c7db48 commit d17e4f8
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/PDNDClientAssertionGenerator.Tests/TokenUtilsTests.cs
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);
}
}
}

0 comments on commit d17e4f8

Please sign in to comment.