Example #1
0
        public async Task Update_SetField_NotAllowedNull_ST()
        {
            xx = string.Empty;

            var agent = await MyDAL_TestDB.SelectOneAsync <Agent>(it => it.Id == Guid.Parse("040afaad-ae07-42fc-9dd0-0165443c847d"));

            try
            {
                var res1 = await MyDAL_TestDB
                           .Updater <Agent>()
                           .Set(it => it.PathId, null)
                           .Where(it => it.Id == agent.Id)
                           .UpdateAsync();
            }
            catch (Exception ex)
            {
                var errStr = "【ERR-054】 -- [[NotAllowedNull -- 字段:[[PathId]]的值不能设为 Null !!!]] ,请 EMail: --> [email protected] <--";
                Assert.Equal(errStr, ex.Message, true);
            }



            /*****************************************************************************************************************************************************************/

            xx = string.Empty;
        }
Example #2
0
        public async Task Update_SetObject_ST_02()
        {
            xx = string.Empty;

            // 要更新的 model 字段 赋值
            var model = new AgentInventoryRecord();

            model.TotalSaleCount = 1000;

            //
            var res1 = await MyDAL_TestDB
                       .Updater <AgentInventoryRecord>() //更新表 AgentInventoryRecord
                       .Set(new
            {
                model.TotalSaleCount, //  更新 字段 TotalSaleCount
                xxx = 2000            //  字段 xxx 在表中无对应 ,自动忽略
            })
                       .Where(it => it.Id == Guid.Parse("032ce51f-1034-4fb2-9741-01655202ecbc"))
                       .UpdateAsync();

            Assert.True(res1 == 1);



            /***************************************************************************************************************************/

            xx = string.Empty;
        }
Example #3
0
        public async Task History_04()
        {
            xx = string.Empty;

            var agent = await MyDAL_TestDB.SelectOneAsync <Agent>(it => it.Id == Guid.Parse("040afaad-ae07-42fc-9dd0-0165443c847d"));

            agent.PathId        = "xxxxxxx";
            agent.ActiveOrderId = null;

            var res1 = await MyDAL_TestDB
                       .Updater <Agent>()
                       .Set(new
            {
                agent.PathId,
                agent.ActiveOrderId
            })
                       .Where(it => it.Id == agent.Id)
                       .UpdateAsync();



            var res11 = await MyDAL_TestDB.SelectOneAsync <Agent>(it => it.Id == agent.Id);

            Assert.Equal("xxxxxxx", res11.PathId, true);
            Assert.Null(res11.ActiveOrderId);

            /*****************************************************************************************************************************************************************/

            xx = string.Empty;
        }
Example #4
0
 private async Task PreRTrim()
 {
     var res1 = await MyDAL_TestDB
                .Updater <Product>()
                .Set(it => it.Title, "演示商品01  ")
                .Where(it => it.Id == Guid.Parse("b3866d7c-2b51-46ae-85cb-0165c9121e8f"))
                .UpdateAsync();
 }
Example #5
0
 private async Task ClearData3(Agent m)
 {
     await MyDAL_TestDB
     .Updater <Agent>()
     .Set(it => it.AgentLevel, m.AgentLevel)
     .Where(it => it.Id == m.Id)
     .UpdateAsync();
 }
Example #6
0
        public async Task <Agent> PreData3()
        {
            var m = await MyDAL_TestDB
                    .Selecter <Agent>()
                    .Where(it => it.Id == Guid.Parse("0001c614-dbef-4335-94b4-01654433a215"))
                    .SelectOneAsync();

            await MyDAL_TestDB
            .Updater <Agent>()
            .Set(it => it.AgentLevel, WhereTest.AgentLevelNull)
            .Where(it => it.Id == m.Id)
            .UpdateAsync();

            return(m);
        }
