Exemple #1
0
        public CaseModel Func_GetValue_SetValue()
        {
            return(new CaseModel()
            {
                NameSign = @"获取/设置值",
                ExeEvent = () => {
                    GS answer = new GS()
                    {
                        Age = RandomData.GetInt(),
                        DateOfBirth = RandomData.GetDateTime(),
                        Name = RandomData.GetChineseString(),
                        Price = RandomData.GetDouble(),
                        Sex = RandomData.Item(EnumInfo.GetALLItem <GS.SexEnum>()),
                    };

                    GS result = new GS();

                    ShineUponParser parser = new ShineUponParser(typeof(GS));
                    foreach (ShineUponInfo info in parser.GetDictionary().Values)
                    {
                        KeyString ks = parser.GetValue_KeyString(info, answer);
                        parser.SetValue_Object(info, result, ks.Value);
                    }

                    return true;
                },
            });
        }
 public CaseModel Func_GetALLItem()
 {
     return(new CaseModel()
     {
         NameSign = @"所有选项",
         ExeEvent = () => {
             TestEnum[] answer = new TestEnum[] {
                 TestEnum.Secrecy,
                 TestEnum.Male,
                 TestEnum.Female,
                 TestEnum.Test,
             };
             TestEnum[] source = EnumInfo.GetALLItem <TestEnum>();
             return new VerifyIList <TestEnum, TestEnum>(CalcWayEnum.DoubleCycle)
             {
                 Answer = answer,
                 Source = source,
                 Func_isEquals = (a_item, s_item) => {
                     return a_item.ToString() == s_item.ToString();
                 },
                 Func_notFind = (a_item) => {
                     Console.WriteLine("answer item enum name: {0}", a_item.ToString());
                 },
             }.Calc();
         },
     });
 }
 public TestModel[] GetRandomDatas(int rewrite_sum = 0)
 {
     if (rewrite_sum <= 0)
     {
         rewrite_sum = RandomData.GetInt(30, 81);
     }
     TestModel[] array = new TestModel[rewrite_sum];
     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 = RandomData.GetDateTime(SqlDateTime.MinValue.Value, SqlDateTime.MaxValue.Value),
             Name        = name + RandomData.GetChineseString(RandomData.GetInt(3, 5)),
             Sex         = RandomData.Item(EnumInfo.GetALLItem <TestModel.SexEnum>()),
         };
     }
     return(array);
 }
        public CaseModel Func_Insert()
        {
            return(new CaseModel()
            {
                NameSign = @"插入数据",
                ExeEvent = () => {
                    List <TestModel> model_list = new List <TestModel>();
                    int record_count = RandomData.GetInt(10, 51);
                    record_count = 15;
                    for (int i = 0; i < record_count; i++)
                    {
                        model_list.Add(new TestModel()
                        {
                            IID = i,
                            Name = RandomData.GetChineseString(RandomData.GetInt(3, 5)),
                            Sex = RandomData.Item(EnumInfo.GetALLItem <TestModel.SexEnum>()),
                            TimeRelease = RandomData.GetDateTime(SqlDateTime.MinValue.Value, SqlDateTime.MaxValue.Value),
                        });
                    }

                    Func <TestModel, string> get_formatprint = (model) => {
                        return JSON.Serializer(model);
                    };

                    List <string> lines = new List <string>();
                    foreach (TestModel model in model_list)
                    {
                        string text = get_formatprint(model);
                        lines.Add(text);
                    }
                    string abs_file_path = Get_AbsFilePath();
                    File.Delete(abs_file_path);
                    File.Create(abs_file_path).Close();
                    WriterLine(abs_file_path, lines.ToArray());

                    Func_Select().ExeEvent();
                    return true;
                },
            });
        }
        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;
                },
            });
        }