using BenchmarkDotNet.Attributes;

using CloudGaming.DtoModel;
using CloudGaming.DtoModel.Epg;

using HuanMeng.DotNetCore.Utility;

using Newtonsoft.Json;

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudGaming.Test
{
    [MemoryDiagnoser]
    public class ToDictionaryOrListTest
    {
        public ToDictionaryOrListTest()
        {

        }


        [Benchmark]
        public object ObjectToDictionaryOrListTest1()
        {
            EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
            {
                CategoryName = "Banner",
                CategoryType = "Banner",
                IsQuickStartPopUp = true,
                ShowNum_Index = 10,
                EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=10,
                        EpgId=10,
                        IdName="IO",
                        ResType=4,
                        Title="title"
                    }
                },
            };

            var dic = epgCategoryDto.ToDictionaryOrList();
            return dic;

        }


        [Benchmark]
        public object ListToDictionaryOrListTest1()
        {

            List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
            for (int i = 0; i < 20; i++)
            {
                epgCategoryDtos.Add(new EpgCategoryDto()
                {
                    CategoryName = "Banner" + i,
                    CategoryType = "Banner" + i,
                    IsQuickStartPopUp = true,
                    ShowNum_Index = 10 + i,
                    EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=i,
                        EpgId=i,
                        IdName="IO"+i,
                        ResType=4,
                        Title="title"+i
                    },
                    new EpgInfo(){
                        CornerIcon=i+2,
                        EpgId=i+2,
                        IdName="IO"+i+2,
                        ResType=4+2,
                        Title="title"+i+2
                    }
                },
                });
            }

            var dic = epgCategoryDtos.ToDictionaryOrList();
            return dic;

        }


        //[Benchmark]
        public object ObjectToDictionaryOrListExtend1()
        {
            EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
            {
                CategoryName = "Banner",
                CategoryType = "Banner",
                IsQuickStartPopUp = true,
                ShowNum_Index = 10,
                EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=10,
                        EpgId=10,
                        IdName="IO",
                        ResType=4,
                        Title="title"
                    }
                },
            };
            var dic = ObjectExtensions1.ToDictionaryOrList(epgCategoryDto);
            return dic;

        }


        //[Benchmark]
        public object ListToDictionaryOrListExtend1()
        {
            List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
            for (int i = 0; i < 20; i++)
            {
                epgCategoryDtos.Add(new EpgCategoryDto()
                {
                    CategoryName = "Banner" + i,
                    CategoryType = "Banner" + i,
                    IsQuickStartPopUp = true,
                    ShowNum_Index = 10 + i,
                    EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=i,
                        EpgId=i,
                        IdName="IO"+i,
                        ResType=4,
                        Title="title"+i
                    },
                    new EpgInfo(){
                        CornerIcon=i+2,
                        EpgId=i+2,
                        IdName="IO"+i+2,
                        ResType=4+2,
                        Title="title"+i+2
                    }
                },
                });
            }


            var dic = ObjectExtensions1.ToDictionaryOrList(epgCategoryDtos);
            return dic;

        }



        //[Benchmark]
        public object ObjectToDictionaryOrListExtend3()
        {
            EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
            {
                CategoryName = "Banner",
                CategoryType = "Banner",
                IsQuickStartPopUp = true,
                ShowNum_Index = 10,
                EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=10,
                        EpgId=10,
                        IdName="IO",
                        ResType=4,
                        Title="title"
                    }
                },
            };
            var dic = ObjectExtensions3.ToDictionaryOrList(epgCategoryDto);
            return dic;

        }


        //[Benchmark]
        public object ListToDictionaryOrListExtend3()
        {
            List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
            for (int i = 0; i < 20; i++)
            {
                epgCategoryDtos.Add(new EpgCategoryDto()
                {
                    CategoryName = "Banner" + i,
                    CategoryType = "Banner" + i,
                    IsQuickStartPopUp = true,
                    ShowNum_Index = 10 + i,
                    EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=i,
                        EpgId=i,
                        IdName="IO"+i,
                        ResType=4,
                        Title="title"+i
                    },
                    new EpgInfo(){
                        CornerIcon=i+2,
                        EpgId=i+2,
                        IdName="IO"+i+2,
                        ResType=4+2,
                        Title="title"+i+2
                    }
                },
                });
            }


            var dic = ObjectExtensions3.ToDictionaryOrList(epgCategoryDtos);
            return dic;

        }

        // [Benchmark]
        public object ObjectToDictionaryOrListExtend4()
        {
            EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
            {
                CategoryName = "Banner",
                CategoryType = "Banner",
                IsQuickStartPopUp = true,
                ShowNum_Index = 10,
                EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=10,
                        EpgId=10,
                        IdName="IO",
                        ResType=4,
                        Title="title"
                    }
                },
            };
            var dic = ObjectExtensions5.ToDictionaryOrList(epgCategoryDto);
            return dic;

        }


        //[Benchmark]
        public object ListToDictionaryOrListExtend4()
        {
            List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
            for (int i = 0; i < 20; i++)
            {
                epgCategoryDtos.Add(new EpgCategoryDto()
                {
                    CategoryName = "Banner" + i,
                    CategoryType = "Banner" + i,
                    IsQuickStartPopUp = true,
                    ShowNum_Index = 10 + i,
                    EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=i,
                        EpgId=i,
                        IdName="IO"+i,
                        ResType=4,
                        Title="title"+i
                    },
                    new EpgInfo(){
                        CornerIcon=i+2,
                        EpgId=i+2,
                        IdName="IO"+i+2,
                        ResType=4+2,
                        Title="title"+i+2
                    }
                },
                });
            }


            var dic = ObjectExtensions5.ToDictionaryOrList(epgCategoryDtos);
            return dic;

        }

        //[Benchmark]
        public object ObjectToDictionaryOrListExtend6()
        {
            EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
            {
                CategoryName = "Banner",
                CategoryType = "Banner",
                IsQuickStartPopUp = true,
                ShowNum_Index = 10,
                EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=10,
                        EpgId=10,
                        IdName="IO",
                        ResType=4,
                        Title="title"
                    }
                },
            };
            var dic = ObjectExtensions6.ToDictionaryOrList(epgCategoryDto);
            return dic;

        }

        //
        //[Benchmark]
        public object ListToDictionaryOrListExtend6()
        {
            List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
            for (int i = 0; i < 20; i++)
            {
                epgCategoryDtos.Add(new EpgCategoryDto()
                {
                    CategoryName = "Banner" + i,
                    CategoryType = "Banner" + i,
                    IsQuickStartPopUp = true,
                    ShowNum_Index = 10 + i,
                    EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=i,
                        EpgId=i,
                        IdName="IO"+i,
                        ResType=4,
                        Title="title"+i
                    },
                    new EpgInfo(){
                        CornerIcon=i+2,
                        EpgId=i+2,
                        IdName="IO"+i+2,
                        ResType=4+2,
                        Title="title"+i+2
                    }
                },
                });
            }


            var dic = ObjectExtensions6.ToDictionaryOrList(epgCategoryDtos);
            return dic;
        }


        //[Benchmark]
        public object ObjectToDictionaryOrListExtend7()
        {
            EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
            {
                CategoryName = "Banner",
                CategoryType = "Banner",
                IsQuickStartPopUp = true,
                ShowNum_Index = 10,
                EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=10,
                        EpgId=10,
                        IdName="IO",
                        ResType=4,
                        Title="title"
                    }
                },
            };
            var dic = ObjectExtensions6.ToDictionaryOrList(epgCategoryDto);
            return dic;

        }


        //[Benchmark]
        public object ListToDictionaryOrListExtend7()
        {
            List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
            for (int i = 0; i < 20; i++)
            {
                epgCategoryDtos.Add(new EpgCategoryDto()
                {
                    CategoryName = "Banner" + i,
                    CategoryType = "Banner" + i,
                    IsQuickStartPopUp = true,
                    ShowNum_Index = 10 + i,
                    EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=i,
                        EpgId=i,
                        IdName="IO"+i,
                        ResType=4,
                        Title="title"+i
                    },
                    new EpgInfo(){
                        CornerIcon=i+2,
                        EpgId=i+2,
                        IdName="IO"+i+2,
                        ResType=4+2,
                        Title="title"+i+2
                    }
                },
                });
            }


            var dic = ObjectExtensions7.ToDictionaryOrList(epgCategoryDtos);
            return dic;
        }

        //[Benchmark]
        public object ObjectToDictionaryOrListExtend8()
        {
            EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
            {
                CategoryName = "Banner",
                CategoryType = "Banner",
                IsQuickStartPopUp = true,
                ShowNum_Index = 10,
                EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=10,
                        EpgId=10,
                        IdName="IO",
                        ResType=4,
                        Title="title"
                    }
                },
            };
            var dic = ObjectExtensions.ToDictionaryOrList(epgCategoryDto);
            return dic;

        }


        // [Benchmark]
        public object ListToDictionaryOrListExtend8()
        {
            List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
            for (int i = 0; i < 20; i++)
            {
                epgCategoryDtos.Add(new EpgCategoryDto()
                {
                    CategoryName = "Banner" + i,
                    CategoryType = "Banner" + i,
                    IsQuickStartPopUp = true,
                    ShowNum_Index = 10 + i,
                    EpgList = new List<EpgInfo>()
                {
                    new EpgInfo(){
                        CornerIcon=i,
                        EpgId=i,
                        IdName="IO"+i,
                        ResType=4,
                        Title="title"+i
                    },
                    new EpgInfo(){
                        CornerIcon=i+2,
                        EpgId=i+2,
                        IdName="IO"+i+2,
                        ResType=4+2,
                        Title="title"+i+2
                    }
                },
                });
            }


            var dic = ObjectExtensions.ToDictionaryOrList(epgCategoryDtos);
            return dic;
        }
    }
}
