Beispiel #1
0
        private void CheckInvalidParse(string input)
        {
            Assert.Throws <FormatException>(() => { RangeConditionHeaderValue.Parse(input); });

            Assert.False(RangeConditionHeaderValue.TryParse(input, out RangeConditionHeaderValue result));
            Assert.Null(result);
        }
        public void Parse()
        {
            var res = RangeConditionHeaderValue.Parse("\"c\"");

            Assert.AreEqual("\"c\"", res.EntityTag.Tag, "#1");
            Assert.IsFalse(res.EntityTag.IsWeak, "#2");
            Assert.IsNull(res.Date, "#3");
        }
Beispiel #3
0
        private void CheckValidParse(string input, RangeConditionHeaderValue expectedResult)
        {
            RangeConditionHeaderValue result = RangeConditionHeaderValue.Parse(input);

            Assert.Equal(expectedResult, result);

            Assert.True(RangeConditionHeaderValue.TryParse(input, out result));
            Assert.Equal(expectedResult, result);
        }
Beispiel #4
0
        public void Parse_Invalid()
        {
            try {
                RangeConditionHeaderValue.Parse(null);
                Assert.Fail("#1");
            } catch (FormatException) {
            }

            try {
                RangeConditionHeaderValue.Parse("  ");
                Assert.Fail("#2");
            } catch (FormatException) {
            }

            try {
                RangeConditionHeaderValue.Parse("a b");
                Assert.Fail("#3");
            } catch (FormatException) {
            }
        }
Beispiel #5
0
        public void Parse()
        {
            var res = RangeConditionHeaderValue.Parse("\"c\"");

            Assert.AreEqual("\"c\"", res.EntityTag.Tag, "#1");
            Assert.IsFalse(res.EntityTag.IsWeak, "#2");
            Assert.IsNull(res.Date, "#3");
            Assert.AreEqual("\"c\"", res.ToString(), "#4");

            res = RangeConditionHeaderValue.Parse("W/\"\"");
            Assert.AreEqual("\"\"", res.EntityTag.Tag, "#11");
            Assert.IsTrue(res.EntityTag.IsWeak, "#12");
            Assert.IsNull(res.Date, "#13");
            Assert.AreEqual("W/\"\"", res.ToString(), "#14");


            res = RangeConditionHeaderValue.Parse("Sun Nov 6 08:49:37 1994");
            Assert.IsNull(res.EntityTag, "#21");
            Assert.AreEqual(new DateTimeOffset(1994, 11, 6, 8, 49, 37, 0, TimeSpan.Zero), res.Date, "#22");
            Assert.AreEqual("Sun, 06 Nov 1994 08:49:37 GMT", res.ToString(), "#23");
        }
Beispiel #6
0
 private void CheckInvalidParse(string input)
 {
     Assert.Throws <FormatException>(() => { RangeConditionHeaderValue.Parse(input); });
 }
        /// <summary>
        /// Insert a request HTTP header
        /// </summary>
        /// <param name="header">A <see cref="System.Net.Http.Headers.HttpRequestHeaders"/> object on wich the request header will be recorded.</param>
        /// <param name="name">The header attribute name.</param>
        /// <param name="value">The header attribute value.</param>
        public void AddRequestHeader(HttpRequestHeaders header, string name, string value)
        {
            if (name.Equals("Authorization", StringComparison.OrdinalIgnoreCase))
            {
                header.Authorization = new AuthenticationHeaderValue(value);
            }

            else if (name.Equals("Cache-Control", StringComparison.OrdinalIgnoreCase))
            {
                header.CacheControl = CacheControlHeaderValue.Parse(value);
            }

            else if (name.Equals("Date", StringComparison.OrdinalIgnoreCase))
            {
                header.Date = DateTimeOffset.Parse(value);
            }

            else if (name.Equals("If-Modified-Since", StringComparison.OrdinalIgnoreCase))
            {
                header.IfModifiedSince = DateTimeOffset.Parse(value);
            }

            else if (name.Equals("If-Range", StringComparison.OrdinalIgnoreCase))
            {
                header.IfRange = RangeConditionHeaderValue.Parse(value);
            }

            else if (name.Equals("If-Unmodified-Since", StringComparison.OrdinalIgnoreCase))
            {
                header.IfUnmodifiedSince = DateTimeOffset.Parse(value);
            }

            else if (name.Equals("Max-Forwards", StringComparison.OrdinalIgnoreCase))
            {
                header.MaxForwards = int.Parse(value);
            }

            else if (name.Equals("Proxy-Authorization", StringComparison.OrdinalIgnoreCase))
            {
                header.ProxyAuthorization = AuthenticationHeaderValue.Parse(value);
            }

            else if (name.Equals("Range", StringComparison.OrdinalIgnoreCase))
            {
                header.Range = RangeHeaderValue.Parse(value);
            }

            else if (name.Equals("Referrer", StringComparison.OrdinalIgnoreCase))
            {
                header.Referrer = new Uri(value);
            }

            else
            {
                try{
                    header.Add(name, value);
                }catch (ArgumentException) {
                    if (header.GetType().GetProperty(name.Replace("-", "")) != null)
                    {
                        header.GetType().GetProperty(name.Replace("-", "")).SetValue(header, value);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
    private void CheckValidParse(string input, RangeConditionHeaderValue expectedResult)
    {
        var result = RangeConditionHeaderValue.Parse(input);

        Assert.Equal(expectedResult, result);
    }
 public void Parse_SetOfInvalidValueStrings_Throws(string input)
 {
     Assert.Throws <FormatException>(() => RangeConditionHeaderValue.Parse(input));
 }