@@ -10,13 +10,27 @@ namespace Eocron.DependencyInjection.Tests.DependencyInjectionTests
1010{
1111 public class CacheTests : BaseDependencyInjectionTests
1212 {
13+ [ Test ]
14+ public async Task ConstantCache ( )
15+ {
16+ Instance . Setup ( x => x . WorkWithResultAsync ( It . Is < int > ( i=> i == 1 ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( 1 ) ;
17+ Instance . Setup ( x => x . WorkWithResultAsync ( It . Is < int > ( i=> i == 2 ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( 2 ) ;
18+
19+ var proxy = CreateTestObject ( x => x . AddAbsoluteTimeoutCache ( Expiration ) ) ;
20+ await Parallel . ForAsync ( 0 , 100 , async ( _ , _ ) =>
21+ {
22+ ( await proxy . WorkWithResultAsync ( 1 , Ct ) ) . Should ( ) . Be ( 1 ) ;
23+ } ) ;
24+ Instance . Verify ( x=> x . WorkWithResultAsync ( It . IsAny < int > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Exactly ( 1 ) ) ;
25+ }
26+
1327 [ Test ]
1428 public async Task AbsoluteExpirationErrorNotCached ( )
1529 {
1630 Instance . Setup ( x => x . WorkWithResultAsync ( It . IsAny < int > ( ) , It . IsAny < CancellationToken > ( ) ) )
1731 . ThrowsAsync ( new InvalidOperationException ( ) ) ;
1832
19- var proxy = CreateTestObject ( x => x . AddAbsoluteTimeoutCache ( Expiration , ( method , args ) => args [ 0 ] ) ) ;
33+ var proxy = CreateTestObject ( x => x . AddAbsoluteTimeoutCache ( Expiration ) ) ;
2034
2135 var func = async ( ) => await proxy . WorkWithResultAsync ( 1 , Ct ) ;
2236 await func . Should ( ) . ThrowAsync < InvalidOperationException > ( ) ;
@@ -31,7 +45,7 @@ public async Task SlidingExpirationErrorNotCached()
3145 Instance . Setup ( x => x . WorkWithResultAsync ( It . IsAny < int > ( ) , It . IsAny < CancellationToken > ( ) ) )
3246 . ThrowsAsync ( new InvalidOperationException ( ) ) ;
3347
34- var proxy = CreateTestObject ( x => x . AddSlidingTimeoutCache ( Expiration , ( method , args ) => args [ 0 ] ) ) ;
48+ var proxy = CreateTestObject ( x => x . AddSlidingTimeoutCache ( Expiration ) ) ;
3549
3650 var func = async ( ) => await proxy . WorkWithResultAsync ( 1 , Ct ) ;
3751 await func . Should ( ) . ThrowAsync < InvalidOperationException > ( ) ;
@@ -46,7 +60,7 @@ public async Task AbsoluteExpiration()
4660 Instance . Setup ( x => x . WorkWithResultAsync ( It . Is < int > ( i=> i == 1 ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( 1 ) ;
4761 Instance . Setup ( x => x . WorkWithResultAsync ( It . Is < int > ( i=> i == 2 ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( 2 ) ;
4862
49- var proxy = CreateTestObject ( x => x . AddAbsoluteTimeoutCache ( Expiration , ( method , args ) => args [ 0 ] ) ) ;
63+ var proxy = CreateTestObject ( x => x . AddAbsoluteTimeoutCache ( Expiration ) ) ;
5064
5165 //first pass
5266 await Parallel . ForAsync ( 0 , 100 , async ( _ , _ ) =>
@@ -73,7 +87,7 @@ public async Task SlidingExpiration()
7387 Instance . Setup ( x => x . WorkWithResultAsync ( It . Is < int > ( i=> i == 1 ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( 1 ) ;
7488 Instance . Setup ( x => x . WorkWithResultAsync ( It . Is < int > ( i=> i == 2 ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( 2 ) ;
7589
76- var proxy = CreateTestObject ( x => x . AddSlidingTimeoutCache ( Expiration , ( method , args ) => args [ 0 ] ) ) ;
90+ var proxy = CreateTestObject ( x => x . AddSlidingTimeoutCache ( Expiration ) ) ;
7791
7892 //first pass
7993 await Parallel . ForAsync ( 0 , 100 , async ( _ , _ ) =>
@@ -100,7 +114,7 @@ public async Task SlidingExpirationOverlap()
100114 Instance . Setup ( x => x . WorkWithResultAsync ( It . Is < int > ( i=> i == 1 ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( 1 ) ;
101115 Instance . Setup ( x => x . WorkWithResultAsync ( It . Is < int > ( i=> i == 2 ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( 2 ) ;
102116
103- var proxy = CreateTestObject ( x => x . AddSlidingTimeoutCache ( Expiration , ( method , args ) => args [ 0 ] ) ) ;
117+ var proxy = CreateTestObject ( x => x . AddSlidingTimeoutCache ( Expiration ) ) ;
104118
105119 //first pass
106120 await Parallel . ForAsync ( 0 , 100 , async ( _ , _ ) =>
0 commit comments