Ejemplo n.º 1
0
        /*
         * protected bool isValideJSON(Type type, string jsonData)
         * {
         *  JSchemaGenerator generator = new JSchemaGenerator();
         *  JSchema schema = generator.Generate(type);
         *  JSONData.LoadJSONSchemaToFile(type);
         *  try
         *  {
         *      if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(List<>)))
         *      {
         *          JArray jarray = JArray.Parse(jsonData);
         *          return jarray.IsValid(schema, out ErrorMessages);
         *      }
         *      JObject jobj = JObject.Parse(jsonData);
         *      return jobj.IsValid(schema, out ErrorMessages);
         *  }
         *  catch(JsonReaderException ex)
         *  {
         *      ErrorMessages.Add(ex.Message);
         *      Exceptions.Add(ex);
         *  }
         *  return false;
         * }
         */
        /*
         * protected T RunAPI<T>(string parameters, HttpVerbs method)
         * {
         *  T jsonObjectModel = default(T);
         *  Client.Method = method;
         *  var response = Client.Request(parameters);
         *  Response = response;
         * //            if (isValideJSON(typeof(T), response))
         *  try
         *  {
         *      jsonObjectModel = JsonConvert.DeserializeObject<T>(response);
         *      JSONData.LoadJSONDataToFile<T>(jsonObjectModel);
         *      return jsonObjectModel;
         *  }catch(Exception e)
         *  {
         *      ErrorMessages.Add(e.Message);
         *      Exceptions.Add(e);
         *  }
         *  Errors = (int)Client.HttpRequestStatusCode + " - " + Response + " : " + GetConfigErrorMessage("TypeOfVerification") + typeof(T).Name + ".\n";
         *  Errors = Errors + String.Join(";\n", ErrorMessages);
         *  return default(T);
         * }
         */

        /*
         * protected T RunAPI<T>(string parameters, HttpVerbs method, string body)
         * {
         *  T jsonObjectModel = default(T);
         *  Client.Body = body;
         *  Client.Method = method;
         *  var response = Client.Request(parameters);
         *  Response = response;
         *  //if (isValideJSON(typeof(T), response))
         *  try
         *  {
         *      jsonObjectModel = JsonConvert.DeserializeObject<T>(response);
         *      JSONData.LoadJSONDataToFile<T>(jsonObjectModel);
         *      return jsonObjectModel;
         *  }
         *  catch(Exception e)
         *  {
         *      ErrorMessages.Add(e.Message);
         *      Exceptions.Add(e);
         *  }
         *  Errors = (int)Client.HttpRequestStatusCode + " - " + Response + " : " + GetConfigErrorMessage("TypeOfVerification") + typeof(T).Name + ".\n";
         *  Errors = Errors + String.Join(";\n", ErrorMessages);
         *  return default(T);
         * }
         */
        //general APIRUN
        public T RunAPI <T>(string endPoint, string subRoute, HttpVerbs method, string body)
        {
            T jsonObjectModel = default(T);

            HeadersDataProcessing();
            Client.Method = method;
            if (body != null)
            {
                Client.Body = body;
            }
            CollectRoute(subRoute);
            var response = Client.Request(Route);

            Response = response;
            if (this.isSuccessRequest())
            {
                try
                {
                    jsonObjectModel = JsonConvert.DeserializeObject <T>(response);
                    JSONData.LoadJSONDataToFile <T>(jsonObjectModel);
                    return(jsonObjectModel);
                }
                catch (Exception e)
                {
                    ErrorMessages.Add(e.Message);
                    Exceptions.Add(e);
                }
                Errors = (int)Client.HttpRequestStatusCode + " - " + Response + " : " + GetConfigErrorMessage("TypeOfVerification") + typeof(T).Name + ".\n";
                Errors = Errors + String.Join(";\n", ErrorMessages);
            }
            return(default(T));
        }
Ejemplo n.º 2
0
        /*
         * [TestMethod]
         * public void GETStates_PositiveTest()
         * {
         *  InitializeActions();
         *
         *  Method = HttpVerbs.Get;
         *  Route = "States";
         *
         *  ExpectedResponseType = typeof(List<StateViewModel>);
         *  ExpectedResponseHttpStatusCode = HttpStatusCode.OK;
         *
         *  Body = null;
         *
         *  quoteActions.ClearURLData();
         *
         *  var result = quoteActions.RunAPI<List<StateViewModel>>(EndPoint, Route, Method, Body);
         *
         *  Verification(quoteActions, result);
         * }
         */
        /*
         * [TestMethod]
         * public void GETGetStateByZip_PositiveTest()
         * {
         *  InitializeActions();
         *
         *  Method = HttpVerbs.Get;
         *  Route = "States";
         *
         *  ExpectedResponseType = typeof(StateViewModel);
         *  ExpectedResponseHttpStatusCode = HttpStatusCode.OK;
         *
         *  Body = null;
         *
         *  quoteActions.ClearURLData();
         *  quoteActions.AddURLData("zipcode", TestsRunParams["TestZipCode"]);
         *
         *  var result = quoteActions.RunAPI<StateViewModel>(EndPoint, Route, Method, Body);
         *
         *  Verification(quoteActions, result);
         * }
         */

        private void QuoteRequestJson()
        {
            QuoteRequest qr = new QuoteRequest();

            qr.Coverage = CoverageType.IndividualSpouse;
            qr.Primary  = new PersonInfo {
                BirthDate = DateTime.Parse("1983/1/1"), Gender = "Male", State = "AZ"
            };
            qr.Spouse = new PersonInfo {
                BirthDate = DateTime.Parse("1987/3/3"), Gender = "Female", State = "AZ"
            };
            JSONData.LoadJSONDataToFile <QuoteRequest>(qr);
        }