static bool TryParseElement(Lexer lexer, out TransferCodingWithQualityHeaderValue parsedValue, out Token t)
        {
            parsedValue = null;

            t = lexer.Scan();
            if (t != Token.Type.Token)
            {
                return(false);
            }

            var result = new TransferCodingWithQualityHeaderValue();

            result.value = lexer.GetStringValue(t);

            t = lexer.Scan();

            // Parameters parsing
            if (t == Token.Type.SeparatorSemicolon && (!NameValueHeaderValue.TryParseParameters(lexer, out result.parameters, out t) || t != Token.Type.End))
            {
                return(false);
            }

            parsedValue = result;
            return(true);
        }
 public void Ctor_AddValueAndQuality_QualityParameterAdded()
 {
     TransferCodingWithQualityHeaderValue mediaType = new TransferCodingWithQualityHeaderValue("custom", 0.08);
     Assert.Equal(0.08, mediaType.Quality);
     Assert.Equal("custom", mediaType.Value);
     Assert.Equal(1, mediaType.Parameters.Count);
 }
        public void Parse_SetOfValidValueStrings_ParsedCorrectly()
        {
            TransferCodingWithQualityHeaderValue expected = new TransferCodingWithQualityHeaderValue("custom");
            CheckValidParse("\r\n custom  ", expected);
            CheckValidParse("custom", expected);

            // We don't have to test all possible input strings, since most of the pieces are handled by other parsers.
            // The purpose of this test is to verify that these other parsers are combined correctly to build a 
            // transfer-coding parser.
            expected.Parameters.Add(new NameValueHeaderValue("name", "value"));
            CheckValidParse("\r\n custom ;  name =   value ", expected);
            CheckValidParse("  custom;name=value", expected);
            CheckValidParse("  custom ; name=value", expected);


            TransferCodingWithQualityHeaderValue value1 = new TransferCodingWithQualityHeaderValue("custom1");
            value1.Parameters.Add(new NameValueHeaderValue("param1", "value1"));
            value1.Quality = 1.0;

            CheckValidParse("custom1 ; param1 =value1 ; q= 1.0 ", value1);

            TransferCodingWithQualityHeaderValue value2 = new TransferCodingWithQualityHeaderValue("custom2");
            value2.Parameters.Add(new NameValueHeaderValue("param2", "value2"));
            value2.Quality = 0.5;

            CheckValidParse("\r\n custom2; param2= value2; q =0.5  ", value2);
        }
		public static bool TryParse (string input, out TransferCodingWithQualityHeaderValue parsedValue)
		{
			var lexer = new Lexer (input);
			Token token;
			if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End)
				return true;

			parsedValue = null;
			return false;
		}
        public static bool TryParse(string input, out TransferCodingWithQualityHeaderValue parsedValue)
        {
            var   lexer = new Lexer(input);
            Token token;

            if (TryParseElement(lexer, out parsedValue, out token) && token == Token.Type.End)
            {
                return(true);
            }

            parsedValue = null;
            return(false);
        }
        public static bool TryParse(string input, out TransferCodingWithQualityHeaderValue parsedValue)
        {
            int index = 0;
            object output;
            parsedValue = null;

            if (TransferCodingHeaderParser.SingleValueWithQualityParser.TryParseValue(
                input, null, ref index, out output))
            {
                parsedValue = (TransferCodingWithQualityHeaderValue)output;
                return true;
            }
            return false;
        }
        public static bool TryParse(string input, out TransferCodingWithQualityHeaderValue parsedValue)
        {
            int    index = 0;
            object output;

            parsedValue = null;

            if (TransferCodingHeaderParser.SingleValueWithQualityParser.TryParseValue(
                    input, null, ref index, out output))
            {
                parsedValue = (TransferCodingWithQualityHeaderValue)output;
                return(true);
            }
            return(false);
        }
        public void Equals()
        {
            var tfhv = new TransferCodingWithQualityHeaderValue ("abc");
            Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("abc"), "#1");
            Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("AbC"), "#2");
            Assert.AreNotEqual (tfhv, new TransferCodingWithQualityHeaderValue ("ab"), "#3");
            Assert.AreNotEqual (tfhv, new TransferCodingWithQualityHeaderValue ("ab", 1), "#3");

            tfhv = new TransferCodingWithQualityHeaderValue ("abc", 0.3);
            Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("abc", 0.3), "#4");
            Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("AbC", 0.3), "#5");
            Assert.AreNotEqual (tfhv, new TransferCodingWithQualityHeaderValue ("abc"), "#6");

            var custom_param = new TransferCodingHeaderValue ("abc");
            custom_param.Parameters.Add (new NameValueHeaderValue ("q", "0.3"));
            Assert.AreEqual (tfhv, custom_param, "#7");
        }
		static bool TryParseElement (Lexer lexer, out TransferCodingWithQualityHeaderValue parsedValue, out Token t)
		{
			parsedValue = null;

			t = lexer.Scan ();
			if (t != Token.Type.Token)
				return false;

			var result = new TransferCodingWithQualityHeaderValue ();
			result.value = lexer.GetStringValue (t);

			t = lexer.Scan ();

			// Parameters parsing
			if (t == Token.Type.SeparatorSemicolon && (!NameValueHeaderValue.TryParseParameters (lexer, out result.parameters, out t) || t != Token.Type.End))
				return false;

			parsedValue = result;
			return true;
		}
        public void Clone_Call_CloneFieldsMatchSourceFields()
        {
            // This test just verifies that TransferCodingWithQualityHeaderValue calls the correct base implementation.
            TransferCodingWithQualityHeaderValue source = new TransferCodingWithQualityHeaderValue("custom");
            TransferCodingWithQualityHeaderValue clone = (TransferCodingWithQualityHeaderValue)
                ((ICloneable)source).Clone();
            Assert.Equal(source.Value, clone.Value);
            Assert.Equal(0, clone.Parameters.Count);

            source.Quality = 0.1;
            clone = (TransferCodingWithQualityHeaderValue)((ICloneable)source).Clone();
            Assert.Equal(source.Value, clone.Value);
            Assert.Equal(0.1, clone.Quality);
            Assert.Equal(1, clone.Parameters.Count);

            source.Parameters.Add(new NameValueHeaderValue("custom", "customValue"));
            clone = (TransferCodingWithQualityHeaderValue)((ICloneable)source).Clone();
            Assert.Equal(source.Value, clone.Value);
            Assert.Equal(0.1, clone.Quality);
            Assert.Equal(2, clone.Parameters.Count);
            Assert.Equal("custom", clone.Parameters.ElementAt(1).Name);
            Assert.Equal("customValue", clone.Parameters.ElementAt(1).Value);
        }
 private void CheckValidTryParse(string input, TransferCodingWithQualityHeaderValue expectedResult)
 {
     TransferCodingWithQualityHeaderValue result = null;
     Assert.True(TransferCodingWithQualityHeaderValue.TryParse(input, out result));
     Assert.Equal(expectedResult, result);
 }
 private void CheckValidParse(string input, TransferCodingWithQualityHeaderValue expectedResult)
 {
     TransferCodingWithQualityHeaderValue result = TransferCodingWithQualityHeaderValue.Parse(input);
     Assert.Equal(expectedResult, result);
 }
