Ejemplo n.º 1
0
        protected static Encoding CreateOrGetSupportedEncoding(
            TextOutputFormatter formatter,
            string encodingAsString,
            bool isDefaultEncoding)
        {
            Encoding encoding = null;

            if (isDefaultEncoding)
            {
                encoding = formatter
                           .SupportedEncodings
                           .First((e) => e.WebName.Equals(encodingAsString, StringComparison.OrdinalIgnoreCase));
            }
            else
            {
                encoding = Encoding.GetEncoding(encodingAsString);
                formatter.SupportedEncodings.Add(encoding);
            }

            return(encoding);
        }
Ejemplo n.º 2
0
        public void GetAcceptCharsetHeaderValues_ReadsHeaderAndParsesValues()
        {
            // Arrange
            const string expectedValue = "expected";

            var formatter = new OverrideEncodingFormatter(encoding: null);
            var context   = new DefaultHttpContext();

            context.Request.Headers[HeaderNames.AcceptCharset] = expectedValue;

            var writerContext = new OutputFormatterWriteContext(
                context,
                new TestHttpResponseStreamWriterFactory().CreateWriter,
                objectType: null,
                @object: null);

            // Act
            var result = TextOutputFormatter.GetAcceptCharsetHeaderValues(writerContext);

            //Assert
            Assert.Equal(expectedValue, Assert.Single(result).Value.Value);
        }