1- using System . Linq ;
1+ using System . Data . Common ;
2+ using System . Linq ;
23using Bunit ;
34using Bunit . TestDoubles ;
45using FluentAssertions ;
89using LinkDotNet . Blog . Web ;
910using LinkDotNet . Blog . Web . Pages . Admin ;
1011using LinkDotNet . Blog . Web . Shared . Admin . Dashboard ;
12+ using Microsoft . Data . Sqlite ;
1113using Microsoft . EntityFrameworkCore ;
1214using Microsoft . Extensions . DependencyInjection ;
1315using Moq ;
@@ -20,11 +22,15 @@ public class DashboardTests : TestContext
2022 [ Fact ]
2123 public void ShouldNotShowAboutMeStatisticsWhenDisabled ( )
2224 {
25+ var options = new DbContextOptionsBuilder ( )
26+ . UseSqlite ( CreateInMemoryConnection ( ) )
27+ . Options ;
2328 var dashboardService = new Mock < IDashboardService > ( ) ;
2429 this . AddTestAuthorization ( ) . SetAuthorized ( "test" ) ;
2530 Services . AddScoped ( _ => CreateAppConfiguration ( false ) ) ;
2631 Services . AddScoped ( _ => dashboardService . Object ) ;
2732 Services . AddScoped ( _ => new Mock < IRepository < BlogPost > > ( ) . Object ) ;
33+ Services . AddScoped ( _ => new BlogDbContext ( options ) ) ;
2834 dashboardService . Setup ( d => d . GetDashboardDataAsync ( ) )
2935 . ReturnsAsync ( new DashboardData ( ) ) ;
3036
@@ -43,5 +49,14 @@ private static AppConfiguration CreateAppConfiguration(bool aboutMeEnabled)
4349 ProfileInformation = aboutMeEnabled ? new ProfileInformation ( ) : null ,
4450 } ;
4551 }
52+
53+ private static DbConnection CreateInMemoryConnection ( )
54+ {
55+ var connection = new SqliteConnection ( "Filename=:memory:" ) ;
56+
57+ connection . Open ( ) ;
58+
59+ return connection ;
60+ }
4661 }
4762}
0 commit comments