public void MapToViewModel_CorrectObject_FullObject() { // arrange var rateInput = new RateCalculation { Rate = (decimal)2.51, RateValue = (decimal)2.5 }; var calculationInput = new CalculateRatesInputModel { SecondCurrency = "USD", FirstCurrency = "LOT", Value = (decimal)12.3 }; // act var result = RateMapper.MapToViewModel(rateInput, calculationInput); // assert Assert.Equal(rateInput.RateValue, result.RateValue); Assert.Equal(rateInput.Rate, result.Rate); Assert.Equal(calculationInput.FirstCurrency, result.FirtsCurrency); Assert.Equal(calculationInput.SecondCurrency, result.SecondCurrency); Assert.Equal(calculationInput.Value, result.Amount); }
public async Task CalculateRates_WhenCurrencyDoesntExist_ReturnException() { //arrange _rateLogic = new RateLogic(MockHelper.GetDataLoadLogicWithMocks()); var request = new CalculateRatesInputModel { FirstCurrency = "USD", SecondCurrency = "AAA", Value = 10 }; // assert await Assert.ThrowsAsync <CurrencyNotFoundException>(() => _rateLogic.CalculateRates(request)); }
public async Task <IActionResult> CalculateRates(CalculateRatesInputModel calculateRatesInputModel) { try { var result = await _rateLogic.CalculateRates(calculateRatesInputModel); return(Ok(result)); } catch (CurrencyNotFoundException ex) { return(BadRequest(ex.Message)); } catch { return(BadRequest("Error unknown")); } }
public async Task <CalculateRatesResponseModel> CalculateRates(CalculateRatesInputModel calculateRatesInputModel) { var firstCurrency = await _dataLoadLogic.GetCurrency(calculateRatesInputModel.FirstCurrency); var secondCurrency = await _dataLoadLogic.GetCurrency(calculateRatesInputModel.SecondCurrency); if (firstCurrency == null || secondCurrency == null) { throw new CurrencyNotFoundException(); } var rateCalculation = new RateCalculation() { RateValue = CaclulateRateValue(firstCurrency.Value, secondCurrency.Value, calculateRatesInputModel.Value), Rate = CaclulateRate(firstCurrency.Value, secondCurrency.Value) }; return(RateMapper.MapToViewModel(rateCalculation, calculateRatesInputModel)); }
public async Task CalculateRates_WhenDataValid_ReturnRateObject() { //arrange _rateLogic = new RateLogic(MockHelper.GetDataLoadLogicWithMocks()); var request = new CalculateRatesInputModel { FirstCurrency = "USD", SecondCurrency = "JPY", Value = 10 }; // act var result = await _rateLogic.CalculateRates(request); // assert Assert.Equal(request.FirstCurrency, result.FirtsCurrency); Assert.Equal(request.SecondCurrency, result.SecondCurrency); Assert.Equal(request.Value, result.Amount); Assert.Equal((decimal)1050.59, result.RateValue); Assert.Equal((decimal)105.0595, result.Rate); }
public static CalculateRatesResponseModel MapToViewModel(RateCalculation rateItem, CalculateRatesInputModel rateInput) { var result = new CalculateRatesResponseModel() { Rate = rateItem.Rate, RateValue = rateItem.RateValue, Amount = rateInput.Value, FirtsCurrency = rateInput.FirstCurrency, SecondCurrency = rateInput.SecondCurrency }; return(result); }