private static Request VerifyRequest(Request request)
        {
            request = request ?? new Request();

            return new Request
            {
                Url = VerifyUrl(request.Url),
                Query = request.Query ?? new NameValueCollection(),
                Headers = request.Headers ?? new NameValueCollection(),
                Post = request.Post,
                File = request.File,
                Method = VerifyMethod(request.Method)
            };
        }
Beispiel #2
0
 public Endpoint()
 {
     Request = new Request();
     Responses = new List<Response>();
 }
Beispiel #3
0
 /// <summary>
 /// Find an endpoint by it's matching Request
 /// </summary>
 /// <param name="request">The signature of the request to find by</param>
 public Response Find(Request request)
 {
     return _endpointDb.Find(new Endpoint { Request = request });
 }
Beispiel #4
0
        private static Request ParseRequest(YamlMappingNode yamlRequest)
        {
            var request = new Request();

            foreach(var property in yamlRequest) {
                switch(property.Key.ToString()) {
                    case "url":
                        {
                            request.Url = ParseString(property);
                            break;
                        }
                    case "method":
                        {
                            request.Method = ParseMethod(property);
                            break;
                        }
                    case "file":
                        {
                            request.File = ParseFile(property);
                            break;
                        }
                    case "post":
                        {
                            request.Post = ParseString(property);
                            break;
                        }
                    case "query":
                        {
                            request.Query = ParseCollection(property);
                            break;
                        }
                    case "headers":
                        {
                            request.Headers = ParseCollection(property, false);
                            break;
                        }
                }
            }
            return request;
        }
Beispiel #5
0
 protected bool Equals(Request other)
 {
     if(!string.Equals(Url, other.Url))
         return false;
     if(!string.Equals(Post, other.Post))
         return false;
     if(!string.Equals(File, other.File))
         return false;
     if(!Compare.Lists(Method, other.Method))
         return false;
     if(!Compare.NameValueCollections(Headers, other.Headers))
         return false;
     if(!Compare.NameValueCollections(Query, other.Query))
         return false;
     return true;
 }
Beispiel #6
0
        internal bool Matches(Request other)
        {
            if(!Regex.IsMatch(other.Url, Url))
                return false;
            if(!Method.Contains(other.Method[0]))
                return false;

            foreach(var header in Headers.AllKeys) {
                IList<string> otherValues = other.Headers.GetValues(header);
                if(otherValues == null)
                    return false;
                if(!Headers.GetValues(header).All(h => otherValues.Any(o => Regex.IsMatch(o, h))))
                    return false;
            }

            foreach(var variable in Query.AllKeys) {
                IList<string> otherValues = other.Query.GetValues(variable);
                if(otherValues == null)
                    return false;
                if(!Query.GetValues(variable).All(q => otherValues.Any(o => Regex.IsMatch(o, q))))
                    return false;
            }

            try {
                return Regex.IsMatch(other.Post, System.IO.File.ReadAllText(File).TrimEnd(' ', '\n', '\r', '\t'));
            } catch {
                if(Post != null && !Regex.IsMatch(other.Post, Post))
                    return false;
            }

            return true;
        }