Пример #1
0
 public PortfolioLogic(YahooFinanceClient yahooFinanceClient, TransactionDataManager transactionDataManager, ILogger <PortfolioLogic> logger, CurrencyClient currencyClient, CurrencyDataManager currencyDataManager)
 {
     _yahooFinanceClient     = yahooFinanceClient;
     _transactionDataManager = transactionDataManager;
     _logger              = logger;
     _currencyClient      = currencyClient;
     _currencyDataManager = currencyDataManager;
 }
Пример #2
0
        public void GetXMLTest()
        {
            //Arrange
            CurrencyClient currencyClient = new CurrencyClient();
            //Act
            string result = currencyClient.GetXML("31.03.2021");

            //Assert
            Assert.Contains("USD", result);
        }
Пример #3
0
        public void ParseValuteNullTest()
        {
            //Arrange
            CurrencyClient currencyClient = new CurrencyClient();
            //Act
            Action act = () => currencyClient.ParseValute(null);
            //Assert
            Exception exception = Assert.Throws <ArgumentNullException>(act);

            Assert.Equal("Value cannot be null. (Parameter 'xml')", exception.Message);
        }
Пример #4
0
        public Price Convert(Currency toCurrency)
        {
            var    currencyClient = new CurrencyClient();
            var    resutl         = currencyClient.GetCurrencyCourses(Currency).Rates;
            double course         = (double)GetPropValue((object)resutl, toCurrency.ToString());

            Cost    *= (course == 0 ? 1 : course);
            Currency = toCurrency;

            return(this);
        }
        // Method for getting the converted price and sending it to the product page (viewmodel)
        public ActionResult Index(ProductPage currentPage)
        {
            var currencyClient = new CurrencyClient();
            var convertedPrice = currencyClient.GetConvertedFromUsd(currentPage.ProductPrice);

            var viewModel = new ProductPageViewModel();

            viewModel.CurrentPage    = currentPage;
            viewModel.ConvertedPrice = convertedPrice.ToString("C3");

            return(View("~/Views/ProductPage/Index.cshtml", viewModel));
        }
Пример #6
0
        public async Task Execute(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            DateTime       dateTime;
            CurrencyClient currencyClient = new CurrencyClient();
            var            chatId         = message.Chat.Id;
            var            messageId      = message.MessageId;
            var            match          = new Regex(@"\d{2}.\d{2}.\d{4}").Matches(message.Text).FirstOrDefault();

            if (match != null && DateTime.TryParse(match.Value, out dateTime))
            {
                var xml        = currencyClient.GetXML(dateTime.Date.ToString());
                var valuteName = new Regex(@"\b[a-zA-Z]{3}\b").Matches(message.Text).FirstOrDefault();
                if (valuteName == null)
                {
                    valuteName = new Regex(@"\b[a-zA-Z]{1}\d{5}\b").Matches(message.Text).FirstOrDefault();
                    if (valuteName == null)
                    {
                        await _client.SendTextMessageAsync(chatId, "Can't parse valute name", replyToMessageId : messageId);

                        return;
                    }
                }
                currencyClient.ValCurs = currencyClient.ParseValute(xml);
                var rate = "";
                foreach (var item in currencyClient.ValCurs.Valutes)
                {
                    if (item.ID == valuteName.Value.ToUpper() || item.CharCode == valuteName.Value.ToUpper())
                    {
                        rate = item.Value.ToString();
                        break;
                    }
                }
                if (rate == "")
                {
                    await _client.SendTextMessageAsync(chatId, "Valute name or code isn't correct", replyToMessageId : messageId);
                }
                else
                {
                    await _client.SendTextMessageAsync(chatId, rate, replyToMessageId : messageId);
                }
            }
            else
            {
                await _client.SendTextMessageAsync(chatId, "Can't parse date", replyToMessageId : messageId);
            }
        }
