Esempio n. 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, "删除 失败");
        }
Esempio n. 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, "删除 失败");
        }
Esempio n. 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, "删除 失败");
        }
Esempio n. 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, "删除 失败");
        }
Esempio n. 5
0
        public async Task T_params_Add_Delete()
        {
            using (var client = new HttpClient())
            {
                //get app

                Uri uri     = new Uri(TestConfig.serviceUrl);
                var context = new DamServiceRef.Container(uri);

                context.Format.UseJson();

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


                var conParam1 = new ConstantParam()
                {
                    Id           = Guid.NewGuid(),
                    AppId        = appItem.Id,
                    ParamName    = "sc1",
                    ParamSymbol  = "sc1",
                    PrecisionNum = 2,
                    UnitSymbol   = "no",
                    Val          = 1,
                    Order        = 1,
                    Description  = "no description",
                };

                var mesParam1 = new MessureParam()
                {
                    Id           = Guid.NewGuid(),
                    AppId        = appItem.Id,
                    ParamName    = "sm1",
                    ParamSymbol  = "sm1",
                    PrecisionNum = 2,
                    UnitSymbol   = "no",
                    Order        = 1,
                    Description  = "no description",
                };


                var calParam1 = new CalculateParam()
                {
                    Id           = Guid.NewGuid(),
                    AppId        = appItem.Id,
                    ParamName    = "scal1",
                    ParamSymbol  = "scal1",
                    PrecisionNum = 2,
                    UnitSymbol   = "no",
                    Order        = 1,
                    Description  = "no description",
                };


                var formula = new Formula()
                {
                    Id                = Guid.NewGuid(),
                    ParamId           = calParam1.Id,
                    StartDate         = DateTimeOffset.MinValue,
                    EndDate           = DateTimeOffset.MaxValue,
                    CalculateOrder    = 1,
                    FormulaExpression = "sc1+sm1"
                };

                ParamsDTO dto = new ParamsDTO()
                {
                    Id = appItem.Id,
                };

                dto.AddedParams = new List <AppParam>()
                {
                    conParam1, mesParam1, calParam1
                };
                dto.AddedFormulae = new List <Formula>()
                {
                    formula
                };


                // New code:
                client.BaseAddress = new Uri(TestConfig.baseAddress);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.PostAsJsonAsync("api/ParamsDTOs", dto);

                Assert.IsTrue(response.IsSuccessStatusCode, " insert param fail");

                //delete all params

                dto = new ParamsDTO()
                {
                    Id = appItem.Id,
                };

                dto.DeletedParams = new List <AppParam>()
                {
                    conParam1, mesParam1, calParam1
                };
                dto.DeletedFormulae = new List <Formula>()
                {
                    formula
                };


                response = await client.PostAsJsonAsync("api/ParamsDTOs", dto);

                Assert.IsTrue(response.IsSuccessStatusCode, "delete formulae fail");

                //reload mesparam

                context.Detach(conParam1);
                context.Detach(mesParam1);
                context.Detach(calParam1);


                var cnt = context.AppParams.Where(s => s.Id == mesParam1.Id).Count();

                Assert.AreEqual(0, cnt, "delete test fail");
            }
        }
Esempio n. 6
0
        public async Task T_paramsUpdate()
        {
            using (var client = new HttpClient())
            {
                //get app

                Uri uri     = new Uri(TestConfig.serviceUrl);
                var context = new DamServiceRef.Container(uri);

                context.Format.UseJson();

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



                // New code:
                client.BaseAddress = new Uri(TestConfig.baseAddress);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));



                ParamsDTO dto = new ParamsDTO()
                {
                    Id = appItem.Id,
                };

                var conParam1 = appItem.AppParams.OfType <ConstantParam>().SingleOrDefault();
                var mesParam1 = appItem.AppParams.OfType <MessureParam>().SingleOrDefault();
                var calParam1 = appItem.AppParams.OfType <CalculateParam>().SingleOrDefault();


                conParam1.Order += 1;
                mesParam1.Order += 1;
                calParam1.Order += 1;


                dto.UpdatedParams = new List <AppParam>()
                {
                    conParam1, mesParam1, calParam1
                };

                HttpResponseMessage response = await client.PostAsJsonAsync("api/ParamsDTOs", dto);

                Assert.IsTrue(response.IsSuccessStatusCode, " update param fail");

                //all update success

                //test  acid

                mesParam1.ParamSymbol = "modify";


                response = await client.PostAsJsonAsync("api/ParamsDTOs", dto);

                context.Detach(mesParam1);


                Assert.IsFalse(response.IsSuccessStatusCode, "test formulae fail");

                //reload mesparam



                var itemInDb = context.AppParams.Where(s => s.Id == mesParam1.Id).SingleOrDefault();

                Assert.AreNotEqual(mesParam1.ParamSymbol, itemInDb.ParamSymbol, "acid test fail");
            }
        }