Exemplo n.º 1
0
            public void EnsuresCredentialsAreOfTheRightType()
            {
                var authenticator = new TokenAuthenticator();
                var request = new Request();

                Assert.Throws<InvalidOperationException>(() =>
                    authenticator.Authenticate(request, new Credentials("login", "password")));
            }
            public void EncodesObjectBody()
            {
                var request = new Request { Body = new { test = "value" } };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Equal("{\"test\":\"value\"}", request.Body);
            }
            public void LeavesNullBodyAlone()
            {
                var request = new Request { Body = null };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Null(request.Body);
            }
            public void SetsRequestHeaderForToken()
            {
                var authenticator = new BasicAuthenticator();
                var request = new Request();

                authenticator.Authenticate(request, new Credentials("that-creepy-dude", "Fahrvergnügen"));

                Assert.Contains("Authorization", request.Headers.Keys);
                Assert.Equal("Basic dGhhdC1jcmVlcHktZHVkZTpGYWhydmVyZ27DvGdlbg==", request.Headers["Authorization"]);
            }
            public void LeavesStreamBodyAlone()
            {
                var stream = new MemoryStream();
                var request = new Request { Body = stream };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Same(stream, request.Body);
            }
            public void LeavesStringBodyAlone()
            {
                const string json = "just some string data";
                var request = new Request { Body = json };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Equal(json, request.Body);
            }
            public void SetsRequestAcceptHeader()
            {
                var request = new Request();
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Contains("Accept", request.Headers.Keys);
                Assert.Equal("application/vnd.github.v3+json; charset=utf-8", request.Headers["Accept"]);
            }
Exemplo n.º 8
0
            public void SetsRequestHeaderForToken()
            {
                var authenticator = new TokenAuthenticator();
                var request = new Request();

                authenticator.Authenticate(request, new Credentials("abcda1234a"));

                Assert.Contains("Authorization", request.Headers.Keys);
                Assert.Equal("Token abcda1234a", request.Headers["Authorization"]);
            }
            public void DoesNotChangeExistingAcceptsHeader()
            {
                var request = new Request();
                request.Headers.Add("Accept", "application/vnd.github.manifold-preview; charset=utf-8");
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Contains("Accept", request.Headers.Keys);
                Assert.Equal("application/vnd.github.manifold-preview; charset=utf-8", request.Headers["Accept"]);
            }
Exemplo n.º 10
0
        public async Task<WikiProbeResult> ProbeAsync(Repository repo)
        {
            var repoUri = new Uri(repo.HtmlUrl);
            var baseUri = new Uri(repo.HtmlUrl.Replace(repoUri.AbsolutePath, ""));
            var request = new Request
            {
                Method = HttpMethod.Get,
                BaseAddress = baseUri,
                Endpoint = new Uri(repoUri.AbsolutePath + "/wiki", UriKind.Relative),
                Timeout = TimeSpan.FromSeconds(3),
            };
            request.Headers.Add("User-Agent", productHeader.ToString());

            var ret = await httpClient
                .Send(request, CancellationToken.None)
                .Catch();

            if (ret == null)
                return WikiProbeResult.Failed;
            else if (ret.StatusCode == System.Net.HttpStatusCode.OK)
                return WikiProbeResult.Ok;
            return WikiProbeResult.NotFound;
        }
Exemplo n.º 11
0
            public void InitializesAllRequiredProperties()
            {
                var r = new Request();

                Assert.NotNull(r.Headers);
            }