Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -18,6 +18,7 @@ using Microsoft.Extensions.Time.Testing;
|
||||
using StellaOps.Auth.Client;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Auth.Client.Tests;
|
||||
|
||||
/// <summary>
|
||||
@@ -31,7 +32,8 @@ public class StellaOpsTokenClientTests
|
||||
{
|
||||
#region Task 1: Token Issuance Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RequestPasswordToken_ReturnsResultAndCaches()
|
||||
{
|
||||
var timeProvider = new FakeTimeProvider(DateTimeOffset.Parse("2025-02-01T00:00:00Z"));
|
||||
@@ -76,7 +78,8 @@ public class StellaOpsTokenClientTests
|
||||
Assert.Empty(jwks.Keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RequestClientCredentialsToken_ReturnsTokenWithCorrectExpiry()
|
||||
{
|
||||
// Arrange
|
||||
@@ -121,7 +124,8 @@ public class StellaOpsTokenClientTests
|
||||
Assert.Equal(expectedExpiry, result.ExpiresAt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RequestClientCredentialsToken_WithCustomScope_UsesCustomScope()
|
||||
{
|
||||
// Arrange
|
||||
@@ -160,7 +164,8 @@ public class StellaOpsTokenClientTests
|
||||
Assert.Contains("policy.evaluate", result.Scopes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RequestClientCredentialsToken_WithoutClientId_ThrowsInvalidOperation()
|
||||
{
|
||||
// Arrange
|
||||
@@ -186,7 +191,8 @@ public class StellaOpsTokenClientTests
|
||||
client.RequestClientCredentialsTokenAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RequestPasswordToken_WithAdditionalParameters_IncludesParameters()
|
||||
{
|
||||
// Arrange
|
||||
@@ -237,7 +243,8 @@ public class StellaOpsTokenClientTests
|
||||
|
||||
#region Task 2: Token Validation/Rejection Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RequestPasswordToken_WhenServerReturnsError_ThrowsInvalidOperation()
|
||||
{
|
||||
// Arrange
|
||||
@@ -278,7 +285,8 @@ public class StellaOpsTokenClientTests
|
||||
Assert.Contains("401", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RequestPasswordToken_WhenResponseMissingAccessToken_ThrowsInvalidOperation()
|
||||
{
|
||||
// Arrange
|
||||
@@ -313,7 +321,8 @@ public class StellaOpsTokenClientTests
|
||||
Assert.Contains("access_token", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CachedToken_WhenExpired_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
@@ -338,7 +347,8 @@ public class StellaOpsTokenClientTests
|
||||
// The cache may have already evicted it or it won't be returned
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RequestPasswordToken_DefaultsToBearer_WhenTokenTypeNotProvided()
|
||||
{
|
||||
// Arrange
|
||||
@@ -375,7 +385,8 @@ public class StellaOpsTokenClientTests
|
||||
Assert.Equal("Bearer", result.TokenType); // Defaults to Bearer
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RequestPasswordToken_DefaultsTo3600ExpiresIn_WhenNotProvided()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user