refactor(HistoryTests): create and implement TestBase

This commit is contained in:
tekh 2025-09-01 15:19:52 +02:00
parent 950ae5a418
commit bb93b980b4
2 changed files with 45 additions and 19 deletions

View File

@ -1,47 +1,42 @@
using DigitalData.UserManager.Domain.Entities;
using EnvelopeGenerator.Application.Envelopes.Commands;
using EnvelopeGenerator.Application.Histories.Commands;
using EnvelopeGenerator.Application.Histories.Commands;
using EnvelopeGenerator.Application.Histories.Queries;
using EnvelopeGenerator.Domain.Constants;
namespace EnvelopeGenerator.Tests.Application;
[TestFixture]
public class HistoryTests
public class HistoryTests : TestBase
{
private Fake.Host _host;
[SetUp]
public async Task Setup()
public override Task Setup()
{
_host = Fake.CreateHost();
await _host.AddSamples();
return base.Setup();
}
[TearDown]
public void TearDown()
public override void TearDown()
{
_host.Dispose();
base.TearDown();
}
[Test]
public async Task CreateHistory_And_ReadHistory_Should_Work()
{
// Arrange
var createEnvelopeCmd = Fake.Provider.CreateEnvelopeCommand(_host.User.Id);
var envelope = await _host.Mediator.Send(createEnvelopeCmd);
var createEnvelopeCmd = FakeCreateEnvelopeCommand;
var envelope = await Mediator.Send(createEnvelopeCmd);
var key = string.Empty;
var createCmd = Fake.Provider.CreateHistoryCommand(key);
// Act
var id = await _host.Mediator.Send(createCmd);
var id = await Mediator.Send(createCmd);
// Assert
Assert.That(id, Is.Not.Null);
// ReadHistory query
var query = new ReadHistoryQuery(1);
var result = await _host.Mediator.Send(query);
var result = await Mediator.Send(query);
Assert.That(result, Is.Not.Empty);
}
@ -64,11 +59,11 @@ public class HistoryTests
Status = EnvelopeStatus.EnvelopePartlySigned
};
await _host.Mediator.Send(createCmd1);
await _host.Mediator.Send(createCmd2);
await Mediator.Send(createCmd1);
await Mediator.Send(createCmd2);
// Act
var result = await _host.Mediator.Send(new ReadHistoryQuery(2, EnvelopeStatus.EnvelopePartlySigned));
var result = await Mediator.Send(new ReadHistoryQuery(2, EnvelopeStatus.EnvelopePartlySigned));
// Assert
Assert.That(result, Has.Exactly(1).Items);
@ -80,7 +75,7 @@ public class HistoryTests
public async Task ReadHistory_Should_Return_Empty_When_No_Record()
{
// Act
var result = await _host.Mediator.Send(new ReadHistoryQuery(999));
var result = await Mediator.Send(new ReadHistoryQuery(999));
// Assert
Assert.That(result, Is.Empty);

View File

@ -0,0 +1,31 @@
using Bogus;
using DigitalData.UserManager.Domain.Entities;
using EnvelopeGenerator.Application.Envelopes.Commands;
using EnvelopeGenerator.Application.Receivers.Commands;
using MediatR;
namespace EnvelopeGenerator.Tests.Application;
public class TestBase : Faker
{
private Fake.Host Host;
public User User => Host.User;
public IMediator Mediator => Host.Mediator;
public CreateEnvelopeCommand FakeCreateEnvelopeCommand => this.CreateEnvelopeCommand(Host.User.Id);
[SetUp]
public virtual async Task Setup()
{
Host = Fake.CreateHost();
await Host.AddSamples();
}
[TearDown]
public virtual void TearDown()
{
Host.Dispose();
}
}