Skip to content

Commit cbf1bc4

Browse files
Merge pull request #1543 from TransactionProcessing/copilot/update-test-coverage-voucher-service
Add missing test coverage for VoucherDomainService failure paths
2 parents 4043a98 + 27b96a1 commit cbf1bc4

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

NuGet.Config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</packageSources>
77
<packageSourceCredentials>
88
<Feedz>
9-
<add key="Username" value="TestUser"/>
9+
<add key="Username" value="TestUser" />
1010
<add key="ClearTextPassword" value="T-jXeJSPLLjOdZvRZOQ5O2e1vrQwRI7uxC1U" />
1111
</Feedz>
1212
</packageSourceCredentials>

TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,69 @@ public async Task VoucherDomainService_RedeemVoucher_VoucherNotFound_ErrorThrown
193193
CancellationToken.None);
194194
result.IsFailed.ShouldBeTrue();
195195
}
196+
197+
[Fact]
198+
public async Task VoucherDomainService_IssueVoucher_GetVoucherFailed_ErrorThrown() {
199+
this.AggregateService.Setup(v => v.GetLatest<VoucherAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
200+
this.AggregateService.Setup(f => f.Get<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.EstateAggregateWithOperator()));
201+
202+
Result<IssueVoucherResponse> result = await this.VoucherDomainService.IssueVoucher(TestData.IssueVoucherCommand,
203+
CancellationToken.None);
204+
result.IsFailed.ShouldBeTrue();
205+
}
206+
207+
[Fact]
208+
public async Task VoucherDomainService_IssueVoucher_SaveFailed_ErrorThrown() {
209+
this.AggregateService.Setup(v => v.GetLatest<VoucherAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(new VoucherAggregate()));
210+
this.AggregateService.Setup(v => v.Save(It.IsAny<VoucherAggregate>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure);
211+
this.AggregateService.Setup(f => f.Get<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.EstateAggregateWithOperator()));
212+
213+
Result<IssueVoucherResponse> result = await this.VoucherDomainService.IssueVoucher(TestData.IssueVoucherCommand,
214+
CancellationToken.None);
215+
result.IsFailed.ShouldBeTrue();
216+
}
217+
218+
[Fact]
219+
public async Task VoucherDomainService_RedeemVoucher_GetVoucherAggregateFailed_ErrorThrown() {
220+
this.AggregateService.Setup(v => v.GetLatest<VoucherAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
221+
this.AggregateService.Setup(f => f.Get<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.CreatedEstateAggregate()));
222+
223+
this.Context.VoucherProjectionStates.Add(new TransactionProcessor.Database.Entities.VoucherProjectionState() {
224+
VoucherCode = TestData.VoucherCode,
225+
OperatorIdentifier = TestData.OperatorIdentifier,
226+
Barcode = TestData.Barcode,
227+
Timestamp = BitConverter.GetBytes(DateTime.UtcNow.Ticks)
228+
});
229+
await this.Context.SaveChangesAsync();
230+
231+
Result<RedeemVoucherResponse> result = await this.VoucherDomainService.RedeemVoucher(TestData.EstateId,
232+
TestData.VoucherCode,
233+
TestData.RedeemedDateTime,
234+
CancellationToken.None);
235+
result.IsFailed.ShouldBeTrue();
236+
}
237+
238+
[Fact]
239+
public async Task VoucherDomainService_RedeemVoucher_SaveFailed_ErrorThrown() {
240+
this.AggregateService.Setup(v => v.GetLatest<VoucherAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
241+
.ReturnsAsync(Result.Success(TestData.GetVoucherAggregateWithRecipientMobile()));
242+
this.AggregateService.Setup(v => v.Save(It.IsAny<VoucherAggregate>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure);
243+
this.AggregateService.Setup(f => f.Get<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.CreatedEstateAggregate()));
244+
245+
this.Context.VoucherProjectionStates.Add(new TransactionProcessor.Database.Entities.VoucherProjectionState() {
246+
VoucherCode = TestData.VoucherCode,
247+
OperatorIdentifier = TestData.OperatorIdentifier,
248+
Barcode = TestData.Barcode,
249+
Timestamp = BitConverter.GetBytes(DateTime.UtcNow.Ticks)
250+
});
251+
await this.Context.SaveChangesAsync();
252+
253+
Result<RedeemVoucherResponse> result = await this.VoucherDomainService.RedeemVoucher(TestData.EstateId,
254+
TestData.VoucherCode,
255+
TestData.RedeemedDateTime,
256+
CancellationToken.None);
257+
result.IsFailed.ShouldBeTrue();
258+
}
196259

197260
private EstateManagementContext GetContext(String databaseName)
198261
{

0 commit comments

Comments
 (0)