public void CompleteAuthorize_Returns_If_Already_Authorized()
        {
            const string Pin = "1234567";
            Action<TwitterAsyncResponse<UserIdentifier>> callback = resp => { };
            var oauthAccessTokenUrl = new Uri("https://api.twitter.com/oauth/access_token");
            var oAuthMock = new Mock<IOAuthTwitter>();
            var pinAuth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = "consumerkey",
                    ConsumerSecret = "consumersecret",
                    OAuthToken = "oauthtoken",
                    AccessToken = "accesstoken"
                },
                OAuthTwitter = oAuthMock.Object,
                GoToTwitterAuthorization = link => { }
            };

            pinAuth.CompleteAuthorize(Pin, callback);

            oAuthMock.Verify(oAuth =>
                oAuth.GetAccessTokenAsync(Pin, oauthAccessTokenUrl, "oob", AuthAccessType.NoChange, callback),
                Times.Never());
        }
        public void CompleteAuthorize_Invokes_AuthorizationCompleteCallback()
        {
            var pinAuth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials(),
                OAuthTwitter = new OAuthTwitterMock(),
                GoToTwitterAuthorization = link => { }
            };
            TwitterAsyncResponse<UserIdentifier> twitterResp = null;

            pinAuth.CompleteAuthorize("1234567", resp => twitterResp = resp);

            Assert.NotNull(twitterResp);
        }
        public void CompleteAuthorize_Requires_Pin()
        {
            var pinAuth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials(),
                OAuthTwitter = new OAuthTwitterMock(),
                GoToTwitterAuthorization = link => { }
            };

            var ex = Assert.Throws<ArgumentNullException>(() => pinAuth.CompleteAuthorize(null, resp => { }));

            Assert.Equal("pin", ex.ParamName);
        }
        public void CompleteAuthorize_Gets_Access_Token()
        {
            const string Pin = "1234567";
            Action<TwitterAsyncResponse<UserIdentifier>> callback = resp => { };
            var oauthAccessTokenUrl = new Uri("https://api.twitter.com/oauth/access_token");
            var oAuthMock = new Mock<IOAuthTwitter>();
            var pinAuth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials(),
                OAuthTwitter = oAuthMock.Object,
                GoToTwitterAuthorization = link => { }
            };

            pinAuth.CompleteAuthorize(Pin, callback);

            oAuthMock.Verify(oAuth =>
                oAuth.GetAccessTokenAsync(
                    Pin, oauthAccessTokenUrl, "oob", AuthAccessType.NoChange,
                    It.IsAny<Action<TwitterAsyncResponse<UserIdentifier>>>()),
                Times.Once());
        }