-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TestsWithInMemoryDbBase abstract class
- Loading branch information
Showing
2 changed files
with
26 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Tests/TutorLizard.BusinessLogic.Tests/TestsWithInMemoryDbBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using TutorLizard.BusinessLogic.Data; | ||
|
||
namespace TutorLizard.BusinessLogic.Tests; | ||
public abstract class TestsWithInMemoryDbBase : IDisposable | ||
{ | ||
protected JaszczurContext DbContext; | ||
|
||
protected TestsWithInMemoryDbBase() | ||
{ | ||
DbContext = SetupInMemoryDbContext(); | ||
} | ||
public void Dispose() | ||
{ | ||
DbContext.Dispose(); | ||
} | ||
private JaszczurContext SetupInMemoryDbContext() | ||
{ | ||
DbContextOptionsBuilder<JaszczurContext> dbBuilder = new(); | ||
dbBuilder.UseInMemoryDatabase(databaseName: $"FakeDb{Guid.NewGuid()}"); | ||
JaszczurContext context = new(dbBuilder.Options); | ||
return context; | ||
} | ||
} |