Exemple #1
0
        public void T_Remark()
        {
            Uri uri     = new Uri(TestConfig.serviceUrl);
            var context = new DamServiceRef.Container(uri);

            context.Format.UseJson();

            var itemList = context.Remarks.ToList();


            int cnt1 = context.Remarks.Count();

            var app = context.Apps.Take(1).SingleOrDefault();//top 1


            var newItem = new Remark();

            newItem.Id         = Guid.NewGuid();
            newItem.RemarkText = "测试";
            newItem.Date       = DateTime.Now;
            newItem.AppId      = app.Id;

            context.AddToRemarks(newItem);
            context.SaveChanges();

            int cnt2 = context.Remarks.Count();


            Assert.IsTrue(cnt1 + 1 == cnt2, "插入 失败");

            //在单独查询

            context.Detach(newItem);

            var itemInDb = context.Remarks.Where(s => s.Id == newItem.Id).SingleOrDefault();

            Assert.AreEqual(itemInDb.Id, newItem.Id, "插入失败");

            //更新

            itemInDb.RemarkText = newItem.RemarkText + "modify";

            context.UpdateObject(itemInDb);
            context.SaveChanges();

            context.Detach(itemInDb);

            var itemUpdated = context.Remarks.Where(s => s.Id == itemInDb.Id).SingleOrDefault();

            Assert.AreEqual(itemUpdated.RemarkText, itemInDb.RemarkText, "更新失败");

            //删除
            context.DeleteObject(itemUpdated);

            context.SaveChanges();
            int fCnt = context.Remarks.Count();

            Assert.IsTrue(cnt1 == fCnt, "删除 失败");
        }
Exemple #2
0
        public void T_projectPart()
        {
            Uri uri     = new Uri(TestConfig.serviceUrl);
            var context = new DamServiceRef.Container(uri);

            context.Format.UseJson();

            var itemList = context.ProjectParts.ToList();


            int cnt1 = context.ProjectParts.Count();

            var root = context.ProjectParts.Where(s => s.ParentPart == null).SingleOrDefault();


            var newItem = new ProjectPart();

            newItem.Id         = Guid.NewGuid();
            newItem.PartName   = "测试部位";
            newItem.ParentPart = root.Id;

            context.AddToProjectParts(newItem);
            context.SaveChanges();

            int cnt2 = context.ProjectParts.Count();


            Assert.IsTrue(cnt1 + 1 == cnt2, "插入 失败");

            //在单独查询

            context.Detach(newItem);

            var itemInDb = context.ProjectParts.Where(s => s.Id == newItem.Id).SingleOrDefault();

            Assert.AreEqual(itemInDb.Id, newItem.Id, "插入失败");

            //更新

            itemInDb.PartName = newItem.PartName + "modify";

            context.UpdateObject(itemInDb);
            context.SaveChanges();

            context.Detach(itemInDb);

            var itemUpdated = context.ProjectParts.Where(s => s.Id == itemInDb.Id).SingleOrDefault();

            Assert.AreEqual(itemUpdated.PartName, itemInDb.PartName, "更新失败");

            //删除
            context.DeleteObject(itemUpdated);

            context.SaveChanges();
            int fCnt = context.ProjectParts.Count();

            Assert.IsTrue(cnt1 == fCnt, "删除 失败");
        }
Exemple #3
0
        public void T_app()
        {
            Uri uri     = new Uri(TestConfig.serviceUrl);
            var context = new DamServiceRef.Container(uri);

            context.Format.UseJson();

            var itemList = context.Apps.ToList();


            int cnt1 = context.Apps.Count();

            var newItem = new App();

            newItem.Id            = Guid.NewGuid();
            newItem.AppName       = "新的仪器";
            newItem.CalculateName = "newCreatedApp";

            context.AddToApps(newItem);
            context.SaveChanges();

            int cnt2 = context.Apps.Count();


            Assert.IsTrue(cnt1 + 1 == cnt2, "插入 失败");

            //在单独查询

            context.Detach(newItem);

            var itemInDb = context.Apps.Where(s => s.Id == newItem.Id).SingleOrDefault();

            Assert.AreEqual(itemInDb.Id, newItem.Id, "插入失败");

            //更新

            itemInDb.AppName = newItem.AppName + "modify";

            context.UpdateObject(itemInDb);
            context.SaveChanges();

            context.Detach(itemInDb);

            var itemUpdated = context.Apps.Where(s => s.Id == itemInDb.Id).SingleOrDefault();

            Assert.AreEqual(itemUpdated.AppName, itemInDb.AppName, "更新失败");

            //删除
            context.DeleteObject(itemUpdated);

            context.SaveChanges();
            int fCnt = context.Apps.Count();

            Assert.IsTrue(cnt1 == fCnt, "删除 失败");
        }
Exemple #4
0
        public void T_type()
        {
            Uri uri     = new Uri(TestConfig.serviceUrl);
            var context = new DamServiceRef.Container(uri);

            context.Format.UseJson();

            var typeList = context.ApparatusTypes.ToList();


            int cnt1 = context.ApparatusTypes.Count();

            var newType = new ApparatusType()
            {
                Id = Guid.NewGuid(), TypeName = (new Random((int)DateTime.Now.Ticks)).Next().ToString()
            };

            context.AddToApparatusTypes(newType);
            context.SaveChanges();

            int cnt2 = context.ApparatusTypes.Count();

            int cnt3 = context.ApparatusTypes.Where(s => s.TypeName == "第一种类型").Count();

            Assert.IsTrue(cnt1 != cnt2, "插入 失败");

            //在单独查询

            context.Detach(newType);

            var type1 = context.ApparatusTypes.Where(s => s.Id == newType.Id).SingleOrDefault();

            Assert.AreEqual(type1.TypeName, newType.TypeName, "插入失败");

            //更新

            type1.TypeName = newType.TypeName + "modify";

            context.UpdateObject(type1);
            context.SaveChanges();

            var type2 = context.ApparatusTypes.Where(s => s.Id == newType.Id).SingleOrDefault();

            Assert.AreEqual(type2.TypeName, type1.TypeName, "更新失败");

            //删除
            context.DeleteObject(type2);

            context.SaveChanges();
            int fCnt = context.ApparatusTypes.Count();

            Assert.IsTrue(cnt1 == fCnt, "删除 失败");
        }
Exemple #5
0
        public void T_app_CheckExistData2()
        {
            Uri uri     = new Uri(TestConfig.serviceUrl);
            var context = new DamServiceRef.Container(uri);

            context.Format.UseJson();

            var app = context.Apps.Where(s => s.AppName == "第一支仪器").SingleOrDefault();


            context.LoadProperty <AppParam>(app, "AppParams", null);

            //添加测量参数

            DateTimeOffset date = DateTimeOffset.Now;

            List <MessureValue> list = new List <MessureValue>();

            foreach (var param in app.AppParams.OfType <MessureParam>())
            {
                var item = new MessureValue()
                {
                    Id      = Guid.NewGuid(),
                    Date    = date,
                    ParamId = param.Id,
                    Val     = 1
                };
                list.Add(item);
                context.AddToMessureValues(item);
            }


            context.SaveChanges();

            var result = context.CheckExistData(app.Id, date);

            Assert.AreEqual(true, result, "测试失败");

            foreach (var item in list)
            {
                context.DeleteObject(item);
            }



            context.SaveChanges();

            result = context.CheckExistData(app.Id, date);

            Assert.AreEqual(false, result, "测试失败");
        }