public void ParseAdd_AddValues_AllValuesAdded() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.ParseAdd("http://www.example.org/1/"); collection.ParseAdd("http://www.example.org/2/"); collection.ParseAdd("http://www.example.org/3/"); Assert.Equal(3, collection.Count); }
public static void SetUserAgent(this HttpRequestHeaders headers, string userAgent) { HttpHeaderValueCollection <ProductInfoHeaderValue> ua = headers.UserAgent; ua.Clear(); ua.ParseAdd(userAgent); }
public static void SetAcceptLanguage(this HttpRequestHeaders headers, string acceptLanguage) { HttpHeaderValueCollection <StringWithQualityHeaderValue> al = headers.AcceptLanguage; al.Clear(); al.ParseAdd(acceptLanguage); }
public static void SetAccept(this HttpRequestHeaders headers, string accept) { HttpHeaderValueCollection <MediaTypeWithQualityHeaderValue> a = headers.Accept; a.Clear(); a.ParseAdd(accept); }
public void ParseAdd_CallWithNullValue_NothingAdded() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers); collection.ParseAdd(null); Assert.Equal(0, collection.Count); Assert.Equal(string.Empty, collection.ToString()); }
internal static HttpHeaderValueCollection <T> AddDistinct <T>(this HttpHeaderValueCollection <T> headers, Func <T, bool> predicate, string value) where T : class { if (!headers.Any(predicate)) { headers.ParseAdd(value); } return(headers); }
public void ParseAdd_CallWithNullValue_NothingAdded() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownHeader, headers); collection.ParseAdd(null); Assert.False(collection.IsSpecialValueSet); Assert.Equal(0, collection.Count); Assert.Equal(String.Empty, collection.ToString()); }
public static HttpHeaderValueCollection <THeader> Set <THeader>(this HttpHeaderValueCollection <THeader> collection, params string[] values) where THeader : class { foreach (var value in values) { collection.ParseAdd(value); } return(collection); }
public void ParseAdd_UseSpecialValue_Added() { MockHeaders headers = new MockHeaders(); HttpHeaderValueCollection <Uri> collection = new HttpHeaderValueCollection <Uri>(knownUriHeader, headers, specialValue); collection.ParseAdd(specialValue.AbsoluteUri); Assert.True(collection.IsSpecialValueSet); Assert.Equal(specialValue.ToString(), collection.ToString()); }
public void ParseAdd_UseSpecialValue_Added() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.ParseAdd(specialValue.AbsoluteUri); Assert.True(collection.IsSpecialValueSet); Assert.Equal(specialValue.ToString(), collection.ToString()); }
public void ParseAdd_AddValues_AllValuesAdded() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers, specialValue); collection.ParseAdd("http://www.example.org/1/"); collection.ParseAdd("http://www.example.org/2/"); collection.ParseAdd("http://www.example.org/3/"); Assert.Equal(3, collection.Count); }
public void ParseAdd_CallWithNullValue_NothingAdded() { MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri))); HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers); collection.ParseAdd(null); Assert.False(collection.IsSpecialValueSet); Assert.Equal(0, collection.Count); Assert.Equal(String.Empty, collection.ToString()); }
/// <summary> /// Set an HTTP header to a single value, clearing any existing values /// </summary> /// <typeparam name="T"></typeparam> /// <param name="headerValue"></param> /// <param name="value"></param> public static void SetValue <T>(this HttpHeaderValueCollection <T> headerValue, string value) where T : class { headerValue.Clear(); headerValue.ParseAdd(value); }