Example #13
0
 private TransferCodingWithQualityHeaderValue(TransferCodingWithQualityHeaderValue source)
     : base(source)
 {
     // No additional members to initialize here. This constructor is used by Clone().
 }
        public void Properties_Invalid()
        {
            try {
                new TransferCodingWithQualityHeaderValue ("value", 4);
                Assert.Fail ("#1");
            } catch (ArgumentOutOfRangeException) {
            }

            var v = new TransferCodingWithQualityHeaderValue ("value");
            try {
                v.Quality = -1;
                Assert.Fail ("#2");
            } catch (ArgumentOutOfRangeException) {
            }
        }
Example #15
0
        public void TE_ReadAndWriteProperty_ValueMatchesPriorSetValue()
        {
            TransferCodingWithQualityHeaderValue value1 = new TransferCodingWithQualityHeaderValue("custom");
            value1.Quality = 0.5;
            value1.Parameters.Add(new NameValueHeaderValue("name", "value"));
            TransferCodingWithQualityHeaderValue value2 = new TransferCodingWithQualityHeaderValue("custom");
            value2.Quality = 0.3868;

            Assert.Equal(0, headers.TE.Count);

            headers.TE.Add(value1);
            headers.TE.Add(value2);

            Assert.Equal(2, headers.TE.Count);
            Assert.Equal(value1, headers.TE.ElementAt(0));
            Assert.Equal(value2, headers.TE.ElementAt(1));

            headers.TE.Clear();
            Assert.Equal(0, headers.TE.Count);
        }
		public void Quality ()
		{
			var v = new TransferCodingWithQualityHeaderValue ("value", 0.4);
			Assert.AreEqual ("value", v.Value, "#1");
			Assert.AreEqual (0.4, v.Quality, "#2");
		}
		public void Ctor ()
		{
			var v = new TransferCodingWithQualityHeaderValue ("value");
			Assert.AreEqual ("value", v.Value, "#1");
			Assert.IsNull (v.Quality);
		}
Example #18
0
 public static bool TryParse(string input, out TransferCodingWithQualityHeaderValue parsedValue)
 {
 }
 private TransferCodingWithQualityHeaderValue(TransferCodingWithQualityHeaderValue source)
     : base(source)
 {
     // No additional members to initialize here. This constructor is used by Clone().
 }
Example #20
0
        public void TE_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
        {
            headers.TryAddWithoutValidation("TE",
                ",custom1; param1=value1; q=1.0,,\r\n custom2; param2=value2; q=0.5  ,");

            TransferCodingWithQualityHeaderValue value1 = new TransferCodingWithQualityHeaderValue("custom1");
            value1.Parameters.Add(new NameValueHeaderValue("param1", "value1"));
            value1.Quality = 1.0;

            TransferCodingWithQualityHeaderValue value2 = new TransferCodingWithQualityHeaderValue("custom2");
            value2.Parameters.Add(new NameValueHeaderValue("param2", "value2"));
            value2.Quality = 0.5;

            Assert.Equal(value1, headers.TE.ElementAt(0));
            Assert.Equal(value2, headers.TE.ElementAt(1));

            headers.Clear();
            headers.TryAddWithoutValidation("TE", "");
            Assert.False(headers.Contains("TE"), "'TE' header should not be added if it just has empty values.");
        }
        public void Properties()
        {
            var v = new TransferCodingWithQualityHeaderValue ("value", 0.412);
            Assert.AreEqual ("value", v.Value, "#1");
            Assert.AreEqual (0.412, v.Quality, "#2");
            Assert.AreEqual ("0.412", v.Parameters.First ().Value, "#3");

            v.Parameters.Add (new NameValueHeaderValue ("q", "0.2"));
            Assert.AreEqual (0.412, v.Quality, "#4");

            v = new TransferCodingWithQualityHeaderValue ("value");
            v.Parameters.Add (new NameValueHeaderValue ("q", "0.112"));
            Assert.AreEqual (0.112, v.Quality, "#5");

            v = new TransferCodingWithQualityHeaderValue ("value");
            v.Parameters.Add (new NameValueHeaderValue ("q", "test"));
            Assert.IsNull (v.Quality, "#6");
        }