Ejemplo n.º 1
0
        public void TestUploadSingleChunkWithQueryParameters()
        {
            using (var server = new MockResumableUploadServer())
            {
                var stream = new MemoryStream(Encoding.UTF8.GetBytes(UploadTestData));

                server.ExpectRequest(context =>
                {
                    Assert.That(context.Request.Url.AbsolutePath, Is.EqualTo("/testPath/123"));
                    Assert.That(context.Request.QueryString.Count, Is.EqualTo(4));
                    Assert.That(context.Request.QueryString["querya"], Is.EqualTo("QueryValueA"));
                    Assert.That(context.Request.QueryString["queryb"], Is.EqualTo("QueryValueB"));
                    Assert.That(context.Request.QueryString["uploadType"], Is.EqualTo("resumable"));

                    Assert.That(context.Request.Headers["X-Upload-Content-Type"], Is.EqualTo("text/plain"));
                    Assert.That(context.Request.Headers["X-Upload-Content-Length"], Is.EqualTo(stream.Length.ToString()));
                    context.Response.Headers.Add(HttpResponseHeader.Location, server.UploadUri.ToString());
                });

                server.ExpectRequest(context =>
                {
                    Assert.That(context.Request.Url.AbsoluteUri, Is.EqualTo(server.UploadUri.ToString()));
                    var range = String.Format("bytes 0-{0}/{1}", UploadTestData.Length - 1, UploadTestData.Length);
                    Assert.That(context.Request.Headers["Content-Range"], Is.EqualTo(range));
                });

                var upload = new MockResumableWithParameters(server, stream, "text/plain")
                {
                    id     = 123,
                    querya = "QueryValueA",
                    queryb = "QueryValueB",
                };
                upload.Upload();
            }
        }
        public void TestUploadWithQueryAndPathParameters()
        {
            var stream = new MemoryStream(Encoding.UTF8.GetBytes(UploadTestData));

            const int id      = 123;
            var       handler = new SingleChunkMessageHandler()
            {
                PathParameters  = "testPath/" + id.ToString(),
                QueryParameters = "&queryA=valuea&queryB=VALUEB",
                StreamLength    = stream.Length
            };

            using (var service = new MockClientService(new BaseClientService.Initializer()
            {
                HttpClientFactory = new MockHttpClientFactory(handler)
            }))
            {
                var upload = new MockResumableWithParameters(service, "testPath/{id}", "POST", stream, "text/plain")
                {
                    id     = id,
                    querya = "valuea",
                    queryb = "VALUEB",
                };
                upload.Upload();

                Assert.That(handler.Calls, Is.EqualTo(2));
            }
        }
Ejemplo n.º 3
0
        public void TestUploadSingleChunkWithParameters()
        {
            const int id = 123;

            using (var server = new MockResumableUploadServer())
            {
                var stream = new MemoryStream(Encoding.UTF8.GetBytes(UploadTestData));

                server.ExpectRequest(context =>
                {
                    // count should be 2 - uploadType, queryA (and not QueryB)
                    Assert.That(context.Request.QueryString.Count, Is.EqualTo(2));
                    Assert.That(context.Request.QueryString["uploadType"], Is.EqualTo("resumable"));
                    Assert.That(context.Request.QueryString["queryA"], Is.EqualTo("a"));
                    Assert.That(context.Request.Url.AbsolutePath,
                                Is.EqualTo(String.Format("/testPath/{0}", id)));
                    Assert.That(context.Request.Headers["X-Upload-Content-Type"], Is.EqualTo("text/plain"));
                    Assert.That(context.Request.Headers["X-Upload-Content-Length"], Is.EqualTo(stream.Length.ToString()));
                    context.Response.Headers.Add(HttpResponseHeader.Location, server.UploadUri.ToString());
                });

                server.ExpectRequest(context =>
                {
                    Assert.That(context.Request.Url.AbsoluteUri, Is.EqualTo(server.UploadUri.ToString()));
                    var range = String.Format("bytes 0-{0}/{1}", UploadTestData.Length - 1,
                                              UploadTestData.Length);
                    Assert.That(context.Request.Headers["Content-Range"], Is.EqualTo(range));
                });

                var upload = new MockResumableWithParameters(server, stream, "text/plain")
                {
                    id     = id,
                    querya = "a"
                };
                upload.Upload();
            }
        }