public ActionResult <Exchange> GetExchange(string from, string to, decimal amount) { if (!String.IsNullOrEmpty(from) && !String.IsNullOrEmpty(to)) { if (amount > 0) { ExchangeResponse r = new ExchangeResponse(); var exchangeInfo = _context.Exchanges.SingleOrDefault(x => x.from == from && x.to == to && x.isActive); if (exchangeInfo != null) { r = FormatterResponse.getInfoResponse(from, to, amount, exchangeInfo); } else { return(BadRequest(new { message = "There is not info with those money codes" })); } return(Ok(r)); } else { return(BadRequest(new { message = "please enter a valid amount" })); } } else { return(BadRequest(new { message = "the money codes are invalid" })); } }
public IActionResult GetMoneyPriceAndValue([FromBody] Exchange exchangeInput) { if (!String.IsNullOrEmpty(exchangeInput.from) && !String.IsNullOrEmpty(exchangeInput.to)) { if (exchangeInput.amount > 0) { ExchangeResponse r = new ExchangeResponse(); var exchangeInfo = _context.Exchanges.SingleOrDefault(x => x.from == exchangeInput.from && x.to == exchangeInput.to && x.isActive); if (exchangeInfo != null) { r = FormatterResponse.getInfoResponse(exchangeInput, exchangeInfo); } else { return(BadRequest(new { message = "There is not info with those money codes" })); } return(Ok(r)); } else { return(BadRequest(new { message = "please enter a valid amount" })); } } else { return(BadRequest(new { message = "the money codes are invalid" })); } }
public void GetExchange_ExistingMoneyExchangePassed_ReturnsExchange() { // Arrange string[] money = new string[] { "PEN", "USD" }; decimal amount = Convert.ToDecimal("100.00"); // Act var info = _service.GetExchange(money[0], money[1]); var r = FormatterResponse.getInfoResponse(money[0], money[1], amount, info); // Assert Assert.IsType <Exchange>(info); }
public void GetExchange_ExchangeOperationPassed_ReturnsValue() { // Arrange string[] money = new string[] { "PEN", "USD" }; decimal amount = Convert.ToDecimal("100.00"); // Act var info = _service.GetExchange(money[0], money[1]); var r = FormatterResponse.getInfoResponse(money[0], money[1], amount, info); decimal value = info.operation == "D" ? amount / info.rate : amount * info.rate; // Assert Assert.Equal(value, r.value); }