Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ public async Task MerchantStatementDomainService_BuildStatement_GetMerchantFaile
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task MerchantStatementDomainService_BuildStatement_MerchantNotCreated_StatementIsNotBuilt()
{
this.AggregateService.Setup(a => a.GetLatest<MerchantStatementAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.GeneratedMerchantStatementAggregate()));
this.AggregateService.Setup(a => a.Save<MerchantStatementAggregate>(It.IsAny<MerchantStatementAggregate>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success);

this.AggregateService.Setup(a => a.GetLatest<MerchantStatementForDateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.MerchantStatementForDateAggregateWithTransactionAndFee()));

this.AggregateService.Setup(a => a.Get<MerchantAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate()));

this.StatementBuilder.Setup(s => s.GetStatementHtml(It.IsAny<MerchantStatementAggregate>(), It.IsAny<Merchant>(), It.IsAny<CancellationToken>())).ReturnsAsync("<html></html>");

Result result = await this.DomainService.BuildStatement(TestData.Commands.BuildMerchantStatementCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task MerchantStatementDomainService_BuildStatement_SaveFailed_StatementIsNotBuilt()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,14 @@ public async Task<Result> BuildStatement(MerchantStatementCommands.BuildMerchant
if (getMerchantResult.IsFailed)
return ResultHelpers.CreateFailure(getMerchantResult);

if (getMerchantResult.Data.IsCreated == false)
return Result.Invalid("Merchant must be created to build a statement");

Merchant merchantModel = getMerchantResult.Data.GetMerchant();

if (merchantModel.Addresses.Any() == false)
return Result.Invalid("Merchant must have an address to build a statement");

Result<String> htmlResult = await this.StatementBuilder.GetStatementHtml(merchantStatementAggregate, merchantModel, cancellationToken);
if (htmlResult.IsFailed)
return ResultHelpers.CreateFailure(htmlResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public async Task<Result<String>> GetStatementHtml(MerchantStatementAggregate st
Merchant merchant,
CancellationToken cancellationToken)
{
// TODO: Check merchant and addresses exist

IDirectoryInfo path = this.FileSystem.Directory.GetParent(Assembly.GetExecutingAssembly().Location);
MerchantStatement statementHeader = statementAggregate.GetStatement();

Expand Down
Loading