public async Task When_AddMoney_Then_ShouldReturn_Ok()
        {
            var fixture        = new Fixture();
            var moneyRequesDto = new MoneyRequesDto();


            _moneyExchangeAppServiceMock.Setup(x => x.AddMoney(moneyRequesDto));

            var moneyController = new MoneyController(_moneyExchangeAppServiceMock.Object);

            var result = await moneyController.AddMoney(moneyRequesDto);

            result.ShouldBeOfType <OkObjectResult>();
        }
        public async Task AddMoney(MoneyRequesDto moneyRequest)
        {
            var user = await _userRepository.GetAsync(moneyRequest.UserId);

            if (user == null)
            {
                throw new UserNotFoundException($"UserId={moneyRequest.UserId} is not found.");
            }

            var currency = await _currencyRepository.GetAsync(moneyRequest.CurrencyName);

            user.AddMoney(new Money(moneyRequest.Amount, currency));

            await _userRepository.UpdateBalanceSync(user);
        }
Exemple #3
0
        public async Task When_AddMoney_And_NoUserFound_Then_ShouldReturn_Exception()
        {
            var  userId       = 0;
            var  moneyRequest = new MoneyRequesDto();
            User user         = null;

            try
            {
                _userRepositoryMock.Setup(x => x.GetAsync(userId)).Returns(Task.FromResult(user));

                var moneyExchangeService =
                    new MoneyExchangeAppService(_userRepositoryMock.Object, _currencyRepository.Object);

                await moneyExchangeService.AddMoney(moneyRequest);

                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.Pass();
            }
        }
        public async Task <IActionResult> AddMoney([FromBody] MoneyRequesDto moneyRequest)
        {
            await _moneyExchangeAppService.AddMoney(moneyRequest);

            return(Ok(1));
        }