@@ -85,6 +85,74 @@ await _cache.Received(1).SetAsync(
8585 opts . SkipDistributedCacheReadWhenStale == false ) ) ;
8686 }
8787
88+ [ Fact ]
89+ public async Task GetAsync_WithValidGrant_ReturnsGrant ( )
90+ {
91+ // Arrange
92+ var grant = CreateTestGrant ( "valid-key" , expiration : DateTime . UtcNow . AddMinutes ( 5 ) ) ;
93+ _cache . TryGetAsync < PersistedGrant > ( "valid-key" )
94+ . Returns ( MaybeValue < PersistedGrant > . FromValue ( grant ) ) ;
95+
96+ // Act
97+ var result = await _sut . GetAsync ( "valid-key" ) ;
98+
99+ // Assert
100+ Assert . NotNull ( result ) ;
101+ Assert . Equal ( "valid-key" , result . Key ) ;
102+ Assert . Equal ( "authorization_code" , result . Type ) ;
103+ Assert . Equal ( "test-subject" , result . SubjectId ) ;
104+ await _cache . DidNotReceive ( ) . RemoveAsync ( Arg . Any < string > ( ) ) ;
105+ }
106+
107+ [ Fact ]
108+ public async Task GetAsync_WithNonExistentKey_ReturnsNull ( )
109+ {
110+ // Arrange
111+ _cache . TryGetAsync < PersistedGrant > ( "nonexistent-key" )
112+ . Returns ( MaybeValue < PersistedGrant > . None ) ;
113+
114+ // Act
115+ var result = await _sut . GetAsync ( "nonexistent-key" ) ;
116+
117+ // Assert
118+ Assert . Null ( result ) ;
119+ await _cache . DidNotReceive ( ) . RemoveAsync ( Arg . Any < string > ( ) ) ;
120+ }
121+
122+ [ Fact ]
123+ public async Task GetAsync_WithExpiredGrant_RemovesAndReturnsNull ( )
124+ {
125+ // Arrange
126+ var expiredGrant = CreateTestGrant ( "expired-key" , expiration : DateTime . UtcNow . AddMinutes ( - 1 ) ) ;
127+ _cache . TryGetAsync < PersistedGrant > ( "expired-key" )
128+ . Returns ( MaybeValue < PersistedGrant > . FromValue ( expiredGrant ) ) ;
129+
130+ // Act
131+ var result = await _sut . GetAsync ( "expired-key" ) ;
132+
133+ // Assert
134+ Assert . Null ( result ) ;
135+ await _cache . Received ( 1 ) . RemoveAsync ( "expired-key" ) ;
136+ }
137+
138+ [ Fact ]
139+ public async Task GetAsync_WithNoExpiration_ReturnsGrant ( )
140+ {
141+ // Arrange
142+ var grant = CreateTestGrant ( "no-expiry-key" , expiration : null ) ;
143+ _cache . TryGetAsync < PersistedGrant > ( "no-expiry-key" )
144+ . Returns ( MaybeValue < PersistedGrant > . FromValue ( grant ) ) ;
145+
146+ // Act
147+ var result = await _sut . GetAsync ( "no-expiry-key" ) ;
148+
149+ // Assert
150+ Assert . NotNull ( result ) ;
151+ Assert . Equal ( "no-expiry-key" , result . Key ) ;
152+ Assert . Null ( result . Expiration ) ;
153+ await _cache . DidNotReceive ( ) . RemoveAsync ( Arg . Any < string > ( ) ) ;
154+ }
155+
88156 [ Fact ]
89157 public async Task RemoveAsync_RemovesGrantFromCache ( )
90158 {
0 commit comments