コード例 #1
0
        public string GenerateUnitTest(string categoryName, string accessToken)
        {
            // 1. read assembly
            // 2. find methods in particular category
            // 3. find methods with not input parameters (it's the most simple case)
            // 4. invoke a method
            // 5. construct unit-test
            // 6. return it

            Assembly dll = Assembly.LoadFrom("VkNet.dll");

            // todo refactor it later
            List <Type> classes = dll.GetTypes().Where(t => t.Name.Contains("Category") && t.Name.Contains(categoryName)).ToList();

            Type category = classes.FirstOrDefault();

            MethodInfo[] methods = category.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);

            var genMethods = new List <VkMethodGenInfo>();

            foreach (var methodInfo in methods)
            {
                var genInfo = GetMethodData(methodInfo);

                if (string.IsNullOrEmpty(genInfo.ApiMethod))
                {
                    continue;
                }

                Debug.WriteLine(genInfo.ToString());

                genMethods.Add(genInfo);
            }

            // invoke and get json and url
            var api = new VkApi();

            api.Authorize(accessToken);
            // TODO must be authorized

            var unittests = new List <UnitTestInfo>();

            var testCategory = new StringBuilder();

            foreach (var m in genMethods)
            {
                if (m.Skip)
                {
                    continue;
                }

                var test = new UnitTestInfo
                {
                    Name = string.Format("{0}_", m.Name),
                    Url  = Utilities.PreetyPrintApiUrl(api.GetApiUrl(m.ApiMethod, m.Params))
                };

                // TODO refactor this shit
                int index = test.Url.IndexOf("access_token", StringComparison.InvariantCulture);
                if (index != -1)
                {
                    test.Url = test.Url.Substring(0, index) + "access_token=token\";";
                }

                test.Json = Utilities.PreetyPrintJson(api.Invoke(m.ApiMethod, m.Params));

                unittests.Add(test);

                testCategory.Append(test);
            }

            File.WriteAllText(@"d:\vk.txt", testCategory.ToString());

            return(string.Empty);

            //throw new NotImplementedException();
        }
コード例 #2
0
ファイル: VkApiGenerator.cs プロジェクト: G-IT-ED/vk
        public string GenerateUnitTest(string categoryName, string accessToken)
        {
            // 1. read assembly
            // 2. find methods in particular category
            // 3. find methods with not input parameters (it's the most simple case)
            // 4. invoke a method
            // 5. construct unit-test
            // 6. return it

            Assembly dll = Assembly.LoadFrom("VkNet.dll");

            // todo refactor it later
            List<Type> classes = dll.GetTypes().Where(t => t.Name.Contains("Category") && t.Name.Contains(categoryName)).ToList();

            Type category = classes.FirstOrDefault();

            MethodInfo[] methods = category.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);

            var genMethods = new List<VkMethodGenInfo>();
            foreach (var methodInfo in methods)
            {
                var genInfo = GetMethodData(methodInfo);

                if (string.IsNullOrEmpty(genInfo.ApiMethod)) continue;

                Debug.WriteLine(genInfo.ToString());

                genMethods.Add(genInfo);

            }

            // invoke and get json and url
            var api = new VkApi();

            api.Authorize(accessToken);
            // TODO must be authorized

            var unittests = new List<UnitTestInfo>();

            var testCategory = new StringBuilder();
            foreach (var m in genMethods)
            {
                if (m.Skip) continue;

                var test = new UnitTestInfo
                {
                    Name = string.Format("{0}_", m.Name),
                    Url = Utilities.PreetyPrintApiUrl(api.GetApiUrl(m.ApiMethod, m.Params))
                };

                // TODO refactor this shit
                int index = test.Url.IndexOf("access_token", StringComparison.InvariantCulture);
                if (index != -1)
                {
                    test.Url = test.Url.Substring(0, index) + "access_token=token\";";
                }

                test.Json = Utilities.PreetyPrintJson(api.Invoke(m.ApiMethod, m.Params));

                unittests.Add(test);

                testCategory.Append(test);
            }

            File.WriteAllText(@"d:\vk.txt", testCategory.ToString());

            return string.Empty;

            //throw new NotImplementedException();
        }