feat(Fake): Erweiterung von Fake.Host um Repository-Zugriff und Unterstützung für Beispielbenutzer
- IRepository<TEntity>-Verknüpfung zum Auflösen von Repositorys hinzugefügt - AddSamples()-Hilfsprogramm zum gemeinsamen Initialisieren von Empfängern und Benutzern eingeführt - SampleReceivers mit Validierungsüberwachung verbessert - Beispiel für Benutzerinitialisierung über Repository mit AddSampleUser() hinzugefügt - using-Anweisungen aktualisiert, um DigitalData.Core.Abstraction.Application.Repository und DigitalData.UserManager.Domain.Entities einzubeziehen
This commit is contained in:
parent
d3e5d3d791
commit
68878c0fc8
@ -1,4 +1,6 @@
|
||||
using Bogus;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using DigitalData.UserManager.Domain.Entities;
|
||||
using EnvelopeGenerator.Application;
|
||||
using EnvelopeGenerator.Application.Envelopes.Commands;
|
||||
using EnvelopeGenerator.Application.Receivers.Commands;
|
||||
@ -67,14 +69,30 @@ public class Fake
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Shortcuts
|
||||
public IMediator Mediator => Services.GetRequiredService<IMediator>();
|
||||
|
||||
public IRepository<TEntity> GetRepository<TEntity>() => Services.GetRequiredService<IRepository<TEntity>>();
|
||||
|
||||
public async Task<Host> AddSamples()
|
||||
{
|
||||
await AddSampleReceivers();
|
||||
await AddSampleUser();
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Sample Receivers
|
||||
public List<(int Id, string EmailAddress)> _sampleReceivers = new();
|
||||
|
||||
public IEnumerable<(int Id, string EmailAddress)> SampleReceivers => _sampleReceivers;
|
||||
public IEnumerable<(int Id, string EmailAddress)> SampleReceivers
|
||||
=> _sampleReceivers.Any()
|
||||
? _sampleReceivers
|
||||
: throw new InvalidOperationException(
|
||||
"No sample receivers have been initialized. Call AddSampleReceivers() before accessing this property."
|
||||
);
|
||||
|
||||
public async Task AddSampleReceivers()
|
||||
public async Task<Host> AddSampleReceivers()
|
||||
{
|
||||
var mediator = Mediator;
|
||||
foreach (var cmd in Provider.CreateReceiverCommands())
|
||||
@ -82,6 +100,22 @@ public class Fake
|
||||
var (Id, _) = await mediator.Send(cmd);
|
||||
_sampleReceivers.Add((Id, cmd.EmailAddress));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Sample User
|
||||
private User? _user;
|
||||
|
||||
public User User => _user ?? throw new InvalidOperationException(
|
||||
"The 'User' instance has not been initialized. Call AddSampleUser() before accessing this property.");
|
||||
|
||||
public async Task<Host> AddSampleUser()
|
||||
{
|
||||
var repo = GetRepository<User>();
|
||||
var cmd = Provider.CreateUserCommand();
|
||||
_user = await repo.CreateAsync(cmd);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user