コード例 #1
0
 private void PrepareResponseCore(TestWebRequest request)
 {
     if (PrepareResponse!=null)
     {
         PrepareResponse(request);
     }
 }
コード例 #2
0
        public void PopulateRequest(TestWebRequest target, RequestInfoBase source)
        {

            target.SetResponseStream(source.ResponseText);
            target.ContentType = source.RequestContentType.ToHeaderValue();
            foreach (var h in source.Headers)
            {
                target.Headers[h.Key] = h.Value;
            }

        }
コード例 #3
0
 public RequestInfoBase FindMatchBySingleHeader(TestWebRequest webRequest, string headerKey)
 {
     string headerValue = webRequest.Headers[headerKey];
     foreach (RequestInfoBase r in Reference)
     {
         if (r.Headers.ContainsKey(headerKey))
         {
             if ((string)r.Headers[headerKey] == headerValue)
             {
                 return r;
             }
         }
     }
     return null;
 }
コード例 #4
0
        public RequestInfoBase FindMatchExact(TestWebRequest webRequest)
        {

            foreach (RequestInfoBase r in Reference)
            {
                if (string.Compare(r.Method.ToString(), webRequest.Method, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    continue;
                }

                if (string.Compare(r.Uri.AbsoluteUri, webRequest.RequestUri.AbsoluteUri, StringComparison.InvariantCultureIgnoreCase) != 0)
                {
                    continue;
                }

                // #hack - RequestInfoBase requestbody is getting set null while TestWebRequest.RequestBody is returning empty string
                // have to decide which is approppriate and standardize
                if ((r.RequestBody ?? "") != webRequest.RequestBody)
                {
                    continue;
                }

                if (r.Headers != null)
                {
                    if (webRequest.Headers == null)
                    {
                        continue;
                    }

                    //#TODO: compare headers
                }

                return r;


            }
            return null;
        }
コード例 #5
0
 public WebRequest Create(string url)
 {
     var request = new TestWebRequest(new Uri(url)) { PrepareResponse = PrepareResponseCore };
     return request;
 }
コード例 #6
0
 public void AddTestRequest(TestWebRequest testRequest)
 {
     TestWebRequests.Add(testRequest);
 }
コード例 #7
0
        public void PopulateRequest(TestWebRequest target, RequestInfoBase source)
        {
            
            target.ResponseStream = new TestWebStream(Encoding.UTF8.GetBytes(source.ResponseText));
            target.ContentType = source.RequestContentType.ToHeaderValue();
            foreach (var h in source.Headers)
            {
                target.Headers[h.Key] = h.Value.ToString();
            }

        }