@@ -989,13 +989,40 @@ public virtual async Task ListAddAsync_WithExpiration_SetsExpirationCorrectly()
989989 Assert . False ( await cache . ExistsAsync ( "list-past-exp-new" ) ) ;
990990 Assert . False ( ( await cache . GetListAsync < int > ( "list-past-exp-new" ) ) . HasValue ) ;
991991
992- // Past expiration on existing key: should return 0 and remove the key
992+ // Past expiration on existing key: should return 0 and only remove the values being added (not the whole key)
993993 Assert . Equal ( 1 , await cache . ListAddAsync ( "list-past-exp-existing" , [ 1 ] ) ) ;
994994 Assert . True ( await cache . ExistsAsync ( "list-past-exp-existing" ) ) ;
995995 result = await cache . ListAddAsync ( "list-past-exp-existing" , [ 2 ] , TimeSpan . FromSeconds ( - 1 ) ) ;
996996 Assert . Equal ( 0 , result ) ;
997- Assert . False ( await cache . ExistsAsync ( "list-past-exp-existing" ) ) ;
998- Assert . False ( ( await cache . GetListAsync < int > ( "list-past-exp-existing" ) ) . HasValue ) ;
997+ Assert . True ( await cache . ExistsAsync ( "list-past-exp-existing" ) ) ; // Key still exists!
998+ var existingList = await cache . GetListAsync < int > ( "list-past-exp-existing" ) ;
999+ Assert . True ( existingList . HasValue ) ;
1000+ Assert . Single ( existingList . Value ) ;
1001+ Assert . Contains ( 1 , existingList . Value ) ; // Item 1 still present
1002+
1003+ // Past expiration on existing key with multiple items: should only remove the values being added
1004+ Assert . Equal ( 1 , await cache . ListAddAsync ( "list-past-exp-multi" , [ 1 ] ) ) ;
1005+ Assert . Equal ( 1 , await cache . ListAddAsync ( "list-past-exp-multi" , [ 2 ] ) ) ;
1006+ Assert . Equal ( 2 , ( await cache . GetListAsync < int > ( "list-past-exp-multi" ) ) . Value . Count ) ;
1007+ // Add item 3 with negative expiration - should NOT delete existing items
1008+ result = await cache . ListAddAsync ( "list-past-exp-multi" , [ 3 ] , TimeSpan . FromSeconds ( - 1 ) ) ;
1009+ Assert . Equal ( 0 , result ) ;
1010+ Assert . True ( await cache . ExistsAsync ( "list-past-exp-multi" ) ) ; // Key still exists!
1011+ var multiList = await cache . GetListAsync < int > ( "list-past-exp-multi" ) ;
1012+ Assert . Equal ( 2 , multiList . Value . Count ) ; // Items 1 and 2 still present
1013+ Assert . Contains ( 1 , multiList . Value ) ;
1014+ Assert . Contains ( 2 , multiList . Value ) ;
1015+
1016+ // Past expiration removes existing item if it matches
1017+ Assert . Equal ( 1 , await cache . ListAddAsync ( "list-past-exp-remove" , [ 1 ] ) ) ;
1018+ Assert . Equal ( 1 , await cache . ListAddAsync ( "list-past-exp-remove" , [ 2 ] ) ) ;
1019+ result = await cache . ListAddAsync ( "list-past-exp-remove" , [ 1 ] , TimeSpan . FromSeconds ( - 1 ) ) ; // Remove item 1
1020+ Assert . Equal ( 0 , result ) ;
1021+ Assert . True ( await cache . ExistsAsync ( "list-past-exp-remove" ) ) ;
1022+ var removeList = await cache . GetListAsync < int > ( "list-past-exp-remove" ) ;
1023+ Assert . Single ( removeList . Value ) ;
1024+ Assert . Contains ( 2 , removeList . Value ) ; // Only item 2 remains
1025+ Assert . DoesNotContain ( 1 , removeList . Value ) ; // Item 1 was removed
9991026
10001027 // Zero expiration: should also be treated as expired
10011028 result = await cache . ListAddAsync ( "list-zero-exp" , [ 1 ] , TimeSpan . Zero ) ;
@@ -1039,6 +1066,7 @@ public virtual async Task ListAddAsync_WithExpiration_SetsExpirationCorrectly()
10391066 Assert . True ( cacheValue . HasValue ) ;
10401067 Assert . Single ( cacheValue . Value ) ;
10411068 Assert . Contains ( 3 , cacheValue . Value ) ;
1069+ Assert . DoesNotContain ( 2 , cacheValue . Value ) ; // Explicit verification item 2 expired
10421070
10431071 // Wait for second item to expire
10441072 await Task . Delay ( 100 ) ;
0 commit comments