This commit introduces a new test method `CreateAsync_ShouldPersistUser` in `DbRepositoryTests.cs`. The method tests the asynchronous creation of a user in the repository using the `Faker` library to generate user data. It asserts that no exceptions are thrown during the creation process. Additionally, the using directives have been updated to include `DigitalData.Core.Abstractions.Infrastructure`.
49 lines
1.3 KiB
C#
49 lines
1.3 KiB
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;
|
|
using System.Reflection;
|
|
using DigitalData.Core.Tests.Mock;
|
|
using DigitalData.Core.Abstractions.Infrastructure;
|
|
|
|
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);
|
|
|
|
builder.Services.AddAutoMapper(Assembly.GetExecutingAssembly());
|
|
|
|
_host = builder.Build();
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
if (_host is IDisposable disposableHost)
|
|
disposableHost.Dispose();
|
|
}
|
|
|
|
[Test]
|
|
public void CreateAsync_ShouldPersistUser()
|
|
{
|
|
// Arrange
|
|
var faker = Fake.CreateUserFaker();
|
|
var user = faker.Generate();
|
|
var repo = _host.Services.GetRequiredService<IRepository<User>>();
|
|
|
|
// Act & Assert
|
|
Assert.DoesNotThrowAsync(async () => await repo.CreateAsync(user));
|
|
}
|
|
}
|