Ejemplo n.º 1
0
 /// <summary>
 /// Handle deposit money request.
 /// </summary>
 /// <param name="command">The deposit money command.</param>
 public void Handle(DepositMoney command)
 {
     if (Status == AccountStatus.Opened)
     {
         Raise(new MoneyDeposited(Type, Number, Balance + command.Amount, command.Amount));
     }
     else
     {
         Raise(new MoneyDepositFailed(Messages.AccountMustBeOpen.FormatWith(Status), command));
     }
 }
Ejemplo n.º 2
0
        private void SheduleDeposit(DepositMoney <int> message, IActorRef sender)
        {
            var time = _currentTime + DepositDuration;

            _innerTasks.Enqueue(new SheduledTask
            {
                Action       = () => ApplyDeposit(message, sender),
                SheduledTime = time
            });

            Log($"Deposit from {sender.Path.Name} sheduled at {time}");
        }
Ejemplo n.º 3
0
        public void DepositMoney_WithBankAccountNotCreated_Throws()
        {
            var bankAccountRepository = Substitute.For <IBankAccountRepository>();
            var systemUnderTest       = new DepositMoneyHandler(bankAccountRepository);
            var transaction           = Transaction.Of(Guid.Parse("f0ad5ace-c64f-4f82-9487-a26b376dcf8b"));
            var command     = new DepositMoney(DefaultBankAccountId, transaction, new Money(100, Currency.Euro), TimeStamp.Of(1));
            var bankAccount = BankAccount.Rehydrate(DefaultBankAccountId, Enumerable.Empty <BankAccountEvent>());

            bankAccountRepository.GetByIdAsync(DefaultBankAccountId).Returns(Task.FromResult(bankAccount));

            systemUnderTest.Awaiting(it => systemUnderTest.Handle(command, CancellationToken.None)).Should().Throw <ConstraintViolationException>();
        }
Ejemplo n.º 4
0
        public void DepositMoney_WithCurrencyMismatch_Throws(decimal amount, string currency, string accountCurrency)
        {
            var transaction           = Transaction.Of(Guid.Parse("f0ad5ace-c64f-4f82-9487-a26b376dcf8b"));
            var bankAccountRepository = Substitute.For <IBankAccountRepository>();
            var systemUnderTest       = new DepositMoneyHandler(bankAccountRepository);
            var bankAccount           = RehydrateWithCreatedEvent(DefaultBankAccountId, Currency.Of(accountCurrency));
            var command = new DepositMoney(DefaultBankAccountId, transaction, new Money(amount, Currency.Of(currency)), TimeStamp.Of(1));

            bankAccountRepository.GetByIdAsync(DefaultBankAccountId).Returns(Task.FromResult(bankAccount));

            systemUnderTest.Awaiting(it => systemUnderTest.Handle(command, CancellationToken.None)).Should().Throw <CurrencyMismatchException>();
        }
Ejemplo n.º 5
0
        private static Task Deposit(IMediator mediator, AvailableAccountsProjection availableAccountsProjection)
        {
            System.Console.Clear();
            System.Console.Write("IBAN: ");
            var iban = Iban.Of(System.Console.ReadLine());

            System.Console.Write("Amount: ");
            var amount        = decimal.Parse(System.Console.ReadLine());
            var bankAccountId = OId.Of <CoreDomain.BankAccount, Guid>(availableAccountsProjection.GetId(iban));
            var depositMoney  = new DepositMoney(bankAccountId,
                                                 Transaction.Of(Guid.NewGuid()),
                                                 new Money(amount, Currency.Euro),
                                                 TimeStamp.Of(DateTimeOffset.Now.ToUnixTimeSeconds()));

            return(mediator.Send(depositMoney));
        }
