Пример #1
0
 public void CreateRequest(ServToken st, string path, HttpMethod method, T entity, HttpStatusCode expectedStatusCode, bool deserialize = true, bool ignoreAction = false, bool breakExecution = false)
 {
     this.entity = entity;
     this.method = method;
     resp        = new HttpResponseMessage[CONTENT_TYPE_ACCEPT.Count];
     if (method.Method != HttpMethod.Post.Method &&
         method.Method != HttpMethod.Put.Method &&
         GenericNames.PATCH_VERB.Method != method.Method)
     {
         SendRequest(ignoreAction, path, st, expectedStatusCode, deserialize);
         return;
     }
     for (; current < CONTENT_TYPE_ACCEPT.Count; current++)
     {
         SendRequest(ignoreAction, path, st, expectedStatusCode, deserialize);
         if (ignoreAction)
         {
             break;
         }
         if (breakExecution)
         {
             if (current >= CONTENT_TYPE_ACCEPT.Count)
             {
                 current = 0;
             }
             current++;
             return;
         }
     }
     current = 0;
 }
Пример #2
0
        public dynamic CallSearch(ServToken st, string searchString, List <string> includes, Type type)
        {
            RequestCreator <AdvSearch> search = new RequestCreator <AdvSearch>();

            search.CreateRequest(st, SearchControllerTest.path, HttpMethod.Post, new AdvSearch()
            {
                Search  = searchString,
                Include = includes
            }, HttpStatusCode.OK, false);
            return(search.resp[0].Content.ReadAsAsync(type).Result);
        }
Пример #3
0
 private void SendRequest(bool ignoreAction, string path, ServToken st, HttpStatusCode expectedStatusCode, bool deserialize, bool throwOnFail = true)
 {
     if (ignoreAction == true)
     {
         resp[current] = st.server.CreateRequest(path).
                         AddHeader("Authorization", new AuthenticationHeaderValue("Bearer", st.token).ToString()).
                         SendAsync(method.Method).Result;
     }
     else
     {
         resp[current] = st.server.CreateRequest(path).
                         And(RequestAction).
                         AddHeader("Authorization", new AuthenticationHeaderValue("Bearer", st.token).ToString()).
                         SendAsync(method.Method).Result;
     }
     if (resp[current].StatusCode != expectedStatusCode && throwOnFail == true)
     {
         throw new Exception(resp[current].Content.ReadAsStringAsync().Result);
     }
     if (deserialize)
     {
         deserializedEntity = Deserialize <T>(CONTENT_TYPE_ACCEPT.ElementAt(current).Value, resp[current]);
     }
 }
Пример #4
0
 public void AuthenticationWithGoodParameter()
 {
     st = ControllerUtils.CreateAndAuthenticate();
 }