public void IsMatch_MultiplePatterns_ReturnsTrue()
        {
            var simple = new SimpleMatchOperation ("{foo}/{bar}");

            int end;
            DataDictionary data = new DataDictionary ();

            bool is_match = simple.IsMatch ("match1/match2", 0, data, out end);
            Assert.IsTrue (is_match);
        }
        public void IsMatch_MatchSecondLastChar_ReturnsTrue()
        {
            var simple = new SimpleMatchOperation ("/foo/{bar}~");

            int end;
            DataDictionary data = new DataDictionary ();

            bool is_match = simple.IsMatch ("/foo/barbaz~", 0, data, out end);
            Assert.IsTrue (is_match);
        }
        public void IsMatch_MatchBeforeEnd_SetsEndCorrectly()
        {
            var simple = new SimpleMatchOperation ("/{bar}/");

            int end;
            DataDictionary data = new DataDictionary ();

            simple.IsMatch ("/yup/more/data/foo/", 0, data, out end);
            Assert.AreEqual (5, end);
        }
        public void Clear_ItemInCollection_SetsCountZero()
        {
            var nvc = new DataDictionary ();
            var rdd = new RequestDataDictionary ();

            nvc.Add ("foobar", "baz");
            rdd.AddCollection (nvc);

            rdd.Clear ();
            Assert.AreEqual (0, rdd.Count);
        }
Exemple #5
0
        public bool IsMatch(string input, int start, DataDictionary data, out int end)
        {
            int i = input.IndexOf (String, start);

            if (i != start) {
                end = start;
                return false;
            }

            end = start + String.Length;
            return true;
        }
        public void MatchNotAtStartShouldFail()
        {
            var op = new StringMatchOperation ("oobar");
            var data = new DataDictionary ();
            int end;

            bool m = op.IsMatch ("foobar", 0, out data, out end);

            Assert.IsFalse (m, "a1");
            Assert.IsNull (data, "a2");
            Assert.AreEqual (0, end, "a3");
        }
        public void MatchFullStringTest()
        {
            var op = new StringMatchOperation ("foobar");
            var data = new DataDictionary ();
            int end;

            bool m = op.IsMatch ("foobar", 0, out data, out end);

            Assert.IsTrue (m, "a1");
            Assert.IsNull (data, "a2");
            Assert.AreEqual (6, end, "a3");
        }
        public bool IsMatch(string input, int start, out DataDictionary data, out int end)
        {
            if (!StartsWith (input, start, String)) {
                data = null;
                end = start;
                return false;
            }

            data = null;
            end = start + String.Length;
            return true;
        }
        public void EmptyRegexTest()
        {
            var r = new Regex ("");
            var op = new RegexMatchOperation (r);
            var col = new DataDictionary ();
            int end;

            bool m = op.IsMatch ("", 0, col, out end);

            Assert.IsTrue (m, "a1");
            Assert.AreEqual (0, end, "a2");
        }
        internal static bool IsMatchInternal(string the_string, string input, int start, out DataDictionary data, out int end)
        {
            if (!StartsWith (input, start, the_string)) {
                data = null;
                end = start;
                return false;
            }

            data = null;
            end = start + the_string.Length;
            return true;
        }
        public void Clear_ItemInCollection_RemovesItem()
        {
            var nvc = new DataDictionary ();
            var rdd = new RequestDataDictionary ();

            nvc.Add ("foobar", "baz");
            rdd.AddCollection (nvc);

            rdd.Clear ();

            bool has_item = rdd.ContainsKey ("foobar");

            Assert.IsFalse (has_item);
        }
Exemple #12
0
        public MockHttpRequest(string method, string local_path)
        {
            Method = method;
            LocalPath = local_path;

            data = new DataDictionary ();
            uri_data = new DataDictionary ();
            query_data = new DataDictionary ();
            post_data = new DataDictionary ();

            data.Children.Add (UriData);
            data.Children.Add (QueryData);
            data.Children.Add (PostData);
        }
Exemple #13
0
        public MockHttpRequest(HttpMethod method, string path)
        {
            Method = method;
            Path = path;

            data = new DataDictionary ();
            uri_data = new DataDictionary ();
            query_data = new DataDictionary ();
            post_data = new DataDictionary ();

            data.Children.Add (UriData);
            data.Children.Add (QueryData);
            data.Children.Add (PostData);
        }
        public void IsMatch_MultiplePatterns_FindsData()
        {
            var simple = new SimpleMatchOperation ("{foo}/{bar}");

            int end;
            DataDictionary data = new DataDictionary ();

            simple.IsMatch ("match1/match2", 0, data, out end);

            string match1 = data ["foo"];
            string match2 = data ["bar"];

            Assert.AreEqual ("match1", match1, "match 1");
            Assert.AreEqual ("match2", match2, "match 2");
        }
