@@ -13,7 +13,7 @@ public class ClientCacheTests
1313 [ Test ]
1414 public void CacheShouldCleanupWhenExceedsLimit ( )
1515 {
16- var clientCache = new ClientCache ( ) ;
16+ var clientCache = new ClientCache ( 100 ) ;
1717
1818 // Add 110 clients to trigger the cleanup.
1919 for ( int i = 0 ; i < 110 ; i ++ )
@@ -23,7 +23,7 @@ public void CacheShouldCleanupWhenExceedsLimit()
2323 }
2424
2525 var clientsField = typeof ( ClientCache ) . GetField ( "_clients" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
26- var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < IEquatable < object > , ClientEntry > ;
26+ var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < object , ClientEntry > ;
2727
2828 Assert . IsNotNull ( clients , "The _clients field is null." ) ;
2929 Assert . AreEqual ( 100 , clients ! . Count , "Cache did not cleanup correctly." ) ;
@@ -32,7 +32,7 @@ public void CacheShouldCleanupWhenExceedsLimit()
3232 [ Test ]
3333 public void CacheShouldNotCleanupWhenUnderLimit ( )
3434 {
35- var clientCache = new ClientCache ( ) ;
35+ var clientCache = new ClientCache ( 100 ) ;
3636
3737 // Add 50 clients, which is below the limit.
3838 for ( int i = 0 ; i < 50 ; i ++ )
@@ -42,7 +42,7 @@ public void CacheShouldNotCleanupWhenUnderLimit()
4242 }
4343
4444 var clientsField = typeof ( ClientCache ) . GetField ( "_clients" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
45- var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < IEquatable < object > , ClientEntry > ;
45+ var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < object , ClientEntry > ;
4646
4747 Assert . IsNotNull ( clients , "The _clients field is null." ) ;
4848 Assert . AreEqual ( 50 , clients ! . Count , "Cache should not have cleaned up when under the limit." ) ;
@@ -51,7 +51,7 @@ public void CacheShouldNotCleanupWhenUnderLimit()
5151 [ Test ]
5252 public void CacheShouldCleanupOldestClients ( )
5353 {
54- var clientCache = new ClientCache ( ) ;
54+ var clientCache = new ClientCache ( 100 ) ;
5555
5656 // Add 110 clients to trigger cleanup (exceeds _maxClients = 100)
5757 for ( int i = 0 ; i < 110 ; i ++ )
@@ -66,7 +66,7 @@ public void CacheShouldCleanupOldestClients()
6666 clientCache . GetClient ( new DummyClientKey ( "client1" ) , ( ) => new object ( ) ) ;
6767
6868 var clientsField = typeof ( ClientCache ) . GetField ( "_clients" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
69- var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < IEquatable < object > , ClientEntry > ;
69+ var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < object , ClientEntry > ;
7070
7171 Assert . IsNotNull ( clients , "The _clients field is null." ) ;
7272 Assert . AreEqual ( 100 , clients ! . Count , "Cache did not cleanup correctly." ) ;
@@ -88,7 +88,7 @@ public void CacheShouldCleanupOldestClients()
8888 [ Test ]
8989 public void LRUShouldNotBeRemoved ( )
9090 {
91- var clientCache = new ClientCache ( ) ;
91+ var clientCache = new ClientCache ( 100 ) ;
9292
9393 for ( int i = 0 ; i <= 100 ; i ++ )
9494 {
@@ -104,7 +104,7 @@ public void LRUShouldNotBeRemoved()
104104 clientCache . GetClient ( new DummyClientKey ( "client102" ) , ( ) => new object ( ) ) ;
105105
106106 var clientsField = typeof ( ClientCache ) . GetField ( "_clients" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
107- var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < IEquatable < object > , ClientEntry > ;
107+ var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < object , ClientEntry > ;
108108
109109 Assert . IsNotNull ( clients , "The _clients field is null." ) ;
110110 Assert . AreEqual ( 100 , clients ! . Count , "Cache did not cleanup correctly." ) ;
@@ -121,7 +121,7 @@ public void LRUShouldNotBeRemoved()
121121 [ Test ]
122122 public void CacheShouldDisposeClientsWhenRemoved ( )
123123 {
124- var clientCache = new ClientCache ( ) ;
124+ var clientCache = new ClientCache ( 100 ) ;
125125
126126 // Create a disposable client
127127 var disposableClient = new DisposableClient ( ) ;
@@ -135,7 +135,7 @@ public void CacheShouldDisposeClientsWhenRemoved()
135135 }
136136
137137 var clientsField = typeof ( ClientCache ) . GetField ( "_clients" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
138- var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < IEquatable < object > , ClientEntry > ;
138+ var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < object , ClientEntry > ;
139139
140140 Assert . IsNotNull ( clients , "The _clients field is null." ) ;
141141 Assert . IsTrue ( disposableClient . IsDisposed , "Disposable client was not disposed correctly." ) ;
@@ -144,7 +144,7 @@ public void CacheShouldDisposeClientsWhenRemoved()
144144 [ Test ]
145145 public void CacheShouldHandleDifferentClientIdsSeparately ( )
146146 {
147- var clientCache = new ClientCache ( ) ;
147+ var clientCache = new ClientCache ( 100 ) ;
148148
149149 // Add clients with the same type but different IDs
150150 var client1 = new object ( ) ;
@@ -154,7 +154,7 @@ public void CacheShouldHandleDifferentClientIdsSeparately()
154154 clientCache . GetClient ( new DummyClientKey ( "client2" ) , ( ) => client2 ) ;
155155
156156 var clientsField = typeof ( ClientCache ) . GetField ( "_clients" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
157- var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < IEquatable < object > , ClientEntry > ;
157+ var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < object , ClientEntry > ;
158158
159159 Assert . IsNotNull ( clients , "The _clients field is null." ) ;
160160 Assert . IsTrue ( clients ! . ContainsKey ( new DummyClientKey ( "client1" ) ) , "Client1 should be in the cache." ) ;
@@ -192,7 +192,7 @@ public void ClientCacheShouldRespectMaxCacheSize()
192192 Assert . False ( wasRecreated , "Client A was unexpectedly recreated" ) ;
193193
194194 var clientsField = typeof ( ClientCache ) . GetField ( "_clients" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
195- var clients = clientsField ? . GetValue ( clientCache ) as IDictionary < IEquatable < object > , ClientEntry > ;
195+ var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < object , ClientEntry > ;
196196
197197 Assert . IsNotNull ( clients , "_clients dictionary should not be null" ) ;
198198
@@ -209,7 +209,7 @@ public void ClientCacheShouldRespectMaxCacheSize()
209209 [ Test ]
210210 public void CacheShouldHandleDifferentOptionsSeparately ( )
211211 {
212- var clientCache = new ClientCache ( ) ;
212+ var clientCache = new ClientCache ( 100 ) ;
213213
214214 // Define two different options as DummyClientKeys
215215 var options1 = new ClientPipelineOptions ( ) { EnableDistributedTracing = true } ;
@@ -226,15 +226,15 @@ public void CacheShouldHandleDifferentOptionsSeparately()
226226 Assert . AreNotSame ( client1 , client2 , "Clients should be distinct when options are different." ) ;
227227
228228 var clientsField = typeof ( ClientCache ) . GetField ( "_clients" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
229- var clients = clientsField ? . GetValue ( clientCache ) as IDictionary < IEquatable < object > , ClientEntry > ;
229+ var clients = clientsField ? . GetValue ( clientCache ) as Dictionary < object , ClientEntry > ;
230230
231231 // Assert that both clients are in the cache with the expected keys
232232 Assert . IsTrue ( clients ! . ContainsKey ( new DummyClientKey ( "abc" , options1 ) ) , "Client with options1 should be in the cache." ) ;
233233 Assert . IsTrue ( clients ! . ContainsKey ( new DummyClientKey ( "abc" , options2 ) ) , "Client with options2 should be in the cache." ) ;
234234 }
235235}
236236
237- internal record DummyClientKey ( string Key , ClientPipelineOptions ? options = null ) : IEquatable < object > ;
237+ internal record DummyClientKey ( string Key , ClientPipelineOptions ? options = null ) ;
238238
239239// Helper class to simulate a disposable client
240240internal class DisposableClient : IDisposable
0 commit comments