File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Tests/Drogecode.Blazor.ExpireStorage.Tests Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ public LocalStorageServiceMock(IMemoryCache memoryCache)
1818
1919 public async ValueTask < T ? > GetItemAsync < T > ( string key , CancellationToken cancellationToken = new CancellationToken ( ) )
2020 {
21- throw new NotImplementedException ( ) ;
21+ if ( _memoryCache . TryGetValue ( key , out var value ) )
22+ {
23+ return ( T ) value ! ;
24+ }
25+ return default ;
2226 }
2327
2428 public async ValueTask < string ? > GetItemAsStringAsync ( string key , CancellationToken cancellationToken = new CancellationToken ( ) )
Original file line number Diff line number Diff line change @@ -32,4 +32,26 @@ public async Task ByFunctionTest()
3232 response . HandledBy . Should ( ) . Be ( HandledBy . Function ) ;
3333 response . Data . Should ( ) . Be ( "test" ) ;
3434 }
35+
36+ [ Fact ]
37+ public async Task FromCacheTest ( )
38+ {
39+ const string cacheKey = "FromCacheTest" ;
40+ var addToCache = await _expireStorageService . CachedRequestAsync < TestStringResponse > ( cacheKey , ( ) => Task . FromResult ( new TestStringResponse
41+ {
42+ Data = "test"
43+ } ) ,
44+ clt : TestContext . Current . CancellationToken ) ;
45+ Assert . NotNull ( addToCache ? . Data ) ;
46+ addToCache . HandledBy . Should ( ) . Be ( HandledBy . Function ) ;
47+ var response = await _expireStorageService . CachedRequestAsync < TestStringResponse > ( cacheKey , ( ) => Task . FromResult ( new TestStringResponse
48+ {
49+ Data = "not called"
50+ } ) ,
51+ new CachedRequest { OneCallPerCache = true } ,
52+ clt : TestContext . Current . CancellationToken ) ;
53+ Assert . NotNull ( response ? . Data ) ;
54+ response . HandledBy . Should ( ) . Be ( HandledBy . Cache ) ;
55+ response . Data . Should ( ) . Be ( "test" ) ;
56+ }
3557}
You can’t perform that action at this time.
0 commit comments