public void TestGetAuthorizationCodeRequestUrl_StandardSettings_Passed()
        {
            var credential = new TestCredential();
            var trSettings = new OAuth2TokenRequestSettings();

            trSettings.RedirectUri = credential.RedirectUrls[0];
            trSettings.Scopes.Add("test-scope1");
            trSettings.Scopes.Add("test-scope2");
            trSettings.State = "state999";

            var    oauth2   = new OAuth2Utility(new DummyNetUtility());
            string url      = oauth2.GetAuthorizationCodeRequestUrl(credential, trSettings);
            string expected = "https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=test-client-id&redirect_uri=http%3A%2F%2Flocalhost%3A1234&scope=test-scope1%20test-scope2&state=state999";

            Assert.Equal(expected, url);
        }
        public void GetAuthorizationCodeRequestUrl_CheckInvalidParams_Passed()
        {
            OAuth2Credential           credential = null;
            OAuth2TokenRequestSettings trSettings = null;
            var oauth2 = new OAuth2Utility(new DummyNetUtility());

            var argNullEx = Assert.Throws <ArgumentNullException>(() => oauth2.GetAuthorizationCodeRequestUrl(credential, trSettings));

            Assert.Equal("credential", argNullEx.ParamName);

            credential = new TestCredential();
            argNullEx  = Assert.Throws <ArgumentNullException>(() => oauth2.GetAuthorizationCodeRequestUrl(credential, trSettings));
            Assert.Equal("requestSettings", argNullEx.ParamName);

            trSettings = new OAuth2TokenRequestSettings();
            var argEx = Assert.Throws <ArgumentException>(() => oauth2.GetAuthorizationCodeRequestUrl(credential, trSettings));

            Assert.True(argEx.Message.Contains("RedirectUri must match one of the values in credential.RedirectUrls"));
        }
        public void TestGetAuthorizationCodeRequestUrl_AllSettingsUsed_Passed()
        {
            var credential = new TestCredential();
            var trSettings = new OAuth2TokenRequestSettings();

            trSettings.IncludeGrantedScopes = true;
            trSettings.IsOnlineAccess       = false;
            trSettings.LoginHint            = "*****@*****.**";
            trSettings.Prompts.Add(OAuth2TokenRequestPrompt.Consent);
            trSettings.Prompts.Add(OAuth2TokenRequestPrompt.SelectAccount);
            trSettings.RedirectUri = credential.RedirectUrls[0];
            trSettings.Scopes.Add("test-scope");
            trSettings.State                = "state999";
            trSettings.IsOnlineAccess       = false;
            trSettings.IncludeGrantedScopes = true;

            var    oauth2   = new OAuth2Utility(new DummyNetUtility());
            string url      = oauth2.GetAuthorizationCodeRequestUrl(credential, trSettings);
            string expected = "https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=test-client-id&redirect_uri=http%3A%2F%2Flocalhost%3A1234&scope=test-scope&state=state999&access_type=offline&prompt=consent%20select_account&[email protected]&include_granted_scopes=true";

            Assert.Equal(expected, url);
        }