Пример #7
0
        public void ParseValuteTest()
        {
            //Arrange
            CurrencyClient currencyClient      = new CurrencyClient();
            string         expectedName        = "Foreign Currency Market";
            string         expectedDate        = "31.03.2021";
            var            expectedValutesType = typeof(List <Valute>);
            //Act
            var result = currencyClient.ParseValute(currencyClient.GetXML("31.03.2021"));

            //Assert
            Assert.Equal(expectedDate, result.Date);
            Assert.Equal(expectedName, result.Name);
            Assert.IsType(expectedValutesType, result.Valutes);
        }
        public ActionResult Index()
        {
            //getting this select list value form Currency client class
            var fromCurrencyList = CurrencyClient.GetFromCurrencyListAsync().Result;

            ViewBag.FromCurrencies = new SelectList(fromCurrencyList, "CurrencyCode", "Name");



            var ToCurrencyList = CurrencyClient.GetToCurrencyListAsync().Result;

            ViewBag.ToCurrencies = new SelectList(ToCurrencyList, "CurrencyCode", "Name");

            return(View());
        }
        public ActionResult Index(string productId)
        {
            var cartCookie = this.Request.Cookies.Get("cart");

            if (cartCookie == null || string.IsNullOrWhiteSpace(cartCookie.Value))
            {
                var guid = Guid.NewGuid();
                cartCookie = new HttpCookie("cart", guid.ToString());
                Response.Cookies.Add(cartCookie);
            }

            var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>();
            var productPage       = contentRepository.Get <ProductPage>(new ContentReference(int.Parse(productId)));

            // Creates a new Entity for the cart
            var cartItem = new CartItemEntity();

            cartItem.ProductId    = int.Parse(productId);
            cartItem.ProductName  = productPage.Name;
            cartItem.ProductPrice = int.Parse(productPage.ProductPrice);
            cartItem.UserId       = cartCookie.Value;
            cartItem.Quantity     = 1;

            // Gets the converted price and adds it to the cart Entity
            var currencyClient = new CurrencyClient();
            var convertedPrice = currencyClient.GetConvertedFromUsd(productPage.ProductPrice);

            cartItem.ConvertedPrice = convertedPrice;

            var cartRepository = new CartRepository();

            cartRepository.Save(cartItem, true);

            // Adds the converted price to the viewmodel
            var viewModel = new ProductPageViewModel();

            viewModel.CurrentPage    = productPage;
            viewModel.ConvertedPrice = convertedPrice.ToString("C3");

            return(View("~/Views/ProductPage/Index.cshtml", viewModel));
        }
        public ActionResult Index(ConvertCurrencyViewModel cur)
        {
            if (ModelState.IsValid)
            {
                string fromcurrname = cur.fromCurrency.Name;
                string tocurrname   = cur.toCurrency.Name;

                //rate is taken by passing both dropdown currency code
                decimal rate = CurrencyClient.GetConversionRate("Currency/GetConversionRate?fromcurrname=" + fromcurrname + "&tocurrname=" + tocurrname).Result;
                ViewBag.result = cur.CurrencyToConvert * rate;
            }
            //getting this select list value form Currency client class
            var fromCurrencyList = CurrencyClient.GetFromCurrencyListAsync().Result;

            ViewBag.FromCurrencies = new SelectList(fromCurrencyList, "CurrencyCode", "Name");

            var ToCurrencyList = CurrencyClient.GetToCurrencyListAsync().Result;

            ViewBag.ToCurrencies = new SelectList(ToCurrencyList, "CurrencyCode", "Name");

            return(View());
        }
Пример #11
0
 public void OneTimeSetUp()
 {
     InitDokladApi();
     _client = DokladApi.CurrencyClient;
 }
Пример #12
0
 public CurrencyQuery(CurrencyClient currencyClient, RedisCommand redis)
 {
     _currencyClient = currencyClient;
     _redis          = redis;
 }