22{
33 using System ;
44 using System . Threading ;
5+ using System . Threading . Tasks ;
56 using Microsoft . Extensions . DependencyInjection ;
67 using Neolution . Extensions . Caching . Abstractions ;
78 using Neolution . Extensions . Caching . UnitTests . Models ;
@@ -18,31 +19,33 @@ public class DistributedCacheAsyncTests
1819 /// Tests if created objects can be retrieved again from the cache.
1920 /// </summary>
2021 /// <param name="services">The service collection.</param>
22+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
2123 [ Theory ]
2224 [ ClassData ( typeof ( ServiceCollectionTestDataCollection ) ) ]
23- public void CreatedObjectCanBeRetrievedAgain ( IServiceCollection services )
25+ public async Task CreatedObjectCanBeRetrievedAgain ( IServiceCollection services )
2426 {
2527 using var serviceProvider = services . BuildServiceProvider ( ) ;
2628 const string cacheObject = "Hello World!" ;
2729
2830 // Act
2931 var cache = GetCache ( serviceProvider ) ;
30- cache . SetAsync ( TestCacheId . Foobar , cacheObject ) . GetAwaiter ( ) . GetResult ( ) ;
31- cache . GetAsync < string > ( TestCacheId . Foobar ) . GetAwaiter ( ) . GetResult ( ) ;
32- cache . SetAsync ( TestCacheId . Foobar , cacheObject ) . GetAwaiter ( ) . GetResult ( ) ;
33- cache . GetAsync < string > ( TestCacheId . Foobar ) . GetAwaiter ( ) . GetResult ( ) ;
32+ await cache . SetAsync ( TestCacheId . Foobar , cacheObject ) ;
33+ await cache . GetAsync < string > ( TestCacheId . Foobar ) ;
34+ await cache . SetAsync ( TestCacheId . Foobar , cacheObject ) ;
35+ await cache . GetAsync < string > ( TestCacheId . Foobar ) ;
3436
3537 // Assert
36- cache . GetAsync < string > ( TestCacheId . Foobar ) . GetAwaiter ( ) . GetResult ( ) . ShouldBe ( cacheObject ) ;
38+ ( await cache . GetAsync < string > ( TestCacheId . Foobar ) ) . ShouldBe ( cacheObject ) ;
3739 }
3840
3941 /// <summary>
4042 /// Tests if created objects can be retrieved again from the cache.
4143 /// </summary>
4244 /// <param name="serviceCollection">The service collection.</param>
45+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
4346 [ Theory ]
4447 [ ClassData ( typeof ( ServiceCollectionTestDataCollection ) ) ]
45- public void CreatedObjectWithKeyCanBeRetrievedAgain ( IServiceCollection serviceCollection )
48+ public async Task CreatedObjectWithKeyCanBeRetrievedAgain ( IServiceCollection serviceCollection )
4649 {
4750 // Assign
4851 using var serviceProvider = serviceCollection . BuildServiceProvider ( ) ;
@@ -52,40 +55,42 @@ public void CreatedObjectWithKeyCanBeRetrievedAgain(IServiceCollection serviceCo
5255
5356 // Act
5457 var cache = GetCache ( serviceProvider ) ;
55- cache . SetAsync ( TestCacheId . Foobar , key , cacheObject ) . GetAwaiter ( ) . GetResult ( ) ;
58+ await cache . SetAsync ( TestCacheId . Foobar , key , cacheObject ) ;
5659
5760 // Assert
58- cache . GetAsync < string > ( TestCacheId . Foobar , key ) . GetAwaiter ( ) . GetResult ( ) . ShouldBe ( cacheObject ) ;
61+ ( await cache . GetAsync < string > ( TestCacheId . Foobar , key ) ) . ShouldBe ( cacheObject ) ;
5962 }
6063
6164 /// <summary>
6265 /// Tests if removed object cannot be retrieved again from the cache.
6366 /// </summary>
6467 /// <param name="serviceCollection">The service collection.</param>
68+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
6569 [ Theory ]
6670 [ ClassData ( typeof ( ServiceCollectionTestDataCollection ) ) ]
67- public void RemovedObjectCannotBeRetrievedAgain ( IServiceCollection serviceCollection )
71+ public async Task RemovedObjectCannotBeRetrievedAgain ( IServiceCollection serviceCollection )
6872 {
6973 // Assign
7074 using var serviceProvider = serviceCollection . BuildServiceProvider ( ) ;
7175 const string cacheObject = "Hello World!" ;
7276
7377 // Act
7478 var cache = GetCache ( serviceProvider ) ;
75- cache . SetAsync ( TestCacheId . Foobar , cacheObject ) . GetAwaiter ( ) . GetResult ( ) ;
76- cache . RemoveAsync ( TestCacheId . Foobar ) . GetAwaiter ( ) . GetResult ( ) ;
79+ await cache . SetAsync ( TestCacheId . Foobar , cacheObject ) ;
80+ await cache . RemoveAsync ( TestCacheId . Foobar ) ;
7781
7882 // Assert
79- cache . GetAsync < string > ( TestCacheId . Foobar ) . GetAwaiter ( ) . GetResult ( ) . ShouldBeNull ( ) ;
83+ ( await cache . GetAsync < string > ( TestCacheId . Foobar ) ) . ShouldBeNull ( ) ;
8084 }
8185
8286 /// <summary>
8387 /// Tests if removed object cannot be retrieved again from the cache.
8488 /// </summary>
8589 /// <param name="serviceCollection">The service collection.</param>
90+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
8691 [ Theory ( Skip = "Refresh is removed from interface (no strong use-case)" ) ]
8792 [ ClassData ( typeof ( ServiceCollectionTestDataCollection ) ) ]
88- public void RefreshedObjectDidNotExpire ( IServiceCollection serviceCollection )
93+ public async Task RefreshedObjectDidNotExpire ( IServiceCollection serviceCollection )
8994 {
9095 // Assign
9196 using var serviceProvider = serviceCollection . BuildServiceProvider ( ) ;
@@ -99,21 +104,21 @@ public void RefreshedObjectDidNotExpire(IServiceCollection serviceCollection)
99104 var cache = GetCache ( serviceProvider ) ;
100105
101106 // Add two objects to cache, both with a sliding expiration of 1000ms
102- cache . SetWithOptionsAsync ( TestCacheId . Foobar , cacheObject , options ) . GetAwaiter ( ) . GetResult ( ) ;
103- cache . SetWithOptionsAsync ( TestCacheId . NonRefreshedFoobar , cacheObject , options ) . GetAwaiter ( ) . GetResult ( ) ;
107+ await cache . SetWithOptionsAsync ( TestCacheId . Foobar , cacheObject , options ) ;
108+ await cache . SetWithOptionsAsync ( TestCacheId . NonRefreshedFoobar , cacheObject , options ) ;
104109
105110 // After a wait of 500ms, refresh only one of the objects.
106111 Thread . Sleep ( TimeSpan . FromMilliseconds ( 500 ) ) ;
107112
108- //cache.RefreshAsync(TestCacheId.Foobar).GetAwaiter().GetResult( )
113+ //await cache.RefreshAsync(TestCacheId.Foobar)
109114
110115 // After a wait of 750ms, one of the objects should now be expired because its at least 1250ms (500+750) old at the moment.
111116 // But the refreshed object should still be valid for roughly another 250ms.
112117 Thread . Sleep ( TimeSpan . FromMilliseconds ( 750 ) ) ;
113118
114119 // Assert
115- cache . GetAsync < string > ( TestCacheId . Foobar ) . GetAwaiter ( ) . GetResult ( ) . ShouldBe ( cacheObject ) ;
116- cache . GetAsync < string > ( TestCacheId . NonRefreshedFoobar ) . GetAwaiter ( ) . GetResult ( ) . ShouldBeNull ( ) ;
120+ ( await cache . GetAsync < string > ( TestCacheId . Foobar ) ) . ShouldBe ( cacheObject ) ;
121+ ( await cache . GetAsync < string > ( TestCacheId . NonRefreshedFoobar ) ) . ShouldBeNull ( ) ;
117122 }
118123
119124 /// <summary>
0 commit comments