public IEnumerable<SecurityDto> Get()
 {
     #if DEBUG
     /*test code for communication * ************************************/
     var dto = new SecurityDto()
     {
         Code = "600036",
         Market = Ore.Infrastructure.MarketData.Market.XSHG,
         ShortName = "招商银行",
         Type = Ore.Infrastructure.MarketData.SecurityType.Sotck
     };
     var result = new List<SecurityDto>();
     result.Add(dto);
     return result;
     /*test code for communication************************************/
     #else
     var appService = new SecurityAppService();
     return appService.GetAll().ToDto();
     #endif
 }
Beispiel #2
0
        public void TestSecurity()
        {
            string dataFile = DataFiles.GetSecuritiesFile();
            if(File.Exists(dataFile))
            {
                File.Delete(dataFile);
            }

            SecurityDto insertData = new SecurityDto()
            {
                Code = "600036",
                ShortName = "招商银行招商银行招商银行",
                Market = Market.XSHG,
                Type = SecurityType.Sotck
            };

            var appService = new SecurityAppService();

            // 测试插入数据
            appService.Add(insertData);
            Assert.IsTrue(appService.Exists(insertData));

            // 测试更新数据
            insertData.ShortName = "招商银行";
            appService.Update(insertData);

            insertData.ShortName = "测试测试";
            appService.Update(insertData);

            Assert.IsTrue(appService.Exists(insertData));

            // 测试读取数据
            var securities = appService.GetAll().ToList();
            Assert.IsNotNull(securities);
            Assert.IsTrue(securities.Count == 1);
            Assert.AreEqual(insertData.ShortName, securities[0].ShortName);
        }
        /// <summary>
        /// 尝试从数据库或者Api获取所有Security
        /// </summary>
        /// <returns></returns>
        protected IEnumerable<ISecurity> GetAllSecurity()
        {
            IEnumerable<ISecurity> result = null;
            try
            {
                SecurityAppService appService = new SecurityAppService();
                result = appService.GetAll();
            }
            catch (Exception ex)
            {
                LogHelper.Logger.WriteLine(ex.ToString(), this.ServiceName);
            }

            // 如果从数据库获取数据不成功,从网页进行数据获取
            if( result == null || result.Count() <= 0)
            {
                result = GetSecurityFromApi();
            }

            return result == null ? new List<ISecurity>() : result;
        }