예제 #1
0
        public string SaveFile(PostmanModel model)
        {
            var settings = new JsonSerializerSettings();

            settings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Guid.NewGuid().ToString("N") + ".json");

            File.AppendAllText(path, JsonConvert.SerializeObject(model, settings));

            return(path);
        }
예제 #2
0
        public PostmanModel Create(string name)
        {
            var model = new PostmanModel();

            model.Info = new Info
            {
                Name      = name,
                PostmanId = Guid.NewGuid()
            };
            model.Item = new List <Item>();

            return(model);
        }
예제 #3
0
        public void ToModel(PostmanModel postmanJasonModel, List <RequestLog> listDistinct)
        {
            int getCount  = 0;
            int postCount = 0;

            Dictionary <string, string> dictWhatDo = null;
            var @event = new Event
            {
                Listen = "test",
                Script = new Script
                {
                    Id   = Guid.NewGuid(),
                    Type = "text/javascript",
                    Exec = new List <string>
                    {
                        "pm.test(\"response is ok\", function () {\r",
                        "    pm.response.to.have.status(200);\r",
                        "});\r",
                        "\r",
                        "pm.test(\"Succeed is true\", function () {\r",
                        "    var jsonData = pm.response.json();\r",
                        "    pm.expect(jsonData.Succeed).to.eql(true)\r",
                        "});\r",
                        "\r",
                        "pm.test(\"Data is exist\", function () {\r",
                        "    var jsonData = pm.response.json();\r",
                        "    pm.expect(jsonData.state).to.eql(0)\r",
                        "});"
                    }
                }
            };

            postmanJasonModel.Event = new List <Event> {
                @event
            };
            var cookie_Aspnet_session = new Header {
                Key   = "cookie",
                Value = "ASP.NET_SessionId={{DP_Session}};",
                Type  = "text"
            };

            var list2 = listDistinct.GroupBy(m => m.DirName);

            foreach (var m in list2)
            {
                Console.WriteLine($"m Name:{m.Key} list count:{m.Count()}");
                var dir1 = new ItemDir {
                    Name = m.Key
                };

                dictWhatDo = new Dictionary <string, string>();
                foreach (var m2 in m)
                {
                    var query = GetQuery(m2.Uri);
                    if (query != null)
                    {
                        var kv = query.FirstOrDefault(m6 => m6.Key == "whatDo");
                        if (kv.Key != null)
                        {
                            if (dictWhatDo.ContainsKey(kv.Value))
                            {
                                continue;
                            }

                            dictWhatDo[kv.Value] = string.Empty;
                        }
                    }

                    ItemRequest item = null;
                    if (m2.Method == "GET")
                    {
                        getCount++;
                        item = new ItemRequest
                        {
                            Name    = m2.Uri.PathAndQuery,
                            Request = new RequestGet
                            {
                                Url = new UrlModel
                                {
                                    Raw  = "{{DP_HOST}}" + m2.Uri.LocalPath,
                                    Host = new List <string> {
                                        "{{DP_HOST}}"
                                    },
                                    Path  = m2.Uri.LocalPath.Split('/', StringSplitOptions.RemoveEmptyEntries),
                                    Query = query
                                },
                                Header = new List <Header> {
                                    cookie_Aspnet_session
                                }
                            }
                        };
                    }
                    else
                    {
                        postCount++;
                        item = new ItemRequest
                        {
                            Name    = m2.Uri.PathAndQuery,
                            Request = new RequestPost
                            {
                                Url = new UrlModel
                                {
                                    Raw  = "{{DP_HOST}}" + m2.Uri.LocalPath,
                                    Host = new List <string> {
                                        "{{DP_HOST}}"
                                    },
                                    Path  = m2.Uri.LocalPath.Split('/', StringSplitOptions.RemoveEmptyEntries),
                                    Query = query
                                },
                                Body = new BodyByUrlencoded
                                {
                                    Urlencoded = new List <BodyByUrlencodedItem>
                                    {
                                    }
                                },
                                Header = new List <Header> {
                                    cookie_Aspnet_session
                                }
                            },
                        };
                    }

                    @event.Script.Id = Guid.NewGuid();
                    item.Event       = new List <Event> {
                    };
                    dir1.Item.Add(item);
                }

                postmanJasonModel.Item.Add(dir1);
            }

            Console.WriteLine($"get:{getCount}");
            Console.WriteLine($"post:{postCount}");
            Console.WriteLine($"filePath:{filePath}");
        }