/// <exception cref="InvalidDataException"></exception>
        public IHttpResponse Deserialize(ResponseInfo responseInfo, Stream dataStream)
        {
            var contentType = responseInfo.GetHeaderValueOrNull(HttpHelper.ContentTypeHeader);

            if (string.IsNullOrWhiteSpace(contentType))
            {
                throw new InvalidDataException("Content-Type header missed");
            }

            var boundary = BatchSerializeHelper.GetBoundaryStringOrThrow(contentType);

            var subresponses = new List <IHttpResponse>(_subresponseDeserializers.Length);

            using (var reader = new PeekableStreamReader(dataStream))
            {
                if (reader.ReadUntilFirstNonEmptyLine())
                {
                    while (true)
                    {
                        var subrequest = ParseNextSubresponseFrom(reader, boundary);
                        subresponses.Add(subrequest);
                        if (reader.PeekLine() == BatchSerializeHelper.GetCloseBoundaryString(boundary))
                        {
                            break;
                        }
                    }
                }
            }
            if (subresponses.Count > _subresponseDeserializers.Length)
            {
                throw new InvalidDataException($"Actual and items count is greater than expected. Actual: {subresponses.Count}, expected: {_subresponseDeserializers.Length}");
            }

            return(new HttpResponse <IHttpResponse[]>(responseInfo, subresponses.ToArray()));
        }
        public void GetBoundaryStringOrThrow_SearchesForSpecifiedBoundary(string contentTypeString, string boundary)
        {
            var actual = BatchSerializeHelper.GetBoundaryStringOrThrow(contentTypeString);

            Assert.AreEqual(boundary, actual);
        }
 public void GetBoundaryStringOrThrow_ContentTypeStringIsInvalid_Throws(string contentTypeString)
 {
     Assert.Throws <InvalidDataException>(() => BatchSerializeHelper.GetBoundaryStringOrThrow(contentTypeString));
 }