示例#1
0
        public void TestGetBinaryData([Values(true, false)] bool async, [Values(true, false)] bool chunked)
        {
            const int bytes_count = 65536;
            const int chunk_size  = 1024;

            string endpoint = chunked ? "stream-bytes" : "bytes";

            WebRequest request = new WebRequest($"{default_protocol}://{host}/{endpoint}/{bytes_count}")
            {
                Method = HttpMethod.Get,
                AllowInsecureRequests = true,
            };

            if (chunked)
            {
                request.AddParameter("chunk_size", chunk_size.ToString());
            }

            if (async)
            {
                Assert.DoesNotThrowAsync(request.PerformAsync);
            }
            else
            {
                Assert.DoesNotThrow(request.Perform);
            }

            Assert.IsTrue(request.Completed);
            Assert.IsFalse(request.Aborted);

            Assert.AreEqual(bytes_count, request.ResponseStream.Length);
        }
示例#2
0
        public void TestGetBinaryData(bool async, bool chunked)
        {
            const int bytes_count = 65536;
            const int chunk_size  = 1024;

            string endpoint = chunked ? "stream-bytes" : "bytes";

            WebRequest request = new WebRequest($"http://httpbin.org/{endpoint}/{bytes_count}")
            {
                Method = HttpMethod.GET
            };

            if (chunked)
            {
                request.AddParameter("chunk_size", chunk_size.ToString());
            }

            if (async)
            {
                Assert.DoesNotThrowAsync(request.PerformAsync);
            }
            else
            {
                Assert.DoesNotThrow(request.Perform);
            }

            Assert.IsTrue(request.Completed);
            Assert.IsFalse(request.Aborted);

            Assert.AreEqual(bytes_count, request.ResponseStream.Length);
        }