public async Task GetExchange_OnCall_Success() { // Arrange var exchange = new GetExchangeResponse { BuyPrice = 30.0M, SellPrice = 40.0M }; _mockExternalService.GetExchangeAsync(_target.CurrencyName) .Returns(Task.FromResult(exchange)); // Act var result = await _target.GetExchange(); // Assert Assert.IsNotNull(result); }
public async Task <ActionResult <GetExchangeResponse> > GetExchange(GetExchangeRequest request) { try { _currencyController = _currencyControllerFactory.CreateCurrencyController(request.CurrencyCode.ToUpper()); return(await _currencyController.GetExchange()); } 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)); } }
public async Task <GetExchangeResponse> GetExchange() { GetExchangeResponse result = null; try { var dollarExchange = await _dollarController.GetExchange(); result = new GetExchangeResponse { BuyPrice = dollarExchange.BuyPrice / 4, SellPrice = dollarExchange.SellPrice / 4 }; } catch (Exception exception) { _logger.LogError(exception, "Unhandled exception"); } return(result); }