Ejemplo n.º 1
0
        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);
            });
        }
Ejemplo n.º 2
0
        /// <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
            });
        }
Ejemplo n.º 3
0
        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);
            });
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 6
0
        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);
            });
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
            });
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        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);
            });
        }
Ejemplo n.º 11
0
        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);
        }