Ejemplo n.º 6
0
        private static async void OptionScreen2(IEndpointInstance endpointInstance, string cardNumber)
        {
            WriteOptionScreen2Options();

            while (true)
            {
                var key = Console.ReadKey();
                Console.WriteLine();
                var auditInfo = new AuditInfo {
                    By = cardNumber, Created = DateTime.UtcNow
                };
                double quantity;
                switch (key.Key)
                {
                case ConsoleKey.Escape:
                    break;

                case ConsoleKey.D1:
                    Console.WriteLine("Enter the amount to withdraw");
                    {
                        quantity = double.Parse(Console.ReadLine());
                        var message = new WithdrawMoney(auditInfo, cardNumber, quantity);
                        await endpointInstance.Send("CashCard.Service", message).ConfigureAwait(false);

                        WriteOptionScreen2Options();
                    }
                    break;

                case ConsoleKey.D2:
                    Console.WriteLine("Enter the amount to deposit");
                    {
                        quantity = double.Parse(Console.ReadLine());
                        var message = new DepositMoney(auditInfo, cardNumber, quantity);
                        await endpointInstance.Send("CashCard.Service", message).ConfigureAwait(false);

                        Console.WriteLine($"Checked and {quantity} has been deposited successfully..");
                        WriteOptionScreen2Options();
                    }
                    break;

                default:
                    Console.WriteLine("Please select correct option");
                    break;
                }
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            List <IVendorMachineContent> list = new List <IVendorMachineContent>();
            {
                list.Add(new Drink(1, "Coke", 20));
                list.Add(new Drink(2, "Sprite", 20));
                list.Add(new Drink(3, "Fanta", 20));
                list.Add(new Drink(4, "Bloody Mary", 75));
                list.Add(new Chocolate(5, "Mars", 15));
                list.Add(new Chocolate(6, "Snickers", 15));
                list.Add(new Chocolate(7, "Bounty", 15));
                list.Add(new Food(8, "Pizza", 95));
            }

            var DepositMoney = new DepositMoney();
            var Purchase     = new Purchase();

            Purchase.Menu();
            int money = DepositMoney.MoneyPool();

            while (true)
            {
                string Choice = Purchase.DisplaySelections();
                // while ( Choice != "Q") {

                if (money >= 15)
                {
                    money = Purchase.Selection(Choice, list, money);
                    Console.WriteLine(money);
                }
                else
                {
                    Console.WriteLine($"Here you have you money { money }");
                    Environment.Exit(-1);
                }
            }


            //else
            //{
            //     DepositMoney.MoneyPool();
            //}
            // Purchase.DisplaySelections();
        }
Ejemplo n.º 8
0
        public void DepositMoney_WithCorrectCurrency_DepositsMoneyInAccount(decimal amount, string currency)
        {
            var bankAccountRepository = Substitute.For <IBankAccountRepository>();
            var systemUnderTest       = new DepositMoneyHandler(bankAccountRepository);
            var transaction           = Transaction.Of(Guid.Parse("f0ad5ace-c64f-4f82-9487-a26b376dcf8b"));
            var accountCurrency       = Currency.Of(currency);
            var command     = new DepositMoney(DefaultBankAccountId, transaction, new Money(amount, accountCurrency), TimeStamp.Of(1));
            var bankAccount = RehydrateWithCreatedEvent(DefaultBankAccountId, accountCurrency);

            bankAccountRepository.GetByIdAsync(DefaultBankAccountId).Returns(Task.FromResult(bankAccount));

            systemUnderTest.Handle(command, CancellationToken.None).GetAwaiter().GetResult();

            var expectedEvents = new BankAccountEvent[] { new MoneyDeposited(DefaultBankAccountId.Value, transaction.Value, amount, 1) };

            bankAccountRepository.Received()
            .SaveAsync(Arg.Is <BankAccount>(it => it.IsCorrectBankAccount(aggregate =>
                                                                          aggregate.Version == 2 &&
                                                                          aggregate.InitialVersion == 0 &&
                                                                          aggregate.GetUncommittedEvents().SequenceEqual(expectedEvents))));
        }
Ejemplo n.º 9
0
        private void ApplyDeposit(DepositMoney <int> message, IActorRef sender)
        {
            _amountOfMoney += message.Amount;

            Log($"Deposit from {sender.Path.Name} applied");
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> DepositMoneyAsync(DepositMoney command)
        {
            await commandDispatcher.DispatchAsync(command);

            return(Ok());
        }