public void FirstStartThrows() { Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FirstStart(null, "A"); }, "contents"); IEnumerable <HttpContent> content = HttpContentCollectionExtensionsTests.CreateContent(); Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FirstStart(content, null); }, "start"); foreach (string empty in TestData.EmptyStrings) { Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FirstStart(content, empty); }, "start"); } }
/// <summary> /// Returns the first <see cref="HttpContent"/> in a sequence that has a <see cref="ContentDispositionHeaderValue"/> header field /// parameter equal to <paramref name="start"/>. This parameter is typically used in connection with <c>multipart/related</c> /// content (see RFC 2387). /// </summary> /// <param name="contents">The contents to evaluate.</param> /// <param name="start">The start value to look for. A match is found if a <see cref="HttpContent"/> has a <c>Content-ID</c> /// header field with the given value.</param> /// <returns>null if source is empty or if no element matches; otherwise the first <see cref="HttpContent"/> in /// the sequence with a matching value.</returns> public static HttpContent FirstStartOrDefault(this IEnumerable <HttpContent> contents, string start) { if (contents == null) { throw new ArgumentNullException("contents"); } if (String.IsNullOrWhiteSpace(start)) { throw new ArgumentNullException("start"); } return(contents.FirstOrDefault((item) => { return HttpContentCollectionExtensions.FirstStart(item, start); })); }