コード例 #1
0
        public Task <ITwitterResult <CreateTokenResponseDTO> > CreateBearerTokenAsync(ICreateBearerTokenParameters parameters, ITwitterRequest request)
        {
            var oAuthQueryGenerator = _oAuthWebRequestGeneratorFactory.Create(request);

            request.Query.Url            = _queryGenerator.GetCreateBearerTokenQuery(parameters);
            request.Query.HttpMethod     = HttpMethod.POST;
            request.TwitterClientHandler = new BearerHttpHandler(oAuthQueryGenerator);
            return(_twitterAccessor.ExecuteRequestAsync <CreateTokenResponseDTO>(request));
        }
コード例 #2
0
        public HttpClient GetHttpClient(ITwitterQuery twitterQuery, ITwitterClientHandler twitterHandler = null)
        {
            var oAuthWebRequestGenerator = _oAuthWebRequestGeneratorFactory.Create();
            var handler = (twitterHandler as TwitterClientHandler) ?? new TwitterClientHandler(oAuthWebRequestGenerator);

            handler.TwitterQuery = twitterQuery;

            var client = new HttpClient(handler)
            {
                Timeout = twitterQuery.Timeout,
            };

            return(client);
        }
コード例 #3
0
        public async Task CreateBearerToken_ReturnsBearerToken()
        {
            // Arrange
            var queryExecutor = CreateAuthQueryExecutor();

            var url                      = TestHelper.GenerateString();
            var request                  = A.Fake <ITwitterRequest>();
            var expectedResult           = A.Fake <ITwitterResult <CreateTokenResponseDTO> >();
            var oAuthWebRequestGenerator = A.Fake <IOAuthWebRequestGenerator>();
            var parameters               = A.Fake <ICreateBearerTokenParameters>();

            A.CallTo(() => _fakeAuthQueryGenerator.GetCreateBearerTokenQuery(parameters)).Returns(url);
            A.CallTo(() => _fakeTwitterAccessor.ExecuteRequest <CreateTokenResponseDTO>(request)).Returns(expectedResult);
            A.CallTo(() => _fakeOAuthWebRequestGeneratorFactory.Create(request)).Returns(oAuthWebRequestGenerator);

            // Act
            var result = await queryExecutor.CreateBearerToken(parameters, request);

            // Assert
            Assert.Equal(result, expectedResult);
            Assert.Equal(request.Query.Url, url);
            Assert.Equal(HttpMethod.POST, request.Query.HttpMethod);
            Assert.True(request.TwitterClientHandler is BearerHttpHandler);
        }