88using CommunityToolkit . Datasync . TestCommon ;
99using CommunityToolkit . Datasync . TestCommon . Databases ;
1010using Microsoft . EntityFrameworkCore ;
11+ using Microsoft . Extensions . Logging ;
12+ using Microsoft . Extensions . Logging . Xunit ;
1113using Xunit . Abstractions ;
1214
1315namespace CommunityToolkit . Datasync . Server . Automapper . Test ;
1416
1517[ ExcludeFromCodeCoverage ]
16- public class MappedTableRepository_Tests ( ITestOutputHelper output ) : RepositoryTests < MovieDto > ( )
18+ public class MappedTableRepository_Tests : RepositoryTests < MovieDto > , IDisposable
1719{
1820 #region Setup
21+ private readonly ITestOutputHelper output ;
1922 private readonly Random random = new ( ) ;
2023 private SqliteDbContext context ;
2124 private EntityTableRepository < SqliteEntityMovie > innerRepository ;
22- private readonly IMapper mapper = new MapperConfiguration ( c => c . AddProfile ( new MapperProfile ( ) ) ) . CreateMapper ( ) ;
25+ private readonly ILoggerFactory loggerFactory ;
26+ private readonly IMapper mapper ;
2327 private MappedTableRepository < SqliteEntityMovie , MovieDto > repository ;
2428 private List < MovieDto > movies ;
29+ private bool _disposedValue ;
30+
31+ public MappedTableRepository_Tests ( ITestOutputHelper output )
32+ {
33+ this . output = output ;
34+ this . loggerFactory = new LoggerFactory ( [ new XunitLoggerProvider ( this . output ) ] ) ;
35+ MapperConfiguration config = new ( c => c . AddProfile ( new MapperProfile ( ) ) , this . loggerFactory ) ;
36+ this . mapper = config . CreateMapper ( ) ;
37+ }
2538
2639 protected override Task < MovieDto > GetEntityAsync ( string id )
2740 => Task . FromResult ( this . mapper . Map < MovieDto > ( this . context . Movies . AsNoTracking ( ) . SingleOrDefault ( m => m . Id == id ) ) ) ;
@@ -31,7 +44,7 @@ protected override Task<int> GetEntityCountAsync()
3144
3245 protected override Task < IRepository < MovieDto > > GetPopulatedRepositoryAsync ( )
3346 {
34- this . context = SqliteDbContext . CreateContext ( output ) ;
47+ this . context = SqliteDbContext . CreateContext ( this . output ) ;
3548 this . innerRepository = new EntityTableRepository < SqliteEntityMovie > ( this . context ) ;
3649 this . repository = new MappedTableRepository < SqliteEntityMovie , MovieDto > ( this . mapper , this . innerRepository ) ;
3750 this . movies = this . context . Movies . AsNoTracking ( ) . ToList ( ) . ConvertAll ( m => this . mapper . Map < MovieDto > ( m ) ) ;
@@ -40,5 +53,26 @@ protected override Task<IRepository<MovieDto>> GetPopulatedRepositoryAsync()
4053
4154 protected override Task < string > GetRandomEntityIdAsync ( bool exists )
4255 => Task . FromResult ( exists ? this . movies [ this . random . Next ( this . movies . Count ) ] . Id : Guid . NewGuid ( ) . ToString ( ) ) ;
56+
57+ protected virtual void Dispose ( bool disposing )
58+ {
59+ if ( ! this . _disposedValue )
60+ {
61+ if ( disposing )
62+ {
63+ this . context . Dispose ( ) ;
64+ this . loggerFactory . Dispose ( ) ;
65+ }
66+
67+ this . _disposedValue = true ;
68+ }
69+ }
70+
71+ public void Dispose ( )
72+ {
73+ // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
74+ Dispose ( disposing : true ) ;
75+ GC . SuppressFinalize ( this ) ;
76+ }
4377 #endregion
4478}
0 commit comments