コード例 #1
0
        private RangeConditionHeaderValue(RangeConditionHeaderValue source)
        {
            Contract.Requires(source != null);

            _entityTag = source._entityTag;
            _date = source._date;
        }
コード例 #2
0
        private RangeConditionHeaderValue(RangeConditionHeaderValue source)
        {
            Debug.Assert(source != null);

            _entityTag = source._entityTag;
            _date      = source._date;
        }
コード例 #3
0
 public void Ctor_DateOverload_MatchExpectation()
 {
     RangeConditionHeaderValue rangeCondition = new RangeConditionHeaderValue(
         new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
     Assert.Null(rangeCondition.EntityTag);
     Assert.Equal(new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero), rangeCondition.Date);
 }
コード例 #4
0
        private RangeConditionHeaderValue(RangeConditionHeaderValue source)
        {
            Debug.Assert(source != null);

            _entityTag = source._entityTag;
            _date = source._date;
        }
コード例 #5
0
        private RangeConditionHeaderValue(RangeConditionHeaderValue source)
        {
            Contract.Requires(source != null);

            this.entityTag = source.entityTag;
            this.date      = source.date;
        }
コード例 #6
0
        public void Ctor_EntityTagStringOverload_MatchExpectation()
        {
            RangeConditionHeaderValue rangeCondition = new RangeConditionHeaderValue("\"y\"");
            Assert.Equal(new EntityTagHeaderValue("\"y\""), rangeCondition.EntityTag);
            Assert.Null(rangeCondition.Date);

            Assert.Throws<ArgumentException>(() => { new RangeConditionHeaderValue((string)null); });
        }
コード例 #7
0
        public void ToString_UseDifferentrangeConditions_AllSerializedCorrectly()
        {
            RangeConditionHeaderValue rangeCondition = new RangeConditionHeaderValue(new EntityTagHeaderValue("\"x\""));
            Assert.Equal("\"x\"", rangeCondition.ToString());

            rangeCondition = new RangeConditionHeaderValue(new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            Assert.Equal("Thu, 15 Jul 2010 12:33:57 GMT", rangeCondition.ToString());
        }
コード例 #8
0
        public void Ctor_EntityTagOverload_MatchExpectation()
        {
            RangeConditionHeaderValue rangeCondition = new RangeConditionHeaderValue(new EntityTagHeaderValue("\"x\""));
            Assert.Equal(new EntityTagHeaderValue("\"x\""), rangeCondition.EntityTag);
            Assert.Null(rangeCondition.Date);

            EntityTagHeaderValue input = null;
            Assert.Throws<ArgumentNullException>(() => { new RangeConditionHeaderValue(input); });
        }
コード例 #9
0
 private void CheckValidParsedValue(string input, int startIndex, RangeConditionHeaderValue expectedResult,
     int expectedIndex)
 {
     HttpHeaderParser parser = GenericHeaderParser.RangeConditionParser;
     object result = null;
     Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
         string.Format("TryParse returned false. Input: '{0}'", input));
     Assert.Equal(expectedIndex, startIndex);
     Assert.Equal(expectedResult, result);
 }
コード例 #10
0
        public static bool TryParse(string input, out RangeConditionHeaderValue parsedValue)
        {
            parsedValue = null;

            var  lexer = new Lexer(input);
            var  t     = lexer.Scan();
            bool is_weak;

            if (t == Token.Type.Token)
            {
                if (lexer.GetStringValue(t) != "W")
                {
                    DateTimeOffset date;
                    if (!Lexer.TryGetDateValue(input, out date))
                    {
                        return(false);
                    }

                    parsedValue = new RangeConditionHeaderValue(date);
                    return(true);
                }

                if (lexer.PeekChar() != '/')
                {
                    return(false);
                }

                is_weak = true;
                lexer.EatChar();
                t = lexer.Scan();
            }
            else
            {
                is_weak = false;
            }

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

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

            parsedValue = new RangeConditionHeaderValue(
                new EntityTagHeaderValue()
            {
                Tag    = lexer.GetStringValue(t),
                IsWeak = is_weak
            });

            return(true);
        }
