Ejemplo n.º 1
0
        public Current_Price GetPriceData(int productId)
        {
            var currentPrice = new Current_Price
            {
                currency_code = "USD",
                value         = 14.92
            };

            return(currentPrice);
        }
Ejemplo n.º 2
0
 public void UpdatePriceData(int id, Current_Price currentPrice)
 {
     try {
         var serializedDataToWrite = JsonConvert.SerializeObject(currentPrice);
         var manager = new RedisManagerPool(Environment.GetEnvironmentVariable("redis_ip") + ":" + Environment.GetEnvironmentVariable("redis_port"));
         using (var client = manager.GetClient())
         {
             client.Set(id.ToString(), serializedDataToWrite);
         }
     }catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 3
0
        public Product GetProductById(int productId)
        {
            var product2Return = new Product
            {
                name = "TestProd",
                id   = productId
            };
            var current_Price = new Current_Price
            {
                value         = 7,
                currency_code = "USD"
            };

            return(product2Return);
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            // this code should be taken out for production
            // but since this is a coding challenge, this seemed
            // to be the easiest way to get the data in the DB
            var dataForDB = new Current_Price
            {
                currency_code = "USD",
                value         = 18.12
            };
            var writeThis = JsonConvert.SerializeObject(dataForDB);
            var manager   = new RedisManagerPool(Environment.GetEnvironmentVariable("redis_ip") + ":" + Environment.GetEnvironmentVariable("redis_port"));

            using (var client = manager.GetClient())
            {
                client.Set("13860428", writeThis);
            }
            BuildWebHost(args).Run();
        }
Ejemplo n.º 5
0
        public void testGetProductRedisDB()
        {
            var testProductId = 13860428;
            var dataForDB     = new Current_Price();

            dataForDB.currency_code = "USD";
            dataForDB.value         = 18.12;
            var writeThis = JsonConvert.SerializeObject(dataForDB);
            var manager   = new RedisManagerPool("localhost:6379");

            using (var client = manager.GetClient())
            {
                client.Set(testProductId.ToString(), writeThis);
            }

            var redisRepo     = new RedisDB();
            var actualResults = redisRepo.GetPriceData(testProductId);

            Assert.AreEqual(actualResults, dataForDB);
        }
Ejemplo n.º 6
0
        public Current_Price GetPriceData(int productId)
        {
            var currentPrice = new Current_Price();

            try
            {
                var manager = new RedisManagerPool(Environment.GetEnvironmentVariable("redis_ip") + ":" + Environment.GetEnvironmentVariable("redis_port"));
                using (var client = manager.GetClient())
                {
                    var returnedData = client.Get <string>(productId.ToString());
                    currentPrice = JsonConvert.DeserializeObject <Current_Price>(returnedData);
                }
            }
            catch
            {
                currentPrice = new Current_Price
                {
                    value = -1
                };
            }

            return(currentPrice);
        }
Ejemplo n.º 7
0
 public void UpdatePriceData(int id, Current_Price current_price)
 {
     return;
 }
Ejemplo n.º 8
0
 public void UpdatePriceData(int id, Current_Price current_price)
 {
     throw new NotImplementedException();
 }