Exemple #1
0
        public async Task Test20359(TestContext ctx, HttpServer server,
                                    [AuthenticationType] AuthenticationType authType,
                                    CancellationToken cancellationToken)
        {
            var post = new PostHandler("Post bug #20359", new StringContent("var1=value&var2=value2"));

            post.Method = "POST";

            post.CustomHandler = (request) => {
                ctx.Expect(request.ContentType, Is.EqualTo("application/x-www-form-urlencoded"), "Content-Type");
                return(null);
            };

            var handler = CreateAuthMaybeNone(post, authType);

            using (var operation = new WebClientOperation(server, handler, WebClientOperationType.UploadValuesTaskAsync)) {
                var collection = new NameValueCollection();
                collection.Add("var1", "value");
                collection.Add("var2", "value2");

                operation.Values = collection;

                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
            }
        }
Exemple #2
0
        public async Task Test18750(TestContext ctx, HttpServer server, CancellationToken cancellationToken)
        {
            var post = new PostHandler("First post", new StringContent("var1=value&var2=value2"))
            {
                Flags = RequestFlags.RedirectedAsGet
            };
            var redirect = new RedirectHandler(post, HttpStatusCode.Redirect);

            using (var operation = new WebClientOperation(server, redirect, WebClientOperationType.UploadStringTaskAsync)) {
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
            }

            var secondPost = new PostHandler("Second post", new StringContent("Should send this"));

            using (var operation = new TraditionalOperation(server, secondPost, true)) {
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
            }
        }
Exemple #3
0
        public async Task Test10163(TestContext ctx, HttpServer server,
                                    [AuthenticationType] AuthenticationType authType,
                                    CancellationToken cancellationToken)
        {
            int handlerCalled = 0;
            var post          = new PostHandler("Post bug #10163", HttpContent.HelloWorld);

            post.Method        = "PUT";
            post.CustomHandler = (request) => {
                Interlocked.Increment(ref handlerCalled);
                return(null);
            };

            var handler = CreateAuthMaybeNone(post, authType);

            using (var operation = new WebClientOperation(server, handler, WebClientOperationType.OpenWriteTaskAsync)) {
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
            }

            ctx.Assert(handlerCalled, Is.EqualTo(1), "handler called");
        }