Esempio n. 1
0
        public bool Exists(ISecurity security)
        {
            SecurityRepository repository = new SecurityRepository(DataFiles.GetSecuritiesFile());
            return repository.Exists(security);

            //// 设置查询条件
            //var spec = Specification<Security>.Eval(p => p.Code.Equals(security.Code));

            //using (var context = GetContext())
            //{
            //    var repository = new Repository<Security>(context);
            //    return repository.Exists(spec);
            //}
        }
Esempio n. 2
0
        public void TestMethod_Security()
        {
            string filePath = Path.Combine(Environment.CurrentDirectory, "TestSecurity.sdf");
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            List<ISecurity> securities = ExampleSecurities();
            System.Diagnostics.Debug.Print(string.Format("Security data count is {0}", securities.Count));

            SecurityRepository repository = new SecurityRepository(filePath);
            repository.AddRange(securities);

            ISecurity get = repository.Get(securities[0].Code);

            Assert.IsTrue(repository.Exists(securities[0]));
            Assert.IsFalse(repository.Exists(ExampleSecurity()));

            var updateData = new Security { Code = "600518", Market = Market.XSHG, ShortName = "康*美*药*业", Type = SecurityType.Unknown };

            repository.UpdateRange(new ISecurity[] { updateData });
            IList<ISecurity> result0 = repository.GetAll().ToList();

            Assert.IsTrue(repository.Exists(updateData));

            List<ISecurity> updateSecurities = GetUpdateSecurityDatas(securities).ToList();
            repository.UpdateRange(updateSecurities);

            IList<ISecurity> result = repository.GetAll().ToList();

            if (result != null && result.Count > 0)
            {
                System.Diagnostics.Debug.Print(string.Format("Security Data count is {0}", result.Count));
            }
            Assert.AreEqual(securities.Count, result.Count);
        }