Ejemplo n.º 1
0
        public void AddChangeTransaction(ChangeTransaction changeTransaction)
        {
            if (State == SaleState.Completed || State == SaleState.Cancelled)
            {
                throw new InvalidOperationException("Change cannot be given on a Completed or Cancelled sale.");
            }

            if (Balance >= 0)
            {
                throw new InvalidOperationException("Change can only be given on a sale with a negative balance.");
            }

            if (changeTransaction.Amount > Math.Abs(Balance))
            {
                throw new InvalidOperationException("Change amount cannot exceed change due amount.");
            }

            _changeTransactions.Add(changeTransaction);
            calculateBalance();
        }
Ejemplo n.º 2
0
 public static StateTransitionResult <SaleState, SaleEvent> Fire(Sale sale, SaleEvent saleEvent, ChangeTransaction change)
 {
     return(_saleStateManager.FireTrigger(sale, saleEvent, change));
 }