@@ -28,12 +28,17 @@ namespace DotNetToolkit.Repository.Integration.Test
2828
2929 public abstract class TestBase
3030 {
31+ protected ILoggerProvider TestXUnitLoggerProvider { get ; }
32+
3133 protected TestBase ( ITestOutputHelper testOutputHelper )
3234 {
3335 TestXUnitLoggerProvider = new TestXUnitLoggerProvider ( testOutputHelper ) ;
3436 }
3537
36- protected ILoggerProvider TestXUnitLoggerProvider { get ; }
38+ protected virtual void BeforeTest ( CachingProviderType cachingProvider ) { }
39+ protected virtual void AfterTest ( CachingProviderType cachingProvider ) { }
40+ protected virtual void BeforeTest ( ContextProviderType contextProvider ) { }
41+ protected virtual void AfterTest ( ContextProviderType contextProvider ) { }
3742
3843 protected void ForRepositoryFactoryWithAllCachingProviders ( ContextProviderType contextProvider , Action < IRepositoryFactory , CachingProviderType > action )
3944 => CachingProviders ( )
@@ -42,9 +47,13 @@ protected void ForRepositoryFactoryWithAllCachingProviders(ContextProviderType c
4247 {
4348 var builder = GetRepositoryOptionsBuilder ( contextProvider ) ;
4449
50+ BeforeTest ( cachingProvider ) ;
51+
4552 ApplyCachingProvider ( cachingProvider , builder ) ;
4653
4754 action ( new RepositoryFactory ( builder . Options ) , cachingProvider ) ;
55+
56+ AfterTest ( cachingProvider ) ;
4857 } ) ;
4958
5059 protected void ForRepositoryFactoryWithAllCachingProviders ( ContextProviderType contextProvider , Action < IRepositoryFactory > action )
@@ -57,11 +66,13 @@ protected void ForRepositoryFactoryWithAllCachingProvidersAsync(ContextProviderT
5766 {
5867 var builder = GetRepositoryOptionsBuilder ( contextProvider ) ;
5968
69+ BeforeTest ( cachingProvider ) ;
70+
6071 ApplyCachingProvider ( cachingProvider , builder ) ;
6172
62- await HandleExceptionAsync ( ( ) => action (
63- new RepositoryFactory ( builder . Options ) ,
64- cachingProvider ) ) ;
73+ await HandleExceptionAsync ( ( ) => action ( new RepositoryFactory ( builder . Options ) , cachingProvider ) ) ;
74+
75+ AfterTest ( cachingProvider ) ;
6576 } ) ;
6677
6778 protected void ForRepositoryFactoryWithAllCachingProvidersAsync ( ContextProviderType contextProvider , Func < IRepositoryFactory , Task > action )
@@ -75,7 +86,11 @@ protected void ForAllRepositoryFactories(Action<IRepositoryFactory, ContextProvi
7586 if ( exclude != null && exclude . Contains ( x ) )
7687 return ;
7788
89+ BeforeTest ( x ) ;
90+
7891 action ( new RepositoryFactory ( BuildOptions ( x ) ) , x ) ;
92+
93+ AfterTest ( x ) ;
7994 } ) ;
8095
8196 protected void ForAllRepositoryFactories ( Action < IRepositoryFactory > action , params ContextProviderType [ ] exclude )
@@ -89,8 +104,11 @@ protected void ForAllRepositoryFactoriesAsync(Func<IRepositoryFactory, ContextPr
89104 if ( exclude != null && exclude . Contains ( x ) )
90105 return ;
91106
92- await HandleExceptionAsync ( ( ) => action (
93- new RepositoryFactory ( BuildOptions ( x ) ) , x ) ) ;
107+ BeforeTest ( x ) ;
108+
109+ await HandleExceptionAsync ( ( ) => action ( new RepositoryFactory ( BuildOptions ( x ) ) , x ) ) ;
110+
111+ AfterTest ( x ) ;
94112 } ) ;
95113
96114 protected void ForAllRepositoryFactoriesAsync ( Func < IRepositoryFactory , Task > action , params ContextProviderType [ ] exclude )
@@ -105,7 +123,11 @@ protected void ForAllServiceFactories(Action<IServiceFactory, ContextProviderTyp
105123 if ( exclude != null && exclude . Contains ( x ) )
106124 return ;
107125
126+ BeforeTest ( x ) ;
127+
108128 action ( new ServiceFactory ( new UnitOfWorkFactory ( BuildOptions ( x ) ) ) , x ) ;
129+
130+ AfterTest ( x ) ;
109131 } ) ;
110132
111133 protected void ForAllServiceFactories ( Action < IServiceFactory > action , params ContextProviderType [ ] exclude )
@@ -120,10 +142,11 @@ protected void ForAllServiceFactoriesAsync(Func<IServiceFactory, ContextProvider
120142 if ( exclude != null && exclude . Contains ( x ) )
121143 return ;
122144
123- await HandleExceptionAsync ( ( ) => action (
124- new ServiceFactory (
125- new UnitOfWorkFactory (
126- BuildOptions ( x ) ) ) , x ) ) ;
145+ BeforeTest ( x ) ;
146+
147+ await HandleExceptionAsync ( ( ) => action ( new ServiceFactory ( new UnitOfWorkFactory ( BuildOptions ( x ) ) ) , x ) ) ;
148+
149+ AfterTest ( x ) ;
127150 } ) ;
128151
129152 protected void ForAllServiceFactoriesAsync ( Func < IServiceFactory , Task > action , params ContextProviderType [ ] exclude )
@@ -133,7 +156,14 @@ protected void ForAllUnitOfWorkFactories(Action<IUnitOfWorkFactory, ContextProvi
133156 => ContextProviders ( )
134157 . Where ( SupportsTransactions )
135158 . ToList ( )
136- . ForEach ( x => action ( new UnitOfWorkFactory ( BuildOptions ( x ) ) , x ) ) ;
159+ . ForEach ( x =>
160+ {
161+ BeforeTest ( x ) ;
162+
163+ action ( new UnitOfWorkFactory ( BuildOptions ( x ) ) , x ) ;
164+
165+ AfterTest ( x ) ;
166+ } ) ;
137167
138168 protected void ForAllUnitOfWorkFactories ( Action < IUnitOfWorkFactory > action )
139169 => ForAllUnitOfWorkFactories ( ( factory , type ) => action ( factory ) ) ;
@@ -208,41 +238,42 @@ private static void ApplyCachingProvider(CachingProviderType cachingProvider, Re
208238 {
209239 case CachingProviderType . MicrosoftInMemory :
210240 {
211- builder . UseCachingProvider ( new InMemoryCacheProvider ( ) ) ;
241+ builder . UseInMemoryCache ( ) ;
242+
212243 break ;
213244 }
214245 case CachingProviderType . Redis :
215246 {
216- var provider = new RedisCacheProvider ( allowAdmin : true , defaultDatabase : 0 , expiry : null ) ;
217-
218- provider . Cache . Server . FlushAllDatabases ( ) ;
219-
220- builder . UseCachingProvider ( provider ) ;
247+ builder . UseRedis ( options =>
248+ {
249+ options
250+ . WithEndPoint ( "localhost" )
251+ . WithDefaultDatabase ( 0 ) ;
252+ } ) ;
221253
222254 break ;
223255 }
224256#if NETFULL
225257 case CachingProviderType . Memcached:
226258 {
227- var provider = new MemcachedCacheProvider ( "127.0.0.1" , 11211 ) ;
228-
229- provider . Cache . Client . FlushAll ( ) ;
230-
231- builder . UseCachingProvider ( provider ) ;
259+ builder . UseMemcached ( options =>
260+ {
261+ options . WithEndPoint ( "127.0.0.1" , 11211 ) ;
262+ } ) ;
232263
233264 break ;
234265 }
235266#endif
236267 case CachingProviderType . Couchbase :
237268 {
238- var provider = new CouchbaseCacheProvider ( "http://localhost:8091" , "default" , "password" ) ;
239-
240- using ( var bucket = provider . Cache . Cluster . OpenBucket ( ) )
269+ builder . UseCouchbase ( options =>
241270 {
242- bucket . CreateManager ( "default" , "password" ) . Flush ( ) ;
243- }
244-
245- builder . UseCachingProvider ( provider ) ;
271+ options
272+ . WithEndPoint ( "http://localhost:8091" )
273+ . WithBucketName ( "default" )
274+ . WithUsername ( "default" )
275+ . WithPassword ( "password" ) ;
276+ } ) ;
246277
247278 break ;
248279 }
@@ -258,7 +289,7 @@ protected static ContextProviderType[] InMemoryContextProviders()
258289 => new [ ]
259290 {
260291 ContextProviderType . InMemory ,
261- ContextProviderType . EntityFrameworkCore ,
292+ ContextProviderType . EntityFrameworkCore ,
262293 } ;
263294
264295 protected static ContextProviderType [ ] SqlServerContextProviders ( )
@@ -293,7 +324,7 @@ private static CachingProviderType[] CachingProviders()
293324 //TODO: Cannot test when Appveyor is running tests.
294325 //I am not able to find the pre-built binaries so that I can manually run
295326 //the server (similar to redis and memcached). I am going to comment out testing couchbase for now
296- //CachingProviderType.Couchbase,
327+ // CachingProviderType.Couchbase,
297328 } ;
298329
299330 private static ContextProviderType [ ] ContextProviders ( )
0 commit comments