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)); }
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); }