示例#1
0
            public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
            {
                var exchangeName = node.Expression.ToString();

                if (exchangeName.StartsWith("ERR_", StringComparison.OrdinalIgnoreCase))
                {
                    Errors.Add(RateRulesErrors.PreprocessError);
                    return(base.VisitInvocationExpression(node));
                }

                var currencyPair = node.ArgumentList.ChildNodes().FirstOrDefault()?.ToString();

                if (currencyPair == null || !CurrencyPair.TryParse(currencyPair, out var pair))
                {
                    Errors.Add(RateRulesErrors.InvalidCurrencyIdentifier);
                    return(RateRules.CreateExpression($"ERR_INVALID_CURRENCY_PAIR({node.ToString()})"));
                }
                else
                {
                    var rate = Rates.GetRate(exchangeName, pair);
                    if (rate == null)
                    {
                        Errors.Add(RateRulesErrors.RateUnavailable);
                        return(RateRules.CreateExpression($"ERR_RATE_UNAVAILABLE({exchangeName}, {pair.ToString()})"));
                    }
                    else
                    {
                        return(RateRules.CreateExpression(rate.ToString()));
                    }
                }
            }
示例#2
0
        public void AreAllRates()
        {
            //Arrange
            Currency[]    currencies = new Currency[] { Currency.AUD, Currency.CAD, Currency.CHF, Currency.EUR, Currency.GBP, Currency.JPY, Currency.USD };
            ExchangeRates rates      = new ExchangeRates();
            string        res        = "";
            decimal       rate       = 0;

            //Act
            for (int i = 0; i < currencies.Length; i++)
            {
                for (int j = 0; j < currencies.Length; j++)
                {
                    try
                    {
                        rate = rates.GetRate(currencies[i], currencies[j]);
                    }
                    catch
                    {
                        res += currencies[i].ToString() + "-" + currencies[j].ToString() + "|";
                    }
                    if (i == j && rate != 1m)
                    {
                        res += currencies[i].ToString() + "-" + currencies[j].ToString() + "|";
                    }
                }
            }

            //Assert
            Assert.AreEqual("", res);
        }
示例#3
0
 public void GetRate()
 {
     Assert.IsNotNull(exchangeRate.GetRate(1, "USD", "EUR"));
 }