Example #7
0
        public async Task Mock_UpdateAll_SetField_ST()
        {
            xx = string.Empty;

            var res1 = await MyDAL_TestDB
                       .Updater <AgentInventoryRecord>()
                       .Set(it => it.LockedCount, 0)
                       .UpdateAsync();

            Assert.True(res1 == 574);



            var res11 = await MyDAL_TestDB.SelectListAsync <AgentInventoryRecord>(it => it.LockedCount != 0);

            Assert.True(res11.Count == 0);

            xx = string.Empty;
        }
Example #8
0
        public async Task Update_SetField_ChangeMinus_ST()
        {
            xx = string.Empty;

            //
            var res5 = await MyDAL_TestDB
                       .Updater <AgentInventoryRecord>()
                       .Change(it => it.LockedCount, 10, ChangeEnum.Minus)
                       .Where(it => it.AgentId == Guid.Parse("0ce552c0-2f5e-4c22-b26d-01654443b30e"))
                       .And(it => it.ProductId == Guid.Parse("85ce17c1-10d9-4784-b054-016551e5e109"))
                       .UpdateAsync();

            Assert.True(res5 == 1);



            /***************************************************************************************************************************/

            xx = string.Empty;
        }
Example #9
0
        public async Task Update_SetField_AllowedNull_ST()
        {
            xx = string.Empty;

            var agent = await MyDAL_TestDB.SelectOneAsync <Agent>(it => it.Id == Guid.Parse("040afaad-ae07-42fc-9dd0-0165443c847d"));

            var res1 = await MyDAL_TestDB
                       .Updater <Agent>()
                       .Set(it => it.PathId, null)
                       .Where(it => it.Id == agent.Id)
                       .UpdateAsync();

            var res11 = await MyDAL_TestDB.SelectOneAsync <Agent>(it => it.Id == agent.Id);

            Assert.Null(res11.PathId);



            /*****************************************************************************************************************************************************************/

            xx = string.Empty;
        }
Example #10
0
        public async Task Update_SetField_Segment_ST()
        {
            xx = string.Empty;

            var m = await CreateDbData();

            // update 要赋值的变量
            var time        = DateTime.Now.ToString();
            var propertyVal = "{xxx:yyy,mmm:nnn,zzz:aaa}";

            // 使用 SetSegment 动态 拼接 set field 起点
            var set = MyDAL_TestDB.Updater <BodyFitRecord>().SetSegment;

            // 根据 条件 判断 是否要对字段 CreatedOn 进行 update
            if (time.IsNotBlank())
            {
                set = set.Set(it => it.CreatedOn, DateTime.Parse(time));
            }

            // 根据 条件 判断 是否要对字段 BodyMeasureProperty 进行 update
            if (propertyVal.IsNotBlank())
            {
                set = set.Set(it => it.BodyMeasureProperty, propertyVal);
            }

            // 对 SetSegment 设定的字段 进行 update 动作
            var res1 = await set
                       .Where(it => it.Id == m.Id)
                       .UpdateAsync();

            Assert.True(res1 == 1);



            /***************************************************************************************************************************/

            xx = string.Empty;
        }
Example #11
0
        public async Task Update_SetDynamic_ST()
        {
            xx = string.Empty;

            dynamic obj = new ExpandoObject();

            obj.TotalSaleCount = 2000;
            obj.xxx            = 3000;

            //
            var res1 = await MyDAL_TestDB
                       .Updater <AgentInventoryRecord>()
                       .Set(obj as object)
                       .Where(it => it.Id == Guid.Parse("032ce51f-1034-4fb2-9741-01655202ecbc"))
                       .UpdateAsync();

            Assert.True(res1 == 1);



            /***************************************************************************************************************************/

            xx = string.Empty;
        }
