Пример #1
0
        public void It_allows_changing_json_serialization_entirely()
        {
            var result = new JsonOrJsonpResult();
            result.JsonSerializerFunc = () => @"{""lol"":""indeed"" }";
            result.ExecuteResult(controllerContext.Object);

            content.Should().Be(@"{""lol"":""indeed"" }");
        }
Пример #2
0
        public void It_accepts_changes_in_the_serialization_settings()
        {
            // We create a json or jsonpresult that contains an object with a null property
            var result = new JsonOrJsonpResult { Data = new Foo { } };
            result.ExecuteResult(controllerContext.Object);

            content.Should().Be(@"{}");
            // Clear the content, since we just continue to write in the same context.
            content = string.Empty;

            // Change a setting
            result.SerializationSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include;
            result.ExecuteResult(controllerContext.Object);

            content.Should().Be(@"{""bar"":null}");
        }
Пример #3
0
        public void It_renders_json_correctly()
        {
            var result = new JsonOrJsonpResult { Data = new { foo = "bar" } };
            result.ExecuteResult(controllerContext.Object);

            content.Should().Be(
                @"{""foo"":""bar""}");

            contentType.Should().Be("application/json");
        }
Пример #4
0
        public void It_renders_jsonp_correctly()
        {
            param["callback"] = "func";
            var result = new JsonOrJsonpResult { Data = new { foo = "bar" } };
            result.ExecuteResult(controllerContext.Object);

            content.Should().Be(
                @"func({""foo"":""bar""});");

            contentType.Should().Be("application/javascript");
        }