public ActionResult Data(string stock,int? total,string date) { stock = string.IsNullOrEmpty(stock) ? null : stock; total = total ?? 60; date = date?? DateTime.Now.AddDays(-1).ToShortDateString(); string s = null; var cache = MemoryCache.Default; var key = "SData" + (total == null ? "" : "_" + total.ToString()) + (date == null ? "" : "_" + date) + (stock == null ? "" : "_" + stock.ToString()); var cacheObj = cache[key]; if (cacheObj != null) { s = (string)cacheObj; return this.Content(s, "text/xml"); } else { var data = new DBStockQuoteData().GetStockPrice(stock, total.Value, DateTime.ParseExact(date,"yyyyMMdd",null)); XmlSerializer serializer = new XmlSerializer(typeof(StockPrice[])); StringWriter writer = new StringWriter(); serializer.Serialize(writer, data); s = writer.ToString(); cache.Set(key, s, DateTimeOffset.UtcNow.AddHours(23)); return this.Content(s, "text/xml"); } }
public void GetStockPriceTest() { DBStockQuoteData target = new DBStockQuoteData(); // TODO: Initialize to an appropriate value string secuCode = string.Empty; // TODO: Initialize to an appropriate value int numRecord = 0; // TODO: Initialize to an appropriate value DateTime endDate = new DateTime(2011,01,20); // TODO: Initialize to an appropriate value StockPrice[] expected = null; // TODO: Initialize to an appropriate value StockPrice[] actual; actual = target.GetStockPrice("000001", 1, endDate); Assert.IsNotNull(actual); }
public void CalcReturnTest() { DBStockQuoteData target = new DBStockQuoteData(); // TODO: Initialize to an appropriate value List<string> secuCode = new List<string>{"000001"}; // TODO: Initialize to an appropriate value DateTime startTime = new DateTime(2011,1,3); // TODO: Initialize to an appropriate value DateTime endTime = new DateTime(2011,1,5); // TODO: Initialize to an appropriate value // var actual = target.CalcReturn(secuCode, startTime, endTime); // Assert.AreNotEqual(null, actual); // Assert.IsTrue(actual.Exists(s=>s.SecuCode == "000001")); // Assert.IsTrue(actual.Where(s=>s.SecuCode == "000001").First().Value != default(double)); }