Пример #1
0
            public CaseModel Func_GetModel()
            {
                return(new CaseModel()
                {
                    NameSign = @"获取一个",
                    ExeEvent = () => {
                        TestModel[] array = GetRandomDatas();
                        iDAL.Delete(null);
                        iDAL.Insert((M[])array);

                        TestModel result_model = iDAL.GetModel(null, sorts);
                        if (!TestModelIsEqual(array[0], result_model))
                        {
                            Console.WriteLine("空条件错误");
                            return false;
                        }

                        TestModel[] answer_array = ConvertTool.ListConvertType <TestModel, TestModel>(array, model => {
                            return w_model(model) ? model : null;
                        }, null);

                        result_model = iDAL.GetModel(w_dal, sorts);
                        if (!TestModelIsEqual(answer_array[0], result_model))
                        {
                            Console.WriteLine("有条件错误");
                            return false;
                        }
                        return true;
                    },
                });
            }
Пример #2
0
            public CaseModel Func_Update()
            {
                TestModel[] array = GetRandomDatas();
                return(new CaseModel()
                {
                    NameSign = string.Format("更改 数据总数: {0}", array.Length),
                    ExeEvent = () => {
                        iDAL.Delete(null);
                        iDAL.Insert((M[])array);

                        double runtime = RunHelp.GetRunTime(() => {
                            iDAL.Update(update_content_dal, w_dal);
                        });
                        Console.WriteLine("Update run time: {0}", runtime);

                        TestModel[] answer_array = ConvertTool.ListConvertType <TestModel, TestModel>(array, model => {
                            if (w_model(model))
                            {
                                return update_content_model(model);
                            }
                            return model;
                        }, null);

                        TestModel[] query_result = iDAL.Select(0, null, sorts);
                        return new VerifyIList <TestModel, TestModel>(CalcWayEnum.Random)
                        {
                            Answer = answer_array,
                            Source = query_result,
                            Func_isEquals = TestModelIsEqual,
                        }.Calc();
                    },
                });
            }
Пример #3
0
            public CaseModel Func_Select_Pagination()
            {
                int sum = RandomData.GetInt(300, 8001);

                sum = RandomData.GetInt(116, 265); // 循环遍历内容太多次,百位是极限了
                TestModel[] array = GetRandomDatas(sum);
                return(new CaseModel()
                {
                    NameSign = string.Format("分页查询 数据总数: {0}", sum),
                    ExeEvent = () => {
                        iDAL.Delete(null);
                        iDAL.Insert((M[])array);

                        Func <int, bool> method = (page_size) => {
                            TestModel[] answer_list = ConvertTool.ListConvertType(array, model => {
                                return w_model(model) ? model : null;
                            }, null);

                            for (int page_index = -2; page_index <= answer_list.Length / page_size + 3; page_index++)
                            {
                                int record_count = 0;
                                TestModel[] result = iDAL.Select(page_size, page_index, out record_count, w_dal, sorts);
                                TestModel[] answer_array = ConvertTool.ToRangePage(answer_list, page_index, page_size);

                                bool isby = new VerifyIList <TestModel, TestModel>(CalcWayEnum.Random)
                                {
                                    Answer = answer_array,
                                    Source = result,
                                    Func_isEquals = TestModelIsEqual,
                                    Func_lengthNotEquals = (al, sl) => {
                                        Console.WriteLine("page_size: {0}, page_index: {1}  列表长度不一样:  answer.Length: {2}, source.Length: {3}", page_size, page_index, al, sl);
                                    },
                                    Func_notFind = am => {
                                        Console.WriteLine("page_size: {0}, page_index: {1} answer model: {2}", page_size, page_index, JSON.Serializer(am));
                                    },
                                }.Calc();
                                if (!isby)
                                {
                                    throw new Exception("错误");
                                }
                            }

                            return true;
                        };

                        for (int i = 10; i <= 11; i++)
                        {
                            if (!method(i))
                            {
                                return false;
                            }
                        }

                        return true;
                    },
                });
            }
