public HttpResponseMessage BuildStringResult(object obj, ResponseMediaType contentType = ResponseMediaType.JSON) { try { HttpResponseMessage res = Request.CreateResponse(HttpStatusCode.OK); StringBuilder sbResult = new StringBuilder(); if (obj is string) { sbResult.Append(obj); } else { sbResult.Append(Newtonsoft.Json.JsonConvert.SerializeObject(obj)); } string strMediaType = string.IsNullOrWhiteSpace(supportMediaType[contentType]) ? supportMediaType[ResponseMediaType.JSON] : supportMediaType[contentType]; res.Content = new StringContent(sbResult.ToString(), Encoding.UTF8, strMediaType); return(res); } catch (Exception) { throw; } }
public void Init() { chaosSettings = new Mock<IChaosSettings>(); responseMediaType = new ResponseMediaType(); requestMessage = new HttpRequestMessage(HttpMethod.Post, "http://www.test.com"); requestMessage.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); }
public void Init() { _chaosSettings = new Mock <IChaosSettings>(); _responseMediaType = new ResponseMediaType(); _requestMessage = new HttpRequestMessage(HttpMethod.Post, "http://www.test.com"); _requestMessage.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); }