Exemple #1
0
        public CaseModel Func_DeleteKey()
        {
            return(new CaseModel()
            {
                NameSign = @"删除键",
                ExeEvent = () => {
                    string section = RandomData.Item(new List <string>(this.dic.Keys));
                    VerifyIList <KeyString, KeyString> verify = new VerifyIList <KeyString, KeyString>(CalcWayEnum.DoubleCycle)
                    {
                        Func_isEquals = (a, s) => a.Key == s.Key && a.Value == s.Value,
                    };
                    verify.Answer = this.dic[section];
                    verify.Source = this.ini.GetKeyValues(section);
                    if (!verify.Calc())
                    {
                        return false;
                    }

                    KeyString ks = RandomData.Item(this.dic[section]);
                    List <KeyString> kss = new List <KeyString>(this.dic[section]);
                    kss.Remove(ks);
                    this.dic[section] = kss.ToArray();
                    this.ini.DeleteKey(section, ks.Key);

                    verify.Answer = this.dic[section];
                    verify.Source = this.ini.GetKeyValues(section);
                    if (!verify.Calc())
                    {
                        return false;
                    }
                    return true;
                },
            });
        }
Exemple #2
0
 public CaseModel Func_GetKeyValues()
 {
     return(new CaseModel()
     {
         NameSign = @"获得部分的所有键值",
         ExeEvent = () => {
             VerifyIList <KeyString, KeyString> verify = new VerifyIList <KeyString, KeyString>(CalcWayEnum.DoubleCycle)
             {
                 Func_isEquals = (a, s) => a.Key == s.Key && a.Value == s.Value,
             };
             foreach (KeyValuePair <string, KeyString[]> section in this.dic)
             {
                 verify.Answer = section.Value;
                 verify.Source = ini.GetKeyValues(section.Key);
                 verify.Func_notFind = (ks) => {
                     Console.WriteLine("GetKeyValues() 错误! section: {0} key: {1} value: {2} 没找到!", section.Key, ks.Key, ks.Value);
                 };
                 if (!verify.Calc())
                 {
                     return false;
                 }
             }
             return true;
         },
     });
 }
Exemple #3
0
        public CaseModel Func_ClearSection()
        {
            return(new CaseModel()
            {
                NameSign = @"清空 Section 部分",
                ExeEvent = () => {
                    VerifyIList <string, string> verify = new VerifyIList <string, string>(CalcWayEnum.DoubleCycle);
                    verify.Answer = new List <string>(this.dic.Keys);
                    verify.Source = this.ini.GetSections();
                    if (!verify.Calc())
                    {
                        return false;
                    }

                    string section = RandomData.Item(new List <string>(this.dic.Keys));
                    this.dic.Remove(section);
                    this.ini.ClearSection(section);

                    verify.Answer = new List <string>(this.dic.Keys);
                    verify.Source = this.ini.GetSections();
                    if (!verify.Calc())
                    {
                        return false;
                    }
                    return true;
                },
            });
        }
            public CaseModel Func_Insert_List()
            {
                return(new CaseModel()
                {
                    NameSign = @"添加多条",
                    ExeEvent = () => {
                        TestModel[] array = GetRandomDatas();
                        // 排序:
                        // List<TestModel> list = new List<TestModel>(array);
                        // list.Sort((one, two) => one.IID == two.IID ? 0 : one.IID < two.IID ? -1 : 1);
                        // array = list.ToArray();

                        iDAL.Delete(null);
                        iDAL.Insert((M[])array);
                        TestModel[] query_result = iDAL.Select(0, null, sorts);
                        bool isby = new VerifyIList <TestModel, TestModel>(CalcWayEnum.DoubleCycle)
                        {
                            Answer = array,
                            Source = query_result,
                            Func_isEquals = TestModelIsEqual,
                        }.Calc();
                        if (!isby)
                        {
                            throw new Exception("错误");
                        }
                        return isby;
                    },
                });
            }
            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;
                    },
                });
            }
            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;
                    },
                });
            }
            public ToRangeList()
            {
                this.NameSign = @"获取列表范围";
                this.ExeEvent = () => {
                    int      sumcount = ToRangeListItem.DataSumCount;
                    string[] source   = new string[sumcount];
                    for (int i = 0; i < source.Length; i++)
                    {
                        source[i] = string.Format("第{0}项", i);
                    }

                    // auto 规则测试
                    VerifyIList <string, string> verify = new VerifyIList <string, string>(CalcWayEnum.DoubleCycle);
                    foreach (ToRangeListItem item in ToRangeListItem.ResultAnswer())
                    {
                        verify.Answer = item.result;
                        verify.Source = ConvertTool.ToRangePage(source, item.index, item.count);
                        if (!verify.Calc())
                        {
                            Console.WriteLine("Error: sum: {0}  index: {1}  count: {2}  result: {3}", source.Length, item.index, item.count, JSON.Serializer(item.result));
                        }
                    }
                    Console.WriteLine("自动化程序测试结果成功!");

                    // old 生成结果数据
                    string absfile = PathHelp.CreateUseFilePath(@"/auto/tools/Test_ConvertTool", @"Func_ToRangeList.txt");
                    File.Delete(absfile);
                    using (FileStream fileshream = new FileStream(absfile, FileMode.OpenOrCreate)) {
                        using (StreamWriter writer = new StreamWriter(fileshream, YTS.Tools.Const.Format.FILE_ENCODING)) {
                            for (int count = 9; count <= 11; count++)
                            {
                                for (int index = -1; index < 11; index++)
                                {
                                    string[] result = ConvertTool.ToRangePage(source, index, count);
                                    writer.WriteLine("sum: {0}  index: {1}  count: {2}  result: {3}", source.Length, index, count, JSON.Serializer(result));
                                }
                                writer.WriteLine();
                            }
                            writer.Flush();
                        }
                    }
                    Console.WriteLine("生成结果数据: {0}", absfile);
                    return(true);
                };
            }
Exemple #8
0
 public CaseModel Func_GetSections()
 {
     return(new CaseModel()
     {
         NameSign = @"获得所有部分",
         ExeEvent = () => {
             VerifyIList <string, string> verify = new VerifyIList <string, string>(CalcWayEnum.DoubleCycle)
             {
                 Answer = new List <string>(this.dic.Keys),
                 Source = ini.GetSections(),
                 Func_notFind = (section) => {
                     Console.WriteLine("GetSections() 错误! section: {0} 没找到!", section);
                 }
             };
             return verify.Calc();
         },
     });
 }
        public bool CalcMethod(Func <Person[], string> serializer, Func <string, Person[]> deserialize)
        {
            Person[] array      = GetModels();
            string   str_result = serializer(array);

            Person[] source = deserialize(str_result);

            VerifyIList <Person, Person> verify = new VerifyIList <Person, Person>(CalcWayEnum.SingleCycle)
            {
                Answer        = array,
                Source        = source,
                Func_isEquals = (a, s) => {
                    return(a.Age == s.Age &&
                           a.Bill.Title == s.Bill.Title &&
                           a.Bill.Surname == s.Bill.Surname);
                },
            };

            return(verify.Calc());
        }
        public CaseModel Func_ToRangeIndex()
        {
            return(new CaseModel()
            {
                NameSign = @"指定范围索引长度",
                ExeEvent = () => {
                    StringBuilder str = new StringBuilder();

                    int[] list = new int[] { 0, 1, 2, 3, 4, 5 };
                    str.AppendFormat("list: {0}\n\n", JSON.Serializer(list));
                    for (int index = -2; index < list.Length + 2; index++)
                    {
                        for (int length = -2; length < list.Length + 2; length++)
                        {
                            int[] result = ConvertTool.ToRangeIndex(list, index, length);
                            str.AppendFormat("index: {0} length: {1} result: {2}\n", index, length, JSON.Serializer(result));
                        }
                    }

                    string path = PathHelp.CreateUseFilePath(@"/auto/tools/Test_ConvertTool", @"Func_ToRangeIndex.txt");
                    this.ClearAndWriteFile(path, str.ToString());

                    VerifyIList <int, int> verify = new VerifyIList <int, int>(CalcWayEnum.DoubleCycle);
                    Action <int, int, int[]> method = (index, length, source) => {
                        verify.Answer = source;
                        verify.Source = ConvertTool.ToRangeIndex(list, index, length);
                        if (!verify.Calc())
                        {
                            Console.WriteLine("Error! index: {0} length: {1} result: {2}", index, length, JSON.Serializer(verify.Source));
                            throw new Exception("错误!");
                        }
                    };

                    method(-2, -2, new int[] { });
                    method(-2, -1, new int[] { });
                    method(-2, 0, new int[] { });
                    method(-2, 1, new int[] { 0 });
                    method(-2, 2, new int[] { 0, 1 });
                    method(-2, 3, new int[] { 0, 1, 2 });
                    method(-2, 4, new int[] { 0, 1, 2, 3 });
                    method(-2, 5, new int[] { 0, 1, 2, 3, 4 });
                    method(-2, 6, new int[] { 0, 1, 2, 3, 4, 5 });
                    method(-2, 7, new int[] { 0, 1, 2, 3, 4, 5 });
                    method(-1, -2, new int[] { });
                    method(-1, -1, new int[] { });
                    method(-1, 0, new int[] { });
                    method(-1, 1, new int[] { 0 });
                    method(-1, 2, new int[] { 0, 1 });
                    method(-1, 3, new int[] { 0, 1, 2 });
                    method(-1, 4, new int[] { 0, 1, 2, 3 });
                    method(-1, 5, new int[] { 0, 1, 2, 3, 4 });
                    method(-1, 6, new int[] { 0, 1, 2, 3, 4, 5 });
                    method(-1, 7, new int[] { 0, 1, 2, 3, 4, 5 });
                    method(0, -2, new int[] { });
                    method(0, -1, new int[] { });
                    method(0, 0, new int[] { });
                    method(0, 1, new int[] { 0 });
                    method(0, 2, new int[] { 0, 1 });
                    method(0, 3, new int[] { 0, 1, 2 });
                    method(0, 4, new int[] { 0, 1, 2, 3 });
                    method(0, 5, new int[] { 0, 1, 2, 3, 4 });
                    method(0, 6, new int[] { 0, 1, 2, 3, 4, 5 });
                    method(0, 7, new int[] { 0, 1, 2, 3, 4, 5 });
                    method(1, -2, new int[] { });
                    method(1, -1, new int[] { });
                    method(1, 0, new int[] { });
                    method(1, 1, new int[] { 1 });
                    method(1, 2, new int[] { 1, 2 });
                    method(1, 3, new int[] { 1, 2, 3 });
                    method(1, 4, new int[] { 1, 2, 3, 4 });
                    method(1, 5, new int[] { 1, 2, 3, 4, 5 });
                    method(1, 6, new int[] { 1, 2, 3, 4, 5 });
                    method(1, 7, new int[] { 1, 2, 3, 4, 5 });
                    method(2, -2, new int[] { });
                    method(2, -1, new int[] { });
                    method(2, 0, new int[] { });
                    method(2, 1, new int[] { 2 });
                    method(2, 2, new int[] { 2, 3 });
                    method(2, 3, new int[] { 2, 3, 4 });
                    method(2, 4, new int[] { 2, 3, 4, 5 });
                    method(2, 5, new int[] { 2, 3, 4, 5 });
                    method(2, 6, new int[] { 2, 3, 4, 5 });
                    method(2, 7, new int[] { 2, 3, 4, 5 });
                    method(3, -2, new int[] { });
                    method(3, -1, new int[] { });
                    method(3, 0, new int[] { });
                    method(3, 1, new int[] { 3 });
                    method(3, 2, new int[] { 3, 4 });
                    method(3, 3, new int[] { 3, 4, 5 });
                    method(3, 4, new int[] { 3, 4, 5 });
                    method(3, 5, new int[] { 3, 4, 5 });
                    method(3, 6, new int[] { 3, 4, 5 });
                    method(3, 7, new int[] { 3, 4, 5 });
                    method(4, -2, new int[] { });
                    method(4, -1, new int[] { });
                    method(4, 0, new int[] { });
                    method(4, 1, new int[] { 4 });
                    method(4, 2, new int[] { 4, 5 });
                    method(4, 3, new int[] { 4, 5 });
                    method(4, 4, new int[] { 4, 5 });
                    method(4, 5, new int[] { 4, 5 });
                    method(4, 6, new int[] { 4, 5 });
                    method(4, 7, new int[] { 4, 5 });
                    method(5, -2, new int[] { });
                    method(5, -1, new int[] { });
                    method(5, 0, new int[] { });
                    method(5, 1, new int[] { 5 });
                    method(5, 2, new int[] { 5 });
                    method(5, 3, new int[] { 5 });
                    method(5, 4, new int[] { 5 });
                    method(5, 5, new int[] { 5 });
                    method(5, 6, new int[] { 5 });
                    method(5, 7, new int[] { 5 });
                    method(6, -2, new int[] { });
                    method(6, -1, new int[] { });
                    method(6, 0, new int[] { });
                    method(6, 1, new int[] { });
                    method(6, 2, new int[] { });
                    method(6, 3, new int[] { });
                    method(6, 4, new int[] { });
                    method(6, 5, new int[] { });
                    method(6, 6, new int[] { });
                    method(6, 7, new int[] { });
                    method(7, -2, new int[] { });
                    method(7, -1, new int[] { });
                    method(7, 0, new int[] { });
                    method(7, 1, new int[] { });
                    method(7, 2, new int[] { });
                    method(7, 3, new int[] { });
                    method(7, 4, new int[] { });
                    method(7, 5, new int[] { });
                    method(7, 6, new int[] { });
                    method(7, 7, new int[] { });

                    return true;
                },
            });
        }