Beispiel #1
0
        public void MerchantAggregate_MakeDeposit_TwoDepositsOneMonthApartSameDetails_BothDepositsMade()
        {
            MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId);

            aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated);

            aggregate.MakeDeposit(TestData.MerchantDepositSourceManual, "Test Data Gen Deposit", new DateTime(2021, 1, 1, 0, 0, 0), 650.00m);
            aggregate.MakeDeposit(TestData.MerchantDepositSourceManual, "Test Data Gen Deposit", new DateTime(2021, 2, 1, 0, 0, 0), 650.00m);

            Merchant merchantModel = aggregate.GetMerchant();

            merchantModel.Deposits.Count.ShouldBe(2);
        }
Beispiel #2
0
        public void MerchantAggregate_MakeDeposit_TwoDeposits_BothDepositsMade()
        {
            MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId);

            aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated);

            aggregate.MakeDeposit(TestData.MerchantDepositSourceManual, TestData.DepositReference, TestData.DepositDateTime, TestData.DepositAmount);
            aggregate.MakeDeposit(TestData.MerchantDepositSourceManual, TestData.DepositReference2, TestData.DepositDateTime2, TestData.DepositAmount2);

            Merchant merchantModel = aggregate.GetMerchant();

            merchantModel.Deposits.Count.ShouldBe(2);
        }
Beispiel #3
0
        public void MerchantAggregate_MakeDeposit_DuplicateDeposit_ErrorThrown()
        {
            MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId);

            aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated);
            aggregate.MakeDeposit(TestData.MerchantDepositSourceManual, TestData.DepositReference, TestData.DepositDateTime, TestData.DepositAmount);
            Merchant merchantModel = aggregate.GetMerchant();

            merchantModel.Deposits.ShouldHaveSingleItem();

            Should.Throw <InvalidOperationException>(() =>
            {
                aggregate.MakeDeposit(TestData.MerchantDepositSourceManual, TestData.DepositReference, TestData.DepositDateTime, TestData.DepositAmount);
            });
        }
Beispiel #4
0
        public void MerchantAggregate_MakeDeposit_MerchantNotCreated_ErrorThrown()
        {
            MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId);

            Should.Throw <InvalidOperationException>(() =>
            {
                aggregate.MakeDeposit(TestData.MerchantDepositSourceManual, TestData.DepositReference, TestData.DepositDateTime, TestData.DepositAmount);
            });
        }
Beispiel #5
0
        public void MerchantAggregate_MakeDeposit_AutomaticDepositSource_ErrorThrown()
        {
            MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId);

            aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated);

            Should.Throw <NotSupportedException>(() =>
            {
                aggregate.MakeDeposit(TestData.MerchantDepositSourceAutomatic, TestData.DepositReference, TestData.DepositDateTime, TestData.DepositAmount);
            });
        }
Beispiel #6
0
        public void MerchantAggregate_MakeDeposit_DepositSourceNotSet_ErrorThrown()
        {
            MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId);

            aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated);

            Should.Throw <InvalidOperationException>(() =>
            {
                aggregate.MakeDeposit(MerchantDepositSource.NotSet, TestData.DepositReference, TestData.DepositDateTime, TestData.DepositAmount);
            });
        }
Beispiel #7
0
        public void MerchantAggregate_MakeDeposit_DepositMade()
        {
            MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId);

            aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated);

            aggregate.MakeDeposit(TestData.MerchantDepositSourceManual, TestData.DepositReference, TestData.DepositDateTime, TestData.DepositAmount);

            Merchant merchantModel = aggregate.GetMerchant();

            merchantModel.Deposits.ShouldHaveSingleItem();
            merchantModel.Deposits.Single().Source.ShouldBe(TestData.MerchantDepositSourceManual);
            //merchantModel.Deposits.Single().DepositId.ShouldNotBe(TestData.DepositId);
            merchantModel.Deposits.Single().DepositDateTime.ShouldBe(TestData.DepositDateTime);
            merchantModel.Deposits.Single().Reference.ShouldBe(TestData.DepositReference);
            merchantModel.Deposits.Single().Amount.ShouldBe(TestData.DepositAmount);
        }
Beispiel #8
0
        /// <summary>
        /// Makes the merchant deposit.
        /// </summary>
        /// <param name="estateId">The estate identifier.</param>
        /// <param name="merchantId">The merchant identifier.</param>
        /// <param name="source">The source.</param>
        /// <param name="reference">The reference.</param>
        /// <param name="depositDateTime">The deposit date time.</param>
        /// <param name="amount">The amount.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException">
        /// Merchant Id {merchantId} has not been created
        /// or
        /// Estate Id {estateId} has not been created
        /// </exception>
        public async Task <Guid> MakeMerchantDeposit(Guid estateId,
                                                     Guid merchantId,
                                                     Models.MerchantDepositSource source,
                                                     String reference,
                                                     DateTime depositDateTime,
                                                     Decimal amount,
                                                     CancellationToken cancellationToken)
        {
            MerchantAggregate merchantAggregate = await this.MerchantAggregateRepository.GetLatestVersion(merchantId, cancellationToken);

            // Check merchant has been created
            if (merchantAggregate.IsCreated == false)
            {
                throw new InvalidOperationException($"Merchant Id {merchantId} has not been created");
            }

            // Estate Id is a valid estate
            EstateAggregate estateAggregate = await this.EstateAggregateRepository.GetLatestVersion(estateId, cancellationToken);

            if (estateAggregate.IsCreated == false)
            {
                throw new InvalidOperationException($"Estate Id {estateId} has not been created");
            }

            merchantAggregate.MakeDeposit(source, reference, depositDateTime, amount);

            await this.MerchantAggregateRepository.SaveChanges(merchantAggregate, cancellationToken);

            Merchant merchant = merchantAggregate.GetMerchant();

            // Find the deposit
            Deposit deposit = merchant.Deposits.Single(d => d.Reference == reference && d.DepositDateTime == depositDateTime && d.Source == source &&
                                                       d.Amount == amount);

            return(deposit.DepositId);
        }