public async Task BuyCurrency_OnValidAmount_Success() { // Arrange var exchange = new GetExchangeResponse { BuyPrice = 30.0M, SellPrice = 40.0M }; _mockExternalService.GetExchangeAsync(_target.CurrencyName) .Returns(Task.FromResult(exchange)); _mockExchangeRepository.GetCurrentTotal(Arg.Any <int>(), "USD", Arg.Any <DateTime>()) .Returns(Task.FromResult(120M)); var amountInPesos = 2000; // Act var result = await _target.BuyCurrency(1, amountInPesos); // Assert Assert.IsTrue(result.BoughtAmount > 0.00M); }
public async Task <ActionResult <BuyCurrencyResponse> > BuyCurrency(BuyCurrencyRequest request) { try { _currencyController = _currencyControllerFactory.CreateCurrencyController(request.CurrencyCode.ToUpper()); return(StatusCode(StatusCodes.Status201Created, await _currencyController.BuyCurrency(request.UserId, request.Amount))); } catch (ArgumentException argumentException) { _logger.LogError(argumentException, "Invalid currency"); return(StatusCode(StatusCodes.Status400BadRequest, argumentException.Message)); } catch (Exception exception) { _logger.LogError(exception, "Unhandled exception"); return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message)); } }