/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns> /// The object value. /// </returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var enumString = (string)reader.Value; return(ProductStringConverter.GetProduct(enumString)); }
/// <summary> /// Sets the parameters for list usages. /// </summary> /// <param name="request">The request.</param> /// <param name="day">The day.</param> /// <param name="month">The month.</param> /// <param name="year">The year.</param> /// <param name="product">The product.</param> /// <param name="page">The page.</param> /// <param name="pageSize">Size of the page.</param> private void SetParamsForListUsages(IRestRequest request, int?day, int?month, int?year, Product?product, int?page, int?pageSize) { if (day != null) { request.AddQueryParameter("Day", day.ToString()); } if (month != null) { request.AddQueryParameter("Month", month.ToString()); } if (year != null) { request.AddQueryParameter("Year", year.ToString()); } if (product != null) { request.AddQueryParameter("Product", ProductStringConverter.GetProduct(product.Value)); } if (page != null) { request.AddQueryParameter("Page", page.ToString()); } if (pageSize != null) { request.AddQueryParameter("PageSize", pageSize.ToString()); } }
public void UsagesConnectorListUsagesTest() { const string methodName = "listUsages"; using (new MockServer(Port, "Accounts/{accountSid}/Usages.json", (req, rsp, prm) => { // Check http method if (!req.HttpMethod.Equals("GET")) { throw new ArgumentException(); } // Check parameter equality ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "bodyParams", req); ParametersHelper.CheckParametersEquality(TestGroupName, methodName, "queryParams", req); // Define server response var assembly = Assembly.GetExecutingAssembly(); var streamReader = new StreamReader(assembly.GetManifestResourceStream($"AvayaCPaaS.Tests.{ResponseListJsonFileName}")); var json = streamReader.ReadToEnd(); var buffer = Encoding.ASCII.GetBytes(json); rsp.Content(buffer); })) { // Create configuration var configuration = new APIConfiguration(AccountSid, AuthToken); configuration.BaseUrl = $"http://localhost:{Port}/"; // Get json request from json file var jsonRequest = ParametersHelper.GetJsonRequestByGroupAndMethod(TestGroupName, methodName); // Create service var service = new CPaaSService(configuration); // List usages using usages connector var usageList = service.UsagesConnector.ListUsages(Convert.ToInt32(jsonRequest.QueryParameter("Day")), Convert.ToInt32(jsonRequest.QueryParameter("Month")), Convert.ToInt32(jsonRequest.QueryParameter("Year")), ProductStringConverter.GetProduct(Convert.ToInt32(jsonRequest.QueryParameter("Product"))), Convert.ToInt32(jsonRequest.QueryParameter("Page")), Convert.ToInt32(jsonRequest.QueryParameter("PageSize"))); Assert.AreEqual(jsonRequest.QueryParameter("Page"), usageList.Page.ToString()); Assert.AreEqual(jsonRequest.QueryParameter("PageSize"), usageList.Pagesize.ToString()); var usage = usageList.Elements.First(); Assert.AreEqual(ProductStringConverter.GetProduct(Convert.ToInt32(jsonRequest.QueryParameter("Product"))), usage.Product); Assert.AreEqual(Convert.ToInt32(jsonRequest.QueryParameter("Year")), usage.Year); } }
/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param> /// <param name="value">The value.</param> /// <param name="serializer">The calling serializer.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var messageTransportResponseProduct = (Product)value; writer.WriteValue(ProductStringConverter.GetProduct(messageTransportResponseProduct)); }