88 lines
2.4 KiB
C#
88 lines
2.4 KiB
C#
using EnvelopeGenerator.Application.Extensions;
|
|
using EnvelopeGenerator.Application.Histories.Commands;
|
|
using EnvelopeGenerator.Application.Histories.Queries;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
|
|
namespace EnvelopeGenerator.Tests.Application;
|
|
|
|
[TestFixture]
|
|
public class HistoryTests : TestBase
|
|
{
|
|
[SetUp]
|
|
public override Task Setup()
|
|
{
|
|
return base.Setup();
|
|
}
|
|
|
|
[TearDown]
|
|
public override void TearDown()
|
|
{
|
|
base.TearDown();
|
|
}
|
|
|
|
[Test]
|
|
public async Task CreateHistory_And_ReadHistory_Should_Work()
|
|
{
|
|
/// Arrange
|
|
CancellationToken cancel = default;
|
|
|
|
// Create envelope
|
|
var envelope = FakeEnvelope;
|
|
envelope = await GetRepository<Envelope>().CreateAsync(envelope, cancel);
|
|
|
|
// Create receiver
|
|
var createReceiverCmd = this.CreateReceiverCommand();
|
|
(var receiver, _) = await Mediator.Send(createReceiverCmd);
|
|
|
|
var key = (envelope.Uuid, receiver.Signature).ToEnvelopeKey();
|
|
|
|
var createCmd = Fake.Provider.CreateHistoryCommand(key);
|
|
|
|
// Act
|
|
var hist = await Mediator.Send(createCmd);
|
|
|
|
// Assert
|
|
Assert.That(hist, Is.Not.Null);
|
|
}
|
|
|
|
[Test]
|
|
public async Task ReadHistory_Should_Filter_By_Status()
|
|
{
|
|
// Arrange
|
|
var createCmd1 = new CreateHistoryCommand
|
|
{
|
|
EnvelopeId = 2,
|
|
UserReference = "UserX",
|
|
Status = EnvelopeStatus.EnvelopeCreated
|
|
};
|
|
|
|
var createCmd2 = new CreateHistoryCommand
|
|
{
|
|
EnvelopeId = 2,
|
|
UserReference = "UserX",
|
|
Status = EnvelopeStatus.EnvelopePartlySigned
|
|
};
|
|
|
|
await Mediator.Send(createCmd1);
|
|
await Mediator.Send(createCmd2);
|
|
|
|
// Act
|
|
var result = await Mediator.Send(new ReadHistoryQuery(2, EnvelopeStatus.EnvelopePartlySigned));
|
|
|
|
// Assert
|
|
Assert.That(result, Has.Exactly(1).Items);
|
|
Assert.That(result, Has.All.Matches<EnvelopeGenerator.Application.Dto.EnvelopeHistory.EnvelopeHistoryDto>(
|
|
r => r.Status == EnvelopeStatus.EnvelopePartlySigned));
|
|
}
|
|
|
|
[Test]
|
|
public async Task ReadHistory_Should_Return_Empty_When_No_Record()
|
|
{
|
|
// Act
|
|
var result = await Mediator.Send(new ReadHistoryQuery(999));
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
} |