コード例 #11
0
		public void Equals ()
		{
			var value = new RangeConditionHeaderValue ("\"abc\"");
			Assert.AreEqual (value, new RangeConditionHeaderValue ("\"abc\""), "#1");
			Assert.AreNotEqual (value, new RangeConditionHeaderValue ("\"AbC\""), "#2");

			value = new RangeConditionHeaderValue (DateTimeOffset.MinValue);
			Assert.AreEqual (value, new RangeConditionHeaderValue (DateTimeOffset.MinValue), "#3");
			Assert.AreNotEqual (value, new RangeConditionHeaderValue (DateTimeOffset.MaxValue), "#4");
			Assert.AreNotEqual (value, new RangeConditionHeaderValue ("\"AbC\""), "#5");
		}
コード例 #12
0
        public static bool TryParse(string input, out RangeConditionHeaderValue parsedValue)
        {
            int    index = 0;
            object output;

            parsedValue = null;

            if (GenericHeaderParser.RangeConditionParser.TryParseValue(input, null, ref index, out output))
            {
                parsedValue = (RangeConditionHeaderValue)output;
                return(true);
            }
            return(false);
        }
コード例 #13
0
        public override bool Equals(object obj)
        {
            RangeConditionHeaderValue other = obj as RangeConditionHeaderValue;

            if (other == null)
            {
                return(false);
            }

            if (_entityTag == null)
            {
                return((other._date != null) && (_date.Value == other._date.Value));
            }

            return(_entityTag.Equals(other._entityTag));
        }
