Skip to content

Commit 2407ffd

Browse files
committed
Use InMemory Database for integration tests
1 parent 551c0f9 commit 2407ffd

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

LinkDotNet.Blog.IntegrationTests/SqlDatabaseTestBase.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.Data.Common;
23
using System.Threading.Tasks;
34
using LinkDotNet.Infrastructure.Persistence.Sql;
5+
using Microsoft.Data.Sqlite;
46
using Microsoft.EntityFrameworkCore;
57
using Xunit;
68

@@ -11,7 +13,7 @@ public abstract class SqlDatabaseTestBase : IAsyncLifetime, IAsyncDisposable
1113
protected SqlDatabaseTestBase()
1214
{
1315
var options = new DbContextOptionsBuilder()
14-
.UseSqlite("Data Source=IntegrationTest.db")
16+
.UseSqlite(CreateInMemoryConnection())
1517
.Options;
1618
DbContext = new BlogPostContext(options);
1719
BlogPostRepository = new BlogPostRepository(new BlogPostContext(options));
@@ -36,5 +38,14 @@ public async ValueTask DisposeAsync()
3638
await DbContext.Database.EnsureDeletedAsync();
3739
await DbContext.DisposeAsync();
3840
}
41+
42+
private static DbConnection CreateInMemoryConnection()
43+
{
44+
var connection = new SqliteConnection("Filename=:memory:");
45+
46+
connection.Open();
47+
48+
return connection;
49+
}
3950
}
4051
}

0 commit comments

Comments
 (0)