Exemple #15
0
        public bool IsMatch(string input, int start, out DataDictionary data, out int end)
        {
            Match m = regex.Match (input, start);

            regex.Match (input, start);
            if (!m.Success || m.Index != start) {
                data = null;
                end = start;
                return false;
            }

            data = new DataDictionary ();
            AddUriData (m, data);
            end = m.Index + m.Length;
            return true;
        }
        public void MatchPartialStringTest()
        {
            var op = new StringMatchOperation ("foo");
            var data = new DataDictionary ();
            int end;

            bool m = op.IsMatch ("foobar", 0, data, out end);

            Assert.IsTrue (m, "a1");
            Assert.AreEqual (0, data.Count, "a2");
            Assert.AreEqual (3, end, "a3");

            op = new StringMatchOperation ("bar");
            m = op.IsMatch ("foobar", end, data, out end);
            Assert.IsTrue (m, "a4");
            Assert.AreEqual (0, data.Count, "a5");
            Assert.AreEqual (6, end, "a3");
        }
Exemple #17
0
        public void TestIsMatch()
        {
            var op = new NopMatchOperation ();
            var data = new DataDictionary ();
            int end;

            bool m = op.IsMatch ("foobar", 0, data, out end);

            Assert.IsTrue (m, "a1");
            Assert.AreEqual (0, data.Count, "a2");
            Assert.AreEqual (0, end, "a3");

            m = op.IsMatch ("foobar", 3, data, out end);

            Assert.IsTrue (m, "a4");
            Assert.AreEqual (0, data.Count, "a5");
            Assert.AreEqual (3, end, "a6");
        }
Exemple #18
0
        public HttpRequest(IHttpTransaction transaction, HttpHeaders headers, string method, string resource, bool support_1_1)
        {
            Transaction = transaction;
            Headers = headers;
            Method = method;
            ResourceUri = resource;
            Http_1_1_Supported = support_1_1;

            Data = new DataDictionary ();
            UriData = new DataDictionary ();
            QueryData = new DataDictionary ();
            PostData = new DataDictionary ();

            Data.Children.Add (UriData);
            Data.Children.Add (QueryData);
            Data.Children.Add (PostData);

            SetEncoding ();
            SetPathAndQuery ();
        }
        public void SimpleGroupTest()
        {
            var r = new Regex ("-(?<foo>.*?)-");
            var op = new RegexMatchOperation (r);
            var col = new DataDictionary ();
            int end;
            bool m;

            m = op.IsMatch ("-manos-", 0, col, out end);
            Assert.IsTrue (m, "a1");
            Assert.AreEqual (1, col.Count, "a2");
            Assert.AreEqual ("manos", col ["foo"], "a3");
            Assert.AreEqual (7, end, "a4");

            col = new DataDictionary ();
            m = op.IsMatch ("manos-", 0, col, out end);
            Assert.IsFalse (m, "a5");
            Assert.AreEqual (0, col.Count, "a6");
            Assert.AreEqual (0, end, "a7");
        }
        public void SimpleRegexTest()
        {
            var r = new Regex (".og");
            var op = new RegexMatchOperation (r);
            var col = new DataDictionary ();
            int end;
            bool m;

            m = op.IsMatch ("dog", 0, col, out end);
            Assert.IsTrue (m, "a1");
            Assert.AreEqual (0, col.Count, "a2");
            Assert.AreEqual (3, end, "a3");

            m = op.IsMatch ("log", 0, col, out end);
            Assert.IsTrue (m, "a4");
            Assert.AreEqual (0, col.Count, "a5");
            Assert.AreEqual (3, end, "a6");

            m = op.IsMatch ("fox", 0, col, out end);
            Assert.IsFalse (m, "a7");
            Assert.AreEqual (0, col.Count, "a8");
            Assert.AreEqual (0, end, "a9");
        }
Exemple #21
0
        public bool IsMatch(string input, int start, out DataDictionary data, out int end)
        {
            end = start;
            data = null;

            if (groups == null) {
                return false;
            }

            int input_pos = start;
            int pattern_pos = 0;

            string data_str;
            foreach (Group g in groups) {
                // scan until start
                int g_start = start + g.Start;

                if (g_start > pattern.Length)
                    return false;

                int len = g_start - pattern_pos;
                for (int i = 0; i < len; i++) {
                    if (input [input_pos] != pattern [pattern_pos])
                        return false;

                    input_pos++;
                    pattern_pos++;

                    if (input_pos > input.Length - 1)
                        return false;
                }

                if (g.End == pattern.Length - 1) {
                    // slurp until end
                    data_str = input.Substring (input_pos);
                    if (data == null)
                        data = new DataDictionary ();
                    data.Set (g.Name, data_str);

                    end = input.Length;
                    return true;
                }

                int input_start = input_pos;
                char end_marker = pattern [g.End + 1];
                while (input [input_pos] != end_marker) {
                    input_pos++;
                    if (input_pos >= input.Length)
                        return false;
                }

                data_str = input.Substring (input_start, input_pos - input_start);
                if (data == null)
                    data = new DataDictionary ();
                data.Set (g.Name, data_str);

                input_pos++;
                pattern_pos = g.End + 2;
            }

            while (pattern_pos < pattern.Length) {
                if (pattern [pattern_pos] != input [input_pos]) {
                    return false;
                }
                pattern_pos++;
                input_pos++;

                if (input_pos > input.Length) {
                    return false;
                }
            }

            end = input_pos;
            return true;
        }
Exemple #22
0
 public void SetWwwFormData(DataDictionary data)
 {
     PostData.Children.Add (data);
 }
Exemple #23
0
 public void SetWwwFormData(DataDictionary data)
 {
     PostData = data;
 }
Exemple #24
0
        public override void Reset()
        {
            Path = null;

            uri_data = null;
            query_data = null;
            cookies = null;

            base.Reset ();
        }
Exemple #25
0
        private void AddUriData(Match m, DataDictionary uri_data)
        {
            string[] groups = regex.GetGroupNames();
            foreach (string gn in groups)
            {
                Group g = m.Groups[gn];

                //
                // Unfortunately regex matching creates named groups with
                // the match index as their name, we want to filter all of
                // these guys out.
                //
                int dummy;
                if (Int32.TryParse(gn, out dummy))
                    continue;
                uri_data.Set(gn, g.Value);
            }
        }
Exemple #26
0
        static string RequestQueryString(DataDictionary queryData)
        {
            var count = queryData.Count;
            if (count == 0)
                return null;

            var sb = new StringBuilder();
            foreach (var key in queryData.Keys)
            {
                if (sb.Length != 0)
                {
                    sb.Append('&');
                }
                UrlEncode(key, sb);
                sb.Append('=');
                UrlEncode(queryData.Get(key).UnsafeValue, sb);
            }
            return sb.ToString();
        }
Exemple #27
0
        public static DataDictionary FromHeader(string header)
        {
            int eq_idx = -1;
            int key_idx = 0;
            var dict = new DataDictionary();

            for (int i = 0; i < header.Length; i++)
            {
                if (header[i] == ';')
                {
                    if (eq_idx == -1)
                        continue;
                    string key = header.Substring(key_idx, eq_idx - key_idx);
                    string value = header.Substring(eq_idx + 1, i - eq_idx - 1);

                    dict.Set(key.Trim(), value.Trim());

                    key_idx = i + 1;
                    eq_idx = -1;
                    continue;
                }

                if (header[i] == '=')
                    eq_idx = i;
            }

            if (eq_idx != -1)
            {
                string key = header.Substring(key_idx, eq_idx - key_idx);
                string value = header.Substring(eq_idx + 1);

                dict.Set(key.Trim(), value.Trim());
            }

            return dict;
        }
Exemple #28
0
        internal static void ParseUrlEncodedData(string data, Encoding encoding, DataDictionary result)
        {
            if (data.Length == 0)
                return;

            string decoded = HtmlDecode (data);
            int decodedLength = decoded.Length;
            int namePos = 0;
            bool first = true;
            while (namePos <= decodedLength) {
                int valuePos = -1, valueEnd = -1;
                for (int q = namePos; q < decodedLength; q++) {
                    if (valuePos == -1 && decoded [q] == '=') {
                        valuePos = q + 1;
                    } else if (decoded [q] == '&') {
                        valueEnd = q;
                        break;
                    }
                }

                if (first) {
                    first = false;
                    if (decoded [namePos] == '?')
                        namePos++;
                }

                string name, value;
                if (valuePos == -1) {
                    name = null;
                    valuePos = namePos;
                } else {
                    name = UrlDecode (decoded.Substring (namePos, valuePos - namePos - 1), encoding);
                }
                if (valueEnd < 0) {
                    namePos = -1;
                    valueEnd = decoded.Length;
                } else {
                    namePos = valueEnd + 1;
                }
                value = UrlDecode (decoded.Substring (valuePos, valueEnd - valuePos), encoding);

                if (name == null) {
                   name = value;
                   value = String.Empty;
                }
                result.Set (name, value);
                if (namePos == -1)
                    break;
            }
        }
Exemple #29
0
 private void SetDataDictionary(DataDictionary old, DataDictionary newd)
 {
     if (data != null && old != null)
         data.Children.Remove (old);
     if (newd != null)
         Data.Children.Add (newd);
 }
Exemple #30
0
 public With(MockHttpRequest request, DataDictionary dict)
 {
     _request = request;
     _dict = dict;
 }