Exemple #1
0
        public async Task ConvertTest()
        {
            //Given
            var expected = new CurrencyAmount(8, ECurrencyType.USD);
            var input    = new CurrencyAmount(4, ECurrencyType.EUR);
            var currency = ECurrencyType.USD;

            _ratioSourceMock.Setup(f => f.GetRatio(input.Currency, currency))
            .Returns(Task.FromResult(2M));

            //When
            var actual = await _interactor.Convert(input, currency);

            //Then
            Assert.AreEqual(expected, actual);
            _ratioSourceMock.Verify(f => f.GetRatio(input.Currency, currency), Times.Once);
        }
Exemple #2
0
        public async Task <string> GetAmount(string amountStr, string from, string to)
        {
            var fromCur = default(ECurrencyType);
            var toCur   = default(ECurrencyType);
            var amount  = default(decimal);

            try
            {
                amount  = decimal.Parse(amountStr);
                fromCur = (ECurrencyType)Enum.Parse(typeof(ECurrencyType), from.ToUpper());
                toCur   = (ECurrencyType)Enum.Parse(typeof(ECurrencyType), to.ToUpper());
            }
            catch (Exception)
            {
                throw new ArgumentException();
            }

            return((await _converterInteractor.Convert(new CurrencyAmount(amount, fromCur), toCur)).ToString());
        }