@@ -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