コード例 #14
0
        public void GetHashCode_UseSameAndDifferentrangeConditions_SameOrDifferentHashCodes()
        {
            RangeConditionHeaderValue rangeCondition1 = new RangeConditionHeaderValue("\"x\"");
            RangeConditionHeaderValue rangeCondition2 = new RangeConditionHeaderValue(new EntityTagHeaderValue("\"x\""));
            RangeConditionHeaderValue rangeCondition3 = new RangeConditionHeaderValue(
                new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            RangeConditionHeaderValue rangeCondition4 = new RangeConditionHeaderValue(
                new DateTimeOffset(2008, 8, 16, 13, 44, 10, TimeSpan.Zero));
            RangeConditionHeaderValue rangeCondition5 = new RangeConditionHeaderValue(
                new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            RangeConditionHeaderValue rangeCondition6 = new RangeConditionHeaderValue(
                new EntityTagHeaderValue("\"x\"", true));

            Assert.Equal(rangeCondition1.GetHashCode(), rangeCondition2.GetHashCode());
            Assert.NotEqual(rangeCondition1.GetHashCode(), rangeCondition3.GetHashCode());
            Assert.NotEqual(rangeCondition3.GetHashCode(), rangeCondition4.GetHashCode());
            Assert.Equal(rangeCondition3.GetHashCode(), rangeCondition5.GetHashCode());
            Assert.NotEqual(rangeCondition1.GetHashCode(), rangeCondition6.GetHashCode());
        }
コード例 #15
0
		public static bool TryParse (string input, out RangeConditionHeaderValue parsedValue)
		{
			parsedValue = null;

			var lexer = new Lexer (input);
			var t = lexer.Scan ();
			bool is_weak;

			if (t == Token.Type.Token) {
				if (lexer.GetStringValue (t) != "W") {
					DateTimeOffset date;
					if (!Lexer.TryGetDateValue (input, out date))
						return false;

					parsedValue = new RangeConditionHeaderValue (date);
					return true;
				}

				if (lexer.PeekChar () != '/')
					return false;

				is_weak = true;
				lexer.EatChar ();
				t = lexer.Scan ();
			} else {
				is_weak = false;
			}

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

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

			parsedValue = new RangeConditionHeaderValue (
				new EntityTagHeaderValue () {
					Tag = lexer.GetStringValue (t),
					IsWeak = is_weak
				});

			return true;
		}
コード例 #16
0
        public void Equals_UseSameAndDifferentRanges_EqualOrNotEqualNoExceptions()
        {
            RangeConditionHeaderValue rangeCondition1 = new RangeConditionHeaderValue("\"x\"");
            RangeConditionHeaderValue rangeCondition2 = new RangeConditionHeaderValue(new EntityTagHeaderValue("\"x\""));
            RangeConditionHeaderValue rangeCondition3 = new RangeConditionHeaderValue(
                new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            RangeConditionHeaderValue rangeCondition4 = new RangeConditionHeaderValue(
                new DateTimeOffset(2008, 8, 16, 13, 44, 10, TimeSpan.Zero));
            RangeConditionHeaderValue rangeCondition5 = new RangeConditionHeaderValue(
                new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            RangeConditionHeaderValue rangeCondition6 = new RangeConditionHeaderValue(
                new EntityTagHeaderValue("\"x\"", true));

            Assert.False(rangeCondition1.Equals(null), "\"x\" vs. <null>");
            Assert.True(rangeCondition1.Equals(rangeCondition2), "\"x\" vs. \"x\"");
            Assert.False(rangeCondition1.Equals(rangeCondition3), "\"x\" vs. date");
            Assert.False(rangeCondition3.Equals(rangeCondition1), "date vs. \"x\"");
            Assert.False(rangeCondition3.Equals(rangeCondition4), "date vs. different date");
            Assert.True(rangeCondition3.Equals(rangeCondition5), "date vs. date");
            Assert.False(rangeCondition1.Equals(rangeCondition6), "\"x\" vs. W/\"x\"");
        }
コード例 #17
0
 private static void CallGetRangeConditionLength(string input, int startIndex, int expectedLength,
     out RangeConditionHeaderValue result)
 {
     object temp = null;
     Assert.Equal(expectedLength, RangeConditionHeaderValue.GetRangeConditionLength(input, startIndex,
         out temp));
     result = temp as RangeConditionHeaderValue;
 }
コード例 #18
0
		public void Properties ()
		{
			var value = new RangeConditionHeaderValue ("\"b\"");
			Assert.AreEqual (new EntityTagHeaderValue ("\"b\""), value.EntityTag, "#1");
			Assert.IsNull (value.Date, "#2");

			var dto = new DateTimeOffset (20000, new TimeSpan ());
			value = new RangeConditionHeaderValue (dto);
			Assert.AreEqual (null, value.EntityTag, "#3");
			Assert.AreEqual (dto, value.Date, "#4");
		}
コード例 #19
0
        internal static int GetRangeConditionLength(string input, int startIndex, out object parsedValue)
        {
            Debug.Assert(startIndex >= 0);

            parsedValue = null;

            // Make sure we have at least 2 characters
            if (string.IsNullOrEmpty(input) || (startIndex + 1 >= input.Length))
            {
                return(0);
            }

            int current = startIndex;

            // Caller must remove leading whitespace.
            DateTimeOffset       date      = DateTimeOffset.MinValue;
            EntityTagHeaderValue entityTag = null;

            // Entity tags are quoted strings optionally preceded by "W/". By looking at the first two character we
            // can determine whether the string is en entity tag or a date.
            char firstChar  = input[current];
            char secondChar = input[current + 1];

            if ((firstChar == '\"') || (((firstChar == 'w') || (firstChar == 'W')) && (secondChar == '/')))
            {
                // trailing whitespace is removed by GetEntityTagLength()
                int entityTagLength = EntityTagHeaderValue.GetEntityTagLength(input, current, out entityTag);

                if (entityTagLength == 0)
                {
                    return(0);
                }

                current = current + entityTagLength;

                // RangeConditionHeaderValue only allows 1 value. There must be no delimiter/other chars after an
                // entity tag.
                if (current != input.Length)
                {
                    return(0);
                }
            }
            else
            {
                if (!HttpDateParser.TryStringToDate(input.AsSpan(current), out date))
                {
                    return(0);
                }

                // If we got a valid date, then the parser consumed the whole string (incl. trailing whitespace).
                current = input.Length;
            }

            RangeConditionHeaderValue result = new RangeConditionHeaderValue();

            if (entityTag == null)
            {
                result._date = date;
            }
            else
            {
                result._entityTag = entityTag;
            }

            parsedValue = result;
            return(current - startIndex);
        }
コード例 #20
0
        public void Clone_Call_CloneFieldsMatchSourceFields()
        {
            RangeConditionHeaderValue source = new RangeConditionHeaderValue(new EntityTagHeaderValue("\"x\""));
            RangeConditionHeaderValue clone = (RangeConditionHeaderValue)((ICloneable)source).Clone();

            Assert.Equal(source.EntityTag, clone.EntityTag);
            Assert.Null(clone.Date);

            source = new RangeConditionHeaderValue(new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            clone = (RangeConditionHeaderValue)((ICloneable)source).Clone();

            Assert.Null(clone.EntityTag);
            Assert.Equal(source.Date, clone.Date);
        }
コード例 #21
0
 public static bool TryParse(string input, out RangeConditionHeaderValue parsedValue)
 {
 }
コード例 #22
0
        internal static int GetRangeConditionLength(string input, int startIndex, out object parsedValue)
        {
            Contract.Requires(startIndex >= 0);

            parsedValue = null;

            // Make sure we have at least 2 characters
            if (string.IsNullOrEmpty(input) || (startIndex + 1 >= input.Length))
            {
                return 0;
            }

            int current = startIndex;

            // Caller must remove leading whitespaces.
            DateTimeOffset date = DateTimeOffset.MinValue;
            EntityTagHeaderValue entityTag = null;

            // Entity tags are quoted strings optionally preceded by "W/". By looking at the first two character we
            // can determine whether the string is en entity tag or a date.
            char firstChar = input[current];
            char secondChar = input[current + 1];

            if ((firstChar == '\"') || (((firstChar == 'w') || (firstChar == 'W')) && (secondChar == '/')))
            {
                // trailing whitespaces are removed by GetEntityTagLength()
                int entityTagLength = EntityTagHeaderValue.GetEntityTagLength(input, current, out entityTag);

                if (entityTagLength == 0)
                {
                    return 0;
                }

                current = current + entityTagLength;

                // RangeConditionHeaderValue only allows 1 value. There must be no delimiter/other chars after an 
                // entity tag.
                if (current != input.Length)
                {
                    return 0;
                }
            }
            else
            {
                if (!HttpRuleParser.TryStringToDate(input.Substring(current), out date))
                {
                    return 0;
                }

                // If we got a valid date, then the parser consumed the whole string (incl. trailing whitespaces).
                current = input.Length;
            }

            RangeConditionHeaderValue result = new RangeConditionHeaderValue();
            if (entityTag == null)
            {
                result._date = date;
            }
            else
            {
                result._entityTag = entityTag;
            }

            parsedValue = result;
            return current - startIndex;
        }
コード例 #23
0
        public static bool TryParse(string input, out RangeConditionHeaderValue parsedValue)
        {
            int index = 0;
            object output;
            parsedValue = null;

            if (GenericHeaderParser.RangeConditionParser.TryParseValue(input, null, ref index, out output))
            {
                parsedValue = (RangeConditionHeaderValue)output;
                return true;
            }
            return false;
        }
コード例 #24
0
 private void CheckValidParse(string input, RangeConditionHeaderValue expectedResult)
 {
     RangeConditionHeaderValue result = RangeConditionHeaderValue.Parse(input);
     Assert.Equal(expectedResult, result);
 }
コード例 #25
0
 private void CheckValidTryParse(string input, RangeConditionHeaderValue expectedResult)
 {
     RangeConditionHeaderValue result = null;
     Assert.True(RangeConditionHeaderValue.TryParse(input, out result));
     Assert.Equal(expectedResult, result);
 }