public void FindAllContentTypeMediaTypeThrows()
        {
            Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FindAllContentType(null, new MediaTypeHeaderValue("text/plain")); }, "contents");

            IEnumerable <HttpContent> content = HttpContentCollectionExtensionsTests.CreateContent();

            Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FindAllContentType(content, (MediaTypeHeaderValue)null); }, "contentType");
        }
        /// <summary>
        /// Returns all instances of <see cref="HttpContent"/> in a sequence that has a <see cref="MediaTypeHeaderValue"/> header field
        /// with a <see cref="MediaTypeHeaderValue.MediaType"/> property equal to the provided <paramref name="contentType"/>.
        /// </summary>
        /// <param name="contents">The content to evaluate</param>
        /// <param name="contentType">The media type to look for.</param>
        /// <returns>null if source is empty or if no element matches; otherwise the first <see cref="HttpContent"/> in
        /// the sequence with a matching media type.</returns>
        public static IEnumerable <HttpContent> FindAllContentType(this IEnumerable <HttpContent> contents, string contentType)
        {
            if (String.IsNullOrWhiteSpace(contentType))
            {
                throw new ArgumentNullException("contentType");
            }

            return(HttpContentCollectionExtensions.FindAllContentType(contents, new MediaTypeHeaderValue(contentType)));
        }
        public void FindAllContentTypeString()
        {
            Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FindAllContentType(null, "text/plain"); }, "contents");

            IEnumerable <HttpContent> content = HttpContentCollectionExtensionsTests.CreateContent();

            Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FindAllContentType(content, (string)null); }, "contentType");
            foreach (string empty in TestData.EmptyStrings)
            {
                Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FindAllContentType(content, empty); }, "contentType");
            }
        }
        public void FirstStartOrDefaultThrows()
        {
            Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FirstStartOrDefault(null, "A"); }, "contents");

            IEnumerable <HttpContent> content = HttpContentCollectionExtensionsTests.CreateContent();

            Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FirstStartOrDefault(content, null); }, "start");
            foreach (string empty in TestData.EmptyStrings)
            {
                Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FirstStartOrDefault(content, empty); }, "start");
            }
        }
        public void FirstDispositionTypeThrows()
        {
            Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FirstDispositionType(null, "A"); }, "contents");

            IEnumerable <HttpContent> content = HttpContentCollectionExtensionsTests.CreateContent();

            Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FirstDispositionType(content, null); }, "dispositionType");
            foreach (string empty in TestData.EmptyStrings)
            {
                Assert.ThrowsArgumentNull(() => { HttpContentCollectionExtensions.FirstDispositionType(content, empty); }, "dispositionType");
            }
        }
        /// <summary>
        /// Returns the first <see cref="HttpContent"/> in a sequence that has a <see cref="ContentDispositionHeaderValue"/> header field
        /// with a <see cref="ContentDispositionHeaderValue.Name"/> property equal to <paramref name="dispositionName"/>.
        /// </summary>
        /// <param name="contents">The contents to evaluate</param>
        /// <param name="dispositionName">The disposition name to look for.</param>
        /// <returns>The first <see cref="HttpContent"/> in the sequence with a matching disposition name.</returns>
        public static HttpContent FirstDispositionName(this IEnumerable <HttpContent> contents, string dispositionName)
        {
            if (contents == null)
            {
                throw new ArgumentNullException("contents");
            }

            if (String.IsNullOrWhiteSpace(dispositionName))
            {
                throw new ArgumentNullException("dispositionName");
            }

            return(contents.First((item) =>
            {
                return HttpContentCollectionExtensions.FirstDispositionName(item, dispositionName);
            }));
        }
        /// <summary>
        /// Returns all instances of <see cref="HttpContent"/> in a sequence that has a <see cref="MediaTypeHeaderValue"/> header field
        /// with a <see cref="MediaTypeHeaderValue.MediaType"/> property equal to the provided <paramref name="contentType"/>.
        /// </summary>
        /// <param name="contents">The content to evaluate</param>
        /// <param name="contentType">The media type to look for.</param>
        /// <returns>null if source is empty or if no element matches; otherwise the first <see cref="HttpContent"/> in
        /// the sequence with a matching media type.</returns>
        public static IEnumerable <HttpContent> FindAllContentType(this IEnumerable <HttpContent> contents, MediaTypeHeaderValue contentType)
        {
            if (contents == null)
            {
                throw new ArgumentNullException("contents");
            }

            if (contentType == null)
            {
                throw new ArgumentNullException("contentType");
            }

            return(contents.Where((item) =>
            {
                return HttpContentCollectionExtensions.FindAllContentType(item, contentType);
            }));
        }
        /// <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);
            }));
        }