1
- using System . Linq ;
1
+ using System . Data . Common ;
2
+ using System . Linq ;
2
3
using Bunit ;
3
4
using Bunit . TestDoubles ;
4
5
using FluentAssertions ;
8
9
using LinkDotNet . Blog . Web ;
9
10
using LinkDotNet . Blog . Web . Pages . Admin ;
10
11
using LinkDotNet . Blog . Web . Shared . Admin . Dashboard ;
12
+ using Microsoft . Data . Sqlite ;
11
13
using Microsoft . EntityFrameworkCore ;
12
14
using Microsoft . Extensions . DependencyInjection ;
13
15
using Moq ;
@@ -20,11 +22,15 @@ public class DashboardTests : TestContext
20
22
[ Fact ]
21
23
public void ShouldNotShowAboutMeStatisticsWhenDisabled ( )
22
24
{
25
+ var options = new DbContextOptionsBuilder ( )
26
+ . UseSqlite ( CreateInMemoryConnection ( ) )
27
+ . Options ;
23
28
var dashboardService = new Mock < IDashboardService > ( ) ;
24
29
this . AddTestAuthorization ( ) . SetAuthorized ( "test" ) ;
25
30
Services . AddScoped ( _ => CreateAppConfiguration ( false ) ) ;
26
31
Services . AddScoped ( _ => dashboardService . Object ) ;
27
32
Services . AddScoped ( _ => new Mock < IRepository < BlogPost > > ( ) . Object ) ;
33
+ Services . AddScoped ( _ => new BlogDbContext ( options ) ) ;
28
34
dashboardService . Setup ( d => d . GetDashboardDataAsync ( ) )
29
35
. ReturnsAsync ( new DashboardData ( ) ) ;
30
36
@@ -43,5 +49,14 @@ private static AppConfiguration CreateAppConfiguration(bool aboutMeEnabled)
43
49
ProfileInformation = aboutMeEnabled ? new ProfileInformation ( ) : null ,
44
50
} ;
45
51
}
52
+
53
+ private static DbConnection CreateInMemoryConnection ( )
54
+ {
55
+ var connection = new SqliteConnection ( "Filename=:memory:" ) ;
56
+
57
+ connection . Open ( ) ;
58
+
59
+ return connection ;
60
+ }
46
61
}
47
62
}
0 commit comments