Пример #1
0
        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);
        }
Пример #2
0
        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));
        }
Пример #3
0
        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"));
            }
        }
Пример #4
0
        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));
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }