예제 #1
0
        public void Test <T>(string threadName, ITestInfo testInfo, LogTypes logType)
        {
            var name  = testInfo.Name;
            var count = testInfo.Count;
            var text  = testInfo.Text;

            var obj = default(T);

            var first = this.DataTableNewRow(results);
            var times = this.DataTableNewRow(results);

            this.SetCellValue(first, TimeName, DateTime.Now.ToString("HH:mm:ss"));
            this.SetCellValue(times, TimeName, DateTime.Now.ToString("HH:mm:ss"));
            this.SetCellValue(first, CaseName, name);
            this.SetCellValue(times, CaseName, name);
            this.SetCellValue(first, ModeName, $"deser (first)");
            this.SetCellValue(times, ModeName, $"deser (the next {count} times)");
            this.SetCellValue(first, ThreadName, threadName);
            this.SetCellValue(times, ThreadName, threadName);

            if ((logType & LogTypes.OnlyFirst) != 0)
            {
                this.DataTableAddRow(results, first);
            }

            if ((logType & LogTypes.OnlyTheNext) != 0)
            {
                this.DataTableAddRow(results, times);
            }

            foreach (var item in testers)
            {
                try
                {
                    var stopwatch = Stopwatch.StartNew();

                    obj = item.Deserialize <T>(text);

                    var time = stopwatch.ElapsedMilliseconds;

                    if (testInfo.VerDeser(obj))
                    {
                        this.SetCellValue(first, item.Name, time);
                    }
                    else
                    {
                        this.SetCellValue(first, item.Name, Error);
                    }
                }
                catch (TimeoutException)
                {
                    this.SetCellValue(first, item.Name, Timeout);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"{item.Name} -- deser -- {name} : \n{e}");

                    this.SetCellValue(first, item.Name, Exception);
                }


                if ((logType & LogTypes.OnlyTheNext) != 0)
                {
                    try
                    {
                        obj = item.Deserialize <T>(text);

                        if (testInfo.VerDeser(obj))
                        {
                            var stopwatch = Stopwatch.StartNew();

                            for (int i = 0; i < count; i++)
                            {
                                item.Deserialize <T>(text);
                            }

                            var time = stopwatch.ElapsedMilliseconds;

                            this.SetCellValue(times, item.Name, time);
                        }
                        else
                        {
                            this.SetCellValue(times, item.Name, Error);
                        }
                    }
                    catch (TimeoutException)
                    {
                        this.SetCellValue(times, item.Name, Timeout);
                    }
                    catch (Exception)
                    {
                        this.SetCellValue(times, item.Name, Exception);
                    }
                }
            }

            foreach (var item in testers)
            {
                try
                {
                    obj = item.Deserialize <T>(text);

                    if (testInfo.VerDeser(obj))
                    {
                        break;
                    }
                }
                catch (Exception)
                {
                }
            }

            first = this.DataTableNewRow(results);
            times = this.DataTableNewRow(results);

            this.SetCellValue(first, TimeName, DateTime.Now.ToString("HH:mm:ss"));
            this.SetCellValue(times, TimeName, DateTime.Now.ToString("HH:mm:ss"));
            this.SetCellValue(first, CaseName, name);
            this.SetCellValue(times, CaseName, name);
            this.SetCellValue(first, ModeName, $"ser (first)");
            this.SetCellValue(times, ModeName, $"ser (the next {count} times)");
            this.SetCellValue(first, ThreadName, threadName);
            this.SetCellValue(times, ThreadName, threadName);

            if ((logType & LogTypes.OnlyFirst) != 0)
            {
                this.DataTableAddRow(results, first);
            }

            if ((logType & LogTypes.OnlyTheNext) != 0)
            {
                this.DataTableAddRow(results, times);
            }

            foreach (var item in testers)
            {
                try
                {
                    var stopwatch = Stopwatch.StartNew();

                    var json = item.Serialize(obj);

                    var time = stopwatch.ElapsedMilliseconds;


                    if (testInfo.VerSer(json))
                    {
                        this.SetCellValue(first, item.Name, time);
                    }
                    else
                    {
                        this.SetCellValue(first, item.Name, Error);
                    }
                }
                catch (TimeoutException)
                {
                    this.SetCellValue(first, item.Name, Timeout);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"{item.Name} -- ser -- {name} : \n{e}");

                    this.SetCellValue(first, item.Name, Exception);
                }


                if ((logType & LogTypes.OnlyTheNext) != 0)
                {
                    try
                    {
                        var json = item.Serialize(obj);

                        if (testInfo.VerSer(json))
                        {
                            var stopwatch = Stopwatch.StartNew();

                            for (int i = 0; i < count; i++)
                            {
                                item.Serialize(obj);
                            }

                            var time = stopwatch.ElapsedMilliseconds;

                            this.SetCellValue(times, item.Name, time);
                        }
                        else
                        {
                            this.SetCellValue(times, item.Name, Error);
                        }
                    }
                    catch (TimeoutException)
                    {
                        this.SetCellValue(times, item.Name, Timeout);
                    }
                    catch (Exception)
                    {
                        this.SetCellValue(times, item.Name, Exception);
                    }
                }
            }
        }