Пример #4
0
 /// <summary>
 /// 获得列信息 可写
 /// </summary>
 public ColumnInfo[] GetListCanWrite()
 {
     ColumnInfo[] arr = GetList();
     return(ConvertTool.ListConvertType(arr, info => {
         if (info.Attribute.IsAutoGenerated)
         {
             return null;
         }
         return info;
     }, null));
 }
Пример #5
0
            public CaseModel Func_Select()
            {
                TestModel[] array = GetRandomDatas(RandomData.GetInt(30, 81));
                return(new CaseModel()
                {
                    NameSign = string.Format("查询 数据总数: {0}", array.Length),
                    ExeEvent = () => {
                        iDAL.Delete(null);
                        iDAL.Insert((M[])array);

                        VerifyIList <TestModel, TestModel> verify = new VerifyIList <TestModel, TestModel>(CalcWayEnum.DoubleCycle);
                        verify.Func_isEquals = TestModelIsEqual;

                        verify.Answer = array;
                        verify.Source = iDAL.Select(0, null, sorts);
                        if (!verify.Calc())
                        {
                            Console.WriteLine("0条, 空条件 : 错误");
                            throw new Exception("错误");
                        }

                        TestModel[] answer_array = ConvertTool.ListConvertType <TestModel, TestModel>(array, model => {
                            return w_model(model) ? model : null;
                        }, null);
                        verify.Answer = answer_array;
                        verify.Source = iDAL.Select(0, w_dal, sorts);
                        if (!verify.Calc())
                        {
                            Console.WriteLine("0条, 有条件 : 错误");
                            throw new Exception("错误");
                        }

                        TestModel[] top_answer_array = new TestModel[8];
                        for (int i = 0; i < top_answer_array.Length; i++)
                        {
                            top_answer_array[i] = answer_array[i];
                        }
                        verify.Answer = top_answer_array;
                        verify.Source = iDAL.Select(top_answer_array.Length, w_dal, sorts);
                        if (!verify.Calc())
                        {
                            Console.WriteLine("{0}条, 有条件 : 错误", top_answer_array.Length);
                            throw new Exception("错误");
                        }
                        return true;
                    },
                });
            }
Пример #6
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="kos">需要更新的键值</param>
        /// <param name="where">查询条件</param>
        /// <returns>是否成功 是:True 否:False</returns>
        public override bool Update(KeyObject[] kos, string where)
        {
            if (CheckData.IsSizeEmpty(kos) || CheckData.IsStringNull(where))
            {
                return(false);
            }
            string[] expressions = ConvertTool.ListConvertType(kos, item => {
                if (CheckData.IsStringNull(item.Key))
                {
                    return(null);
                }
                string str_value = ConvertTool.ToString(item.Value);
                return(string.Format("{0} = '{1}'", item.Key, item.Value));
            }, null);
            string set_str    = ConvertTool.ToString(expressions, ',');
            string sql_update = CreateSQL.Update(this.GetTableName(), set_str, where);

            return(CheckData.IsStringNull(sql_update) ? false : DbHelperSQL.ExecuteSql(sql_update) > 0);
        }
Пример #7
0
            public CaseModel Func_GetRecordCount()
            {
                return(new CaseModel()
                {
                    NameSign = @"记录总数",
                    ExeEvent = () => {
                        TestModel[] array = GetRandomDatas();
                        iDAL.Delete(null);
                        iDAL.Insert((M[])array);

                        if (array.Length != iDAL.GetRecordCount(null))
                        {
                            return false;
                        }
                        TestModel[] answer_array = ConvertTool.ListConvertType <TestModel, TestModel>(array, model => {
                            return w_model(model) ? null : model;
                        }, null);

                        return answer_array.Length != iDAL.GetRecordCount(w_dal);
                    },
                });
            }
 /// <summary>
 /// 输出HTML代码: 给内容套上区域模块
 /// </summary>
 /// <param name="list"></param>
 /// <returns></returns>
 protected string PageFormat_Region(string[] list)
 {
     string[] formatlist = ConvertTool.ListConvertType(list, str => string.Format("<span>{0}</span>", str));
     return(string.Format("<div class=\"l-btns\">{0}</div>", ConvertTool.ToString(formatlist, PAGE_OUTPUT_LINE_BREAK)));
 }
