public void VoucherAggregate_Generate_VoucherAlreadyIssued_ErrorThrown() { VoucherAggregate aggregate = VoucherAggregate.Create(TestData.VoucherId); aggregate.Generate(TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.GeneratedDateTime, TestData.Value); aggregate.Issue(TestData.RecipientEmail, TestData.RecipientMobile, TestData.IssuedDateTime); Should.Throw <InvalidOperationException>(() => { aggregate.Generate(TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.IssuedDateTime, TestData.Value); }); }
/// <summary> /// Issues the voucher. /// </summary> /// <param name="voucherId">The voucher identifier.</param> /// <param name="operatorId">The operator identifier.</param> /// <param name="estateId">The estate identifier.</param> /// <param name="transactionId">The transaction identifier.</param> /// <param name="issuedDateTime">The issued date time.</param> /// <param name="value">The value.</param> /// <param name="recipientEmail">The recipient email.</param> /// <param name="recipientMobile">The recipient mobile.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <IssueVoucherResponse> IssueVoucher(Guid voucherId, String operatorId, Guid estateId, Guid transactionId, DateTime issuedDateTime, Decimal value, String recipientEmail, String recipientMobile, CancellationToken cancellationToken) { await this.ValidateVoucherIssue(estateId, operatorId, cancellationToken); VoucherAggregate voucher = await this.VoucherAggregateRepository.GetLatestVersion(voucherId, cancellationToken); voucher.Generate(operatorId, estateId, transactionId, issuedDateTime, value); var voucherModel = voucher.GetVoucher(); // Generate the barcode Barcode barcode = new Barcode(voucherModel.VoucherCode); voucher.AddBarcode(barcode.GetBase64Image()); voucher.Issue(recipientEmail, recipientMobile, issuedDateTime); await this.VoucherAggregateRepository.SaveChanges(voucher, cancellationToken); return(new IssueVoucherResponse { ExpiryDate = voucherModel.ExpiryDate, Message = voucherModel.Message, VoucherCode = voucherModel.VoucherCode, VoucherId = voucherId }); }
public void VoucherAggregate_Generate_InvalidValue_ErrorIsThrown(Decimal value) { VoucherAggregate aggregate = VoucherAggregate.Create(TestData.VoucherId); Should.Throw <ArgumentOutOfRangeException>(() => { aggregate.Generate(TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.GeneratedDateTime, value); }); }
public void VoucherAggregate_Generate_InvalidEstateId_ErrorIsThrown() { VoucherAggregate aggregate = VoucherAggregate.Create(TestData.VoucherId); Should.Throw <ArgumentNullException>(() => { aggregate.Generate(TestData.OperatorIdentifier, Guid.Empty, TestData.TransactionId, TestData.GeneratedDateTime, TestData.Value); }); }
public static VoucherAggregate GetVoucherAggregateWithRecipientMobile() { VoucherAggregate aggregate = VoucherAggregate.Create(TestData.VoucherId); aggregate.Generate(TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.GeneratedDateTime, TestData.Value); aggregate.AddBarcode(TestData.Barcode); aggregate.Issue(null, TestData.RecipientMobile, TestData.IssuedDateTime); return(aggregate); }
public void VoucherAggregate_Redeem_VoucherNotIssued_ErrorThrown() { VoucherAggregate aggregate = VoucherAggregate.Create(TestData.VoucherId); aggregate.Generate(TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.GeneratedDateTime, TestData.Value); Should.Throw <InvalidOperationException>(() => { aggregate.Redeem(TestData.RedeemedDateTime); }); }
public void VoucherAggregate_AddBarcode_BarcodeIsAdded() { VoucherAggregate aggregate = VoucherAggregate.Create(TestData.VoucherId); aggregate.Generate(TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.GeneratedDateTime, TestData.Value); aggregate.AddBarcode(TestData.Barcode); var voucher = aggregate.GetVoucher(); voucher.Barcode.ShouldBe(TestData.Barcode); }
public void VoucherAggregate_Issue_EitherEmailOrMobileIsRequired_ErrorThrown(String recipientEmail, String recipientMobile) { VoucherAggregate aggregate = VoucherAggregate.Create(TestData.VoucherId); aggregate.Generate(TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.GeneratedDateTime, TestData.Value); Should.Throw <ArgumentNullException>(() => { aggregate.Issue(recipientEmail, recipientMobile, TestData.IssuedDateTime); }); }
public void VoucherAggregate_Issue_VoucherIsIssued() { VoucherAggregate aggregate = VoucherAggregate.Create(TestData.VoucherId); aggregate.Generate(TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.GeneratedDateTime, TestData.Value); aggregate.Issue(TestData.RecipientEmail, TestData.RecipientMobile, TestData.IssuedDateTime); var voucher = aggregate.GetVoucher(); voucher.IsIssued.ShouldBeTrue(); }
public void VoucherAggregate_AddBarcode_InvalidBarcode_ErrorThrown(String barcode) { VoucherAggregate aggregate = VoucherAggregate.Create(TestData.VoucherId); aggregate.Generate(TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.GeneratedDateTime, TestData.Value); Should.Throw <ArgumentException>(() => { aggregate.AddBarcode(barcode); }); }
public void VoucherAggregate_Generate_VoucherIsGenerated() { VoucherAggregate aggregate = VoucherAggregate.Create(TestData.VoucherId); aggregate.Generate(TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.GeneratedDateTime, TestData.Value); var voucher = aggregate.GetVoucher(); voucher.IsGenerated.ShouldBeTrue(); voucher.EstateId.ShouldBe(TestData.EstateId); voucher.IsIssued.ShouldBeFalse(); voucher.GeneratedDateTime.ShouldBe(TestData.GeneratedDateTime); voucher.VoucherCode.ShouldNotBeNullOrEmpty(); voucher.TransactionId.ShouldBe(TestData.TransactionId); }