Esempio n. 1
0
        public void must_provide_required_args_to_builder()
        {
            var content = new CapturedMultipartContent();

            Assert.Throws <ArgumentNullException>(() => content.AddStringParts(null));
            Assert.Throws <ArgumentNullException>(() => content.AddString("other", null));
            Assert.Throws <ArgumentException>(() => content.AddString(null, "hello!"));
            Assert.Throws <ArgumentException>(() => content.AddFile("  ", "path"));
        }
Esempio n. 2
0
        /**
         * @param CapturedMultipartContent $content
         * @param JToken                   $json
         * @param string                   $key
         */
        private void captureMultipartContentInJson(CapturedMultipartContent content, JToken json, string key)
        {
            var property = json as JProperty;

            if (property == null)
            {
                return;
            }

            if (property.Value.GetType().Name == "JArray")
            {
                int index = 0;

                foreach (JToken child in property.Values())
                {
                    string valueKey = key == "" ? property.Name : $"{key}[{property.Name}]";
                    valueKey += $"[{index++}]";

                    if (child.GetType().Name == "JValue")
                    {
                        content.AddString(valueKey, $"{child}");
                    }
                    else
                    {
                        foreach (JToken subChild in child)
                        {
                            captureMultipartContentInJson(content, subChild, valueKey);
                        }
                    }
                }

                return;
            }

            if (property.Value.GetType().Name == "JObject")
            {
                string valueKey = key == "" ? property.Name : $"{key}[{property.Name}]";

                foreach (JToken child in property.Values())
                {
                    captureMultipartContentInJson(content, child, valueKey);
                }

                return;
            }

            if (property.Value.GetType().Name == "JValue")
            {
                string valueKey = key == "" ? property.Name : $"{key}[{property.Name}]";

                content.AddString(valueKey, property.Value.ToString());

                return;
            }
        }