Пример #9
0
        public CaseModel Error_DateTimeType()
        {
            return(new CaseModel()
            {
                NameSign = @"时间类型",
                ExeEvent = () => {
                    DAL_MSSQLServer <TestModel> dal = new DAL_MSSQLServer <TestModel>();
                    TestModel[] array = new TestModel[999];
                    for (int i = 0; i < array.Length; i++)
                    {
                        string name = string.Format("第{0}条 - ", i);
                        array[i] = new TestModel()
                        {
                            RecordIndex = i,
                            Age = RandomData.GetInt(7828, 546822),
                            DateOfBirth = new DateTime(2018, 10, 30, 14, 42, 33, i),
                            Name = name + RandomData.GetChineseString(RandomData.GetInt(3, 5)),
                            Sex = RandomData.Item(EnumInfo.GetALLItem <TestModel.SexEnum>()),
                        };
                    }

                    Console.WriteLine("dal.Delete(null): {0}s", RunHelp.GetRunTime(() => {
                        dal.Delete(null);
                    }));

                    string[] sqls = null;

                    Console.WriteLine("sqls create: {0}s", RunHelp.GetRunTime(() => {
                        sqls = ConvertTool.ListConvertType(array, (model) => dal.SQLInsert(model, false));
                    }));

                    Console.WriteLine("dal.Transaction(sqls): {0}s", RunHelp.GetRunTime(() => {
                        dal.Transaction(sqls);
                    }));

                    //dal.Insert(array);

                    DataTable dt = dal.QueryRecords(0, null, "RecordIndex asc").Tables[0];

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TestModel a = array[i];
                        DataRow dr = dt.Rows[i];
                        TestModel s = dal.DataRowToModel(dr);

                        if (a.DateOfBirth != s.DateOfBirth)
                        {
                            throw new Exception("错误");
                        }
                    }



                    /*
                     * TestModel[] result = dal.Select(0, null, new KeyBoolean[] {
                     *  new KeyBoolean("RecordIndex", true),
                     * });
                     * VerifyIList<TestModel, TestModel> verify = new VerifyIList<TestModel, TestModel>(CalcWayEnum.SingleCycle) {
                     *  Answer = array,
                     *  Source = result,
                     *  Func_isEquals = (a, s) => {
                     *      if (a.RecordIndex != s.RecordIndex) {
                     *          return false;
                     *      }
                     *      if (a.Age != s.Age) {
                     *          return false;
                     *      }
                     *      if (a.Name != s.Name) {
                     *          return false;
                     *      }
                     *      if (a.Sex != s.Sex) {
                     *          return false;
                     *      }
                     *
                     *      if (a.DateOfBirth != s.DateOfBirth) {
                     *          string a_dt = a.DateOfBirth.ToString(Format.DATETIME_SECOND);
                     *          string s_dt = s.DateOfBirth.ToString(Format.DATETIME_SECOND);
                     *          Console.WriteLine("时间不一致!  a:{0}  s:{1}", a, s);
                     *          throw new Exception("错误");
                     *          return false;
                     *      }
                     *      return true;
                     *  },
                     * };
                     *
                     * bool isby = verify.Calc();
                     * if (!isby) {
                     *  return false;
                     * }
                     */
                    return true;
                },
            });
        }
Пример #10
0
 /// <summary>
 /// 插入
 /// </summary>
 /// <param name="models">数据映射模型多条记录</param>
 /// <returns>是否成功 是:True 否:False</returns>
 public override bool Insert(M[] models)
 {
     string[] sql_inserts = ConvertTool.ListConvertType(models, (model) => SQLInsert(model, false));
     return(Transaction(sql_inserts));
 }