Example #12
0
        private async Task PereValue()
        {
            var res1 = await MyDAL_TestDB
                       .Selecter <Agent>()
                       .Where(it => it.Id == Guid.Parse("03f0a7b4-acd3-4003-b686-01654436e906"))
                       .SelectOneAsync();

            var res2 = await MyDAL_TestDB
                       .Updater <Agent>()
                       .Set(it => it.DirectorStarCount, 10)
                       .Where(it => it.Id == res1.Id)
                       .UpdateAsync();

            var res3 = await MyDAL_TestDB
                       .Selecter <Agent>()
                       .Where(it => it.Id == Guid.Parse("03fc18e2-4b1e-4aa2-832b-0165443388bd"))
                       .SelectOneAsync();

            var res4 = await MyDAL_TestDB
                       .Updater <Agent>()
                       .Set(it => it.DirectorStarCount, 5)
                       .Where(it => it.Id == res3.Id)
                       .UpdateAsync();
        }
Example #13
0
        public async Task History_02()
        {
            xx = string.Empty;

            // set field 2
            var res2 = await MyDAL_TestDB
                       .Updater <AgentInventoryRecord>()
                       .Set(it => it.LockedCount, 100)
                       .Where(it => it.AgentId == Guid.Parse("0ce552c0-2f5e-4c22-b26d-01654443b30e"))
                       .Or(it => it.CreatedOn == Convert.ToDateTime("2018-08-19 11:34:42.577074"))
                       .UpdateAsync();

            Assert.True(res2 == 2);



            /***************************************************************************************************************************/

            xx = string.Empty;

            var resx6 = await MyDAL_TestDB
                        .Selecter <Agent>()
                        .Where(it => it.Id == Guid.Parse("000c1569-a6f7-4140-89a7-0165443b5a4b"))
                        .SelectOneAsync();

            resx6.ActivedOn = null;

            // update set null
            var res6 = await MyDAL_TestDB
                       .Updater <Agent>()
                       .Set(it => it.ActivedOn, resx6.ActivedOn)
                       .Where(it => it.Id == resx6.Id)
                       .UpdateAsync();

            Assert.True(res6 == 1);



            /***************************************************************************************************************************/

            xx = string.Empty;

            var guid7 = Guid.Parse("b3866d7c-2b51-46ae-85cb-0165c9121e8f");

            var resxxx7 = await MyDAL_TestDB
                          .Updater <Product>()
                          .Set(it => it.VipProduct, false)
                          .Where(it => it.Id == guid7)
                          .UpdateAsync();

            var resx7 = await MyDAL_TestDB
                        .Selecter <Product>()
                        .Where(it => it.Id == guid7)
                        .SelectOneAsync();

            Assert.NotNull(resx7);
            Assert.False(resx7.VipProduct);

            resx7.VipProduct = true;

            // update set bool bit
            var res7 = await MyDAL_TestDB
                       .Updater <Product>()
                       .Set(it => it.VipProduct, resx7.VipProduct)
                       .Where(it => it.Id == resx7.Id)
                       .UpdateAsync();

            Assert.True(res7 == 1);



            var resxx7 = await MyDAL_TestDB
                         .Selecter <Product>()
                         .Where(it => it.Id == guid7)
                         .SelectOneAsync();

            Assert.True(resxx7.VipProduct);

            /***************************************************************************************************************************/

            xx = string.Empty;

            var res8 = await MyDAL_TestDB
                       .Updater <Agent>()
                       .Set(it => it.AgentLevel, AgentLevel.NewCustomer)
                       .Where(it => it.Id == Guid.Parse("0014f62d-2a96-4b5b-b4bd-01654438e3d4"))
                       .UpdateAsync();

            var res81 = await MyDAL_TestDB
                        .Selecter <Agent>()
                        .Where(it => it.Id == Guid.Parse("0014f62d-2a96-4b5b-b4bd-01654438e3d4"))
                        .SelectOneAsync();

            Assert.True(res81.AgentLevel == AgentLevel.NewCustomer);



            /***************************************************************************************************************************/

            xx = string.Empty;
        }