public async Task <IActionResult> CreateWallet([FromBody] CreateWalletRequest request)
        {
            var createWalletCommand = new CreateWalletCommand(request);
            var result = await mediator.Send(createWalletCommand);

            return(StatusCode((int)result.Code, result.Value));
        }
예제 #2
0
        public async Task <IActionResult> Post(CreateWalletCommand command)
        {
            command.InvestorId = InvestorId;
            await _dispatcher.SendAsync(command);

            return(Ok());
        }
        public async Task CanCreateWalletAsync()
        {
            CreateWalletCommand command = new CreateWalletCommand
            {
                Name       = "default",
                Timestamp  = 1605037286186,
                CustomerId = "asd1212112qx"
            };

            Assert.NotNull((await walletController.CreateWallet(command)).Value);
        }
예제 #4
0
        public async Task CreateWalletSuccessful()
        {
            var sut = new CreateWalletCommandHandler(context);

            var command = new CreateWalletCommand
            {
                UserId   = "test_user_id",
                Currency = "EUR"
            };

            var result = await sut.Handle(command, CancellationToken.None);

            Assert.IsTrue(result.IsSuccessful);
        }
        public async Task <IActionResult> CreateWallet([FromQuery] string currency)
        {
            var createWalletCommand = new CreateWalletCommand
            {
                UserId   = userManager.GetUserId(User),
                Currency = currency
            };
            var createWalletResult = await mediator.Send(createWalletCommand);

            if (!createWalletResult.IsSuccessful)
            {
                return(BadRequest());
            }

            return(Ok());
        }
예제 #6
0
        public async Task CreateWalletInvalidCurrency()
        {
            var sut = new CreateWalletCommandHandler(context);

            var command = new CreateWalletCommand
            {
                UserId   = "test_user_id",
                Currency = "RUB"
            };

            var result = await sut.Handle(command, CancellationToken.None);

            Assert.Multiple(() =>
            {
                Assert.IsFalse(result.IsSuccessful);
                Assert.AreEqual("INVALID_CURRENCY", result.FailureReason);
            });
        }
예제 #7
0
        public async Task <ActionResult <Wallet> > CreateWallet(CreateWalletCommand command)
        {
            var wallet = new Wallet
            {
                Id         = GenerateAccountNumber(),
                CustomerId = command.CustomerId,
                Name       = command.Name,
                Balance    = 0,
                Deleted    = false,
                CreatedAt  = DateTime.Now,
                Timestamp  = command.Timestamp
            };

            _context.Wallets.Add(wallet);
            await _context.SaveChangesAsync();

            return(wallet);
        }
        public async Task CreateWalletTestAmount()
        {
            var sut = new CreateWalletCommandHandler(context, promotionManagerMock.Object);

            var command = new CreateWalletCommand
            {
                UserId   = "test_user_id",
                Currency = "EUR"
            };

            var result = await sut.Handle(command, CancellationToken.None);

            Assert.Multiple(() =>
            {
                Assert.IsTrue(result.IsSuccessful);
                Assert.AreEqual(500, result.Amount);
            });
        }
예제 #9
0
        public async Task <IActionResult> CreateWalletAsync([FromBody] CreateWalletCommand createWalletCommand)
        {
            _logger.LogInformation(
                "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
                createWalletCommand.GetGenericTypeName(),
                nameof(createWalletCommand.UserId),
                createWalletCommand.UserId,
                createWalletCommand);

            var commandResult = await Mediator.Send(createWalletCommand);

            if (!commandResult)
            {
                return(StatusCode(500, new { error = "Wallet can't be created." }));
            }

            return(Ok());
        }
예제 #10
0
 // POST: api/Wallet
 public HttpResponseMessage Post([FromBody] CreateWalletCommand value)
 {
     return(CreateResponse(_commandHandler.Handle(value)));
 }
예제 #11
0
 public async Task <ActionResult <Wallet> > CreateWallet(CreateWalletCommand command)
 {
     return(await _walletWriteService.CreateWallet(command));
 }