コード例 #1
0
        public async Task <ActionResult> CreatePaymentAsync([FromHeader(Name = "ACCOUNT_KEY")] Guid accountId, [FromBody] CreatePaymentCommand createPaymentCommand)
        {
            var createAccountPaymentCommand = new CreateAccountPaymentCommand(accountId, createPaymentCommand);
            var paymentId = await _mediator.Send(createAccountPaymentCommand);

            return(CreatedAtAction(nameof(GetPaymentsAsync), new { id = paymentId }, null));
        }
コード例 #2
0
        public async void Handle_ShouldCreateClosedPayment()
        {
            var accountsRepo = new Mock <IAccountRepository>();

            var account = new Account(Guid.NewGuid(), 100);

            accountsRepo.Setup(a => a.GetAsync(account.Id)).ReturnsAsync(account);
            accountsRepo.Setup(p => p.UnitOfWork.SaveEntitiesAsync(It.IsAny <CancellationToken>())).ReturnsAsync(true);

            var amount = 200;
            var date   = new DateTime(2020, 3, 1);

            var command = new CreateAccountPaymentCommand(account.Id, new CreatePaymentCommand {
                Amount = amount, Date = date
            });

            var handler   = new CreateAccountPaymentHandler(accountsRepo.Object);
            var paymentId = await handler.Handle(command, new CancellationToken());

            Assert.Equal(100, account.Balance);
            Assert.Equal(amount, account.PaymentRequests.First().Amount);
            Assert.Equal(date, account.PaymentRequests.First().Date);
            Assert.Equal(PaymentStatus.Closed, account.PaymentRequests.First().Status);
        }