public NewtonJsonResult GetAllCats() { string url = ConfigurationManager.AppSettings[SERVICEURL]; var resultJson = new NewtonJsonResult() { Model = string.Empty, StatusCode = HttpStatusCode.OK, JsonRequestBehavior = JsonRequestBehavior.AllowGet, ContentType = "application/json" }; if (!string.IsNullOrWhiteSpace(url)) { try { var webClient = new WebClient(); var content = webClient.DownloadString(url); resultJson.Model = content; } catch (Exception e) { resultJson.StatusCode = HttpStatusCode.NotFound; resultJson.Model = e.Message.ToString(); } } else { resultJson.StatusCode = HttpStatusCode.BadRequest; resultJson.Model = SERVICEURL_MISSING; } return(resultJson); }
protected override JsonResult Json(object data, string contentType, Encoding contentEncoding) { NewtonJsonResult result = new NewtonJsonResult() { Data = data, ContentType = contentType, ContentEncoding = contentEncoding }; return(result); }
protected override JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior) { NewtonJsonResult result = new NewtonJsonResult() { Data = data, ContentType = contentType, ContentEncoding = contentEncoding, JsonRequestBehavior = behavior }; return(result); }
new protected JsonResult Json(object data, JsonRequestBehavior behavior) { var result = new NewtonJsonResult(); result.Data = data; result.JsonRequestBehavior = behavior; if (Request.Browser.Type.StartsWith("IE")) { result.ContentType = "text/plain"; } return(result); }
public void Index() { // Arrange CatsController controller = new CatsController(); // Act NewtonJsonResult result = controller.GetAllCats() as NewtonJsonResult; // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.Model); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }