コード例 #1
0
        public void Parse_NullValue_Throw()
        {
            MediaTypeHeaderParser parser = MediaTypeHeaderParser.SingleValueParser;
            int index = 0;

            Assert.Throws <FormatException>(() => { parser.ParseValue(null, null, ref index); });
        }
コード例 #2
0
        public void Parse_InvalidValue_Throw()
        {
            // This test verifies that Parse() correctly calls TryParse().
            MediaTypeHeaderParser parser = MediaTypeHeaderParser.SingleValueParser;
            int index = 0;

            // only one value allowed.
            Assert.Throws <FormatException>(() => { parser.ParseValue("text/plain; charset=utf-8, next/mediatype", null, ref index); });
        }
コード例 #3
0
        public void Properties_ReadValues_MatchExpectation()
        {
            MediaTypeHeaderParser parser = MediaTypeHeaderParser.SingleValueParser;

            Assert.False(parser.SupportsMultipleValues, "SupportsMultipleValues");
            Assert.Null(parser.Comparer);

            parser = MediaTypeHeaderParser.MultipleValuesParser;
            Assert.True(parser.SupportsMultipleValues, "SupportsMultipleValues");
            Assert.Null(parser.Comparer);
        }
コード例 #4
0
        public void Parse_ValidValue_ReturnsMediaTypeHeaderValue()
        {
            // This test verifies that Parse() correctly calls TryParse().
            MediaTypeHeaderParser parser = MediaTypeHeaderParser.SingleValueParser;
            int index = 2;

            MediaTypeHeaderValue expected = new MediaTypeHeaderValue("text/plain");

            expected.CharSet = "utf-8";
            Assert.True(expected.Equals(parser.ParseValue("   text / plain ; charset = utf-8 ", null, ref index)));
            Assert.Equal(34, index);
        }
コード例 #5
0
        private void CheckInvalidParsedValue(string input, int startIndex, bool supportsMultipleValues)
        {
            MediaTypeHeaderParser parser = null;

            if (supportsMultipleValues)
            {
                parser = MediaTypeHeaderParser.MultipleValuesParser;
            }
            else
            {
                parser = MediaTypeHeaderParser.SingleValueParser;
            }

            object result   = null;
            int    newIndex = startIndex;

            Assert.False(parser.TryParseValue(input, null, ref newIndex, out result),
                         string.Format("TryParse returned true. Input: '{0}', Index: {1}", input, startIndex));
            Assert.Null(result);
            Assert.Equal(startIndex, newIndex);
        }
コード例 #6
0
        private void CheckValidParsedValue(string input, int startIndex, MediaTypeHeaderValue expectedResult,
                                           int expectedIndex, bool supportsMultipleValues)
        {
            MediaTypeHeaderParser parser = null;

            if (supportsMultipleValues)
            {
                parser = MediaTypeHeaderParser.MultipleValuesParser;
            }
            else
            {
                parser = MediaTypeHeaderParser.SingleValueParser;
            }

            object result = null;

            Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
                        string.Format("TryParse returned false. Input: '{0}', Index: {1}", input, startIndex));
            Assert.Equal(expectedIndex, startIndex);
            Assert.Equal(expectedResult, result);
        }