diff --git a/Tests/TutorLizard.BusinessLogic.Tests/Services/Browse/BrowseServiceTestsBase.cs b/Tests/TutorLizard.BusinessLogic.Tests/Services/Browse/BrowseServiceTestsBase.cs index ec4cadf8..de6e4f8a 100644 --- a/Tests/TutorLizard.BusinessLogic.Tests/Services/Browse/BrowseServiceTestsBase.cs +++ b/Tests/TutorLizard.BusinessLogic.Tests/Services/Browse/BrowseServiceTestsBase.cs @@ -8,23 +8,16 @@ namespace TutorLizard.BusinessLogic.Tests.Services.Browse; -public abstract class BrowseServiceTestsBase : IDisposable +public abstract class BrowseServiceTestsBase : TestsWithInMemoryDbBase { protected BrowseService BrowseService; - protected JaszczurContext DbContext; protected Fixture Fixture = new(); protected Mock> MockAdRepository = new(); protected Mock> MockScheduleItemRepository = new(); - public BrowseServiceTestsBase() + protected BrowseServiceTestsBase() : base() { BrowseService = new(MockAdRepository.Object, MockScheduleItemRepository.Object); - DbContext = SetupInMemoryDbContext(); - } - - public void Dispose() - { - DbContext.Dispose(); } protected void SetupMockGetAllAds(List ads) @@ -138,12 +131,4 @@ protected IQueryable AddEntitiesToInMemoryDb(List ent .Set() .AsQueryable(); } - - private JaszczurContext SetupInMemoryDbContext() - { - DbContextOptionsBuilder dbBuilder = new(); - dbBuilder.UseInMemoryDatabase(databaseName: $"FakeDb{Guid.NewGuid()}"); - JaszczurContext context = new(dbBuilder.Options); - return context; - } } \ No newline at end of file diff --git a/Tests/TutorLizard.BusinessLogic.Tests/TestsWithInMemoryDbBase.cs b/Tests/TutorLizard.BusinessLogic.Tests/TestsWithInMemoryDbBase.cs new file mode 100644 index 00000000..9cc5c53d --- /dev/null +++ b/Tests/TutorLizard.BusinessLogic.Tests/TestsWithInMemoryDbBase.cs @@ -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 dbBuilder = new(); + dbBuilder.UseInMemoryDatabase(databaseName: $"FakeDb{Guid.NewGuid()}"); + JaszczurContext context = new(dbBuilder.Options); + return context; + } +}