Skip to content

Commit 674eddd

Browse files
committed
Fixed test setup
1 parent 9161450 commit 674eddd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

LinkDotNet.Blog.UnitTests/Web/Pages/Admin/DashboardTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System.Data.Common;
2+
using System.Linq;
23
using Bunit;
34
using Bunit.TestDoubles;
45
using FluentAssertions;
@@ -8,6 +9,7 @@
89
using LinkDotNet.Blog.Web;
910
using LinkDotNet.Blog.Web.Pages.Admin;
1011
using LinkDotNet.Blog.Web.Shared.Admin.Dashboard;
12+
using Microsoft.Data.Sqlite;
1113
using Microsoft.EntityFrameworkCore;
1214
using Microsoft.Extensions.DependencyInjection;
1315
using 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

Comments
 (0)