Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        protected override JsonResult Json(object data, string contentType, Encoding contentEncoding)
        {
            NewtonJsonResult result = new NewtonJsonResult()
            {
                Data = data, ContentType = contentType, ContentEncoding = contentEncoding
            };

            return(result);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 5
0
        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);
        }