public void Serialize_UsesHtmlSafeVersionOfPassedInSettings()
        {
            // Arrange
            var options = new MvcNewtonsoftJsonOptions();
            var helper  = new NewtonsoftJsonHelper(
                Options.Create(options),
                ArrayPool <char> .Shared);
            var obj = new
            {
                FullHtml = "<b>John Doe</b>"
            };
            var serializerSettings = new JsonSerializerSettings
            {
                StringEscapeHandling = StringEscapeHandling.Default,
                ContractResolver     = new DefaultContractResolver
                {
                    NamingStrategy = new SnakeCaseNamingStrategy(),
                }
            };

            var expectedOutput = "{\"full_html\":\"\\u003cb\\u003eJohn Doe\\u003c/b\\u003e\"}";

            // Act
            var result = helper.Serialize(obj, serializerSettings);

            // Assert
            var htmlString = Assert.IsType <HtmlString>(result);

            Assert.Equal(expectedOutput, htmlString.ToString());
        }
        public void Serialize_MaintainsSettingsAndEscapesHtml()
        {
            // Arrange
            var options = new MvcNewtonsoftJsonOptions();

            options.SerializerSettings.ContractResolver = new DefaultContractResolver
            {
                NamingStrategy = new DefaultNamingStrategy(),
            };
            var helper = new NewtonsoftJsonHelper(
                Options.Create(options),
                ArrayPool <char> .Shared);
            var obj = new
            {
                FullHtml = "<b>John Doe</b>"
            };
            var expectedOutput = "{\"FullHtml\":\"\\u003cb\\u003eJohn Doe\\u003c/b\\u003e\"}";

            // Act
            var result = helper.Serialize(obj);

            // Assert
            var htmlString = Assert.IsType <HtmlString>(result);

            Assert.Equal(expectedOutput, htmlString.ToString());
        }
Beispiel #3
0
        public void Serialize_MaintainsSettingsAndEscapesHtml()
        {
            // Arrange
            var settings = new JsonSerializerSettings()
            {
                ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy(),
                },
            };
            var helper = new NewtonsoftJsonHelper(
                new NewtonsoftJsonOutputFormatter(settings, ArrayPool <char> .Shared),
                ArrayPool <char> .Shared);
            var obj = new
            {
                FullHtml = "<b>John Doe</b>"
            };
            var expectedOutput = "{\"fullHtml\":\"\\u003cb\\u003eJohn Doe\\u003c/b\\u003e\"}";

            // Act
            var result = helper.Serialize(obj);

            // Assert
            var htmlString = Assert.IsType <HtmlString>(result);

            Assert.Equal(expectedOutput, htmlString.ToString());
        }
Beispiel #4
0
        protected override IJsonHelper GetJsonHelper()
        {
            var options = new MvcNewtonsoftJsonOptions();
            var helper  = new NewtonsoftJsonHelper(
                Options.Create(options),
                ArrayPool <char> .Shared);

            return(helper);
        }
        public void Serialize_EscapesHtmlByDefault()
        {
            // Arrange
            var options = new MvcNewtonsoftJsonOptions();

            options.SerializerSettings.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii;
            var helper = new NewtonsoftJsonHelper(
                Options.Create(options),
                ArrayPool <char> .Shared);
            var obj = new
            {
                HTML = "<b>John Doe</b>"
            };
            var expectedOutput = "{\"html\":\"\\u003cb\\u003eJohn Doe\\u003c/b\\u003e\"}";

            // Act
            var result = helper.Serialize(obj);

            // Assert
            var htmlString = Assert.IsType <HtmlString>(result);

            Assert.Equal(expectedOutput, htmlString.ToString());
        }
Beispiel #6
0
        public void Serialize_EscapesHtmlByDefault()
        {
            // Arrange
            var settings = new JsonSerializerSettings()
            {
                StringEscapeHandling = StringEscapeHandling.EscapeNonAscii,
            };
            var helper = new NewtonsoftJsonHelper(
                new NewtonsoftJsonOutputFormatter(settings, ArrayPool <char> .Shared),
                ArrayPool <char> .Shared);
            var obj = new
            {
                HTML = "<b>John Doe</b>"
            };
            var expectedOutput = "{\"HTML\":\"\\u003cb\\u003eJohn Doe\\u003c/b\\u003e\"}";

            // Act
            var result = helper.Serialize(obj);

            // Assert
            var htmlString = Assert.IsType <HtmlString>(result);

            Assert.Equal(expectedOutput, htmlString.ToString());
        }