Modified `AddDbRepository` method to allow broader entity types and registered `queryFactory` as a singleton. Added necessary using directives in `DbRepositoryTests.cs` and updated the `Setup` method to configure an in-memory database for testing with `MockDbContext` and `User` entity.
32 lines
776 B
C#
32 lines
776 B
C#
namespace DigitalData.Core.Tests.Infrastructure;
|
|
|
|
using DigitalData.Core.Infrastructure;
|
|
using DigitalData.Core.Tests.Mock;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
public class DbRepositoryTests
|
|
{
|
|
private IHost _host;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
var builder = Host.CreateApplicationBuilder();
|
|
|
|
builder.Services.AddDbContext<MockDbContext>(opt => opt.UseInMemoryDatabase("MockDB"));
|
|
|
|
builder.Services.AddDbRepository<MockDbContext, User>(context => context.Users);
|
|
|
|
_host = builder.Build();
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
if (_host is IDisposable disposableHost)
|
|
disposableHost.Dispose();
|
|
}
|
|
}
|