/// <summary> /// Makes the deposit. /// </summary> /// <param name="depositId">The deposit 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> public void MakeDeposit(MerchantDepositSource source, String reference, DateTime depositDateTime, Decimal amount) { String depositData = $"{depositDateTime.ToString("yyyyMMdd hh:mm:ss.fff")}-{reference}-{amount:N2}-{source}"; Guid depositId = this.GenerateGuidFromString(depositData); this.EnsureMerchantHasBeenCreated(); this.EnsureNotDuplicateDeposit(depositId); // TODO: Change amount to a value object (PositiveAmount VO) this.EnsureDepositSourceHasBeenSet(source); if (source == MerchantDepositSource.Manual) { ManualDepositMadeEvent manualDepositMadeEvent = new ManualDepositMadeEvent(this.AggregateId, this.EstateId, depositId, reference, depositDateTime, amount); this.ApplyAndAppend(manualDepositMadeEvent); } else if (source == MerchantDepositSource.Automatic) { // TODO: throw new NotSupportedException("Automatic deposits are not yet supported"); } }
/// <summary> /// Plays the event. /// </summary> /// <param name="manualDepositMadeEvent">The manual deposit made event.</param> private void PlayEvent(ManualDepositMadeEvent manualDepositMadeEvent) { Deposit deposit = Deposit.Create(manualDepositMadeEvent.DepositId, MerchantDepositSource.Manual, manualDepositMadeEvent.Reference, manualDepositMadeEvent.DepositDateTime, manualDepositMadeEvent.Amount); this.Deposits.Add(deposit); }
public void ManualDepositMadeEvent_CanBeCreated_IsCreated() { ManualDepositMadeEvent manualDepositMadeEvent = new ManualDepositMadeEvent(TestData.MerchantId, TestData.EstateId, TestData.DepositId, TestData.DepositReference, TestData.DepositDateTime, TestData.DepositAmount); manualDepositMadeEvent.ShouldNotBeNull(); manualDepositMadeEvent.AggregateId.ShouldBe(TestData.MerchantId); manualDepositMadeEvent.EventId.ShouldNotBe(Guid.Empty); manualDepositMadeEvent.EstateId.ShouldBe(TestData.EstateId); manualDepositMadeEvent.MerchantId.ShouldBe(TestData.MerchantId); manualDepositMadeEvent.DepositId.ShouldBe(TestData.DepositId); manualDepositMadeEvent.Reference.ShouldBe(TestData.DepositReference); manualDepositMadeEvent.DepositDateTime.ShouldBe(TestData.DepositDateTime); manualDepositMadeEvent.Amount.ShouldBe(TestData.DepositAmount); }