@@ -33,6 +33,21 @@ public class DropboxApiTests
3333 /// </summary>
3434 public static string UserAccessToken ;
3535
36+ /// <summary>
37+ /// The user refresh token.
38+ /// </summary>
39+ public static string UserRefreshToken ;
40+
41+ /// <summary>
42+ /// The app key
43+ /// </summary>
44+ public static string AppKey ;
45+
46+ /// <summary>
47+ /// The app secret
48+ /// </summary>
49+ public static string AppSecret ;
50+
3651 /// <summary>
3752 /// The Dropbox client.
3853 /// </summary>
@@ -53,16 +68,18 @@ public class DropboxApiTests
5368 [ ClassInitialize ]
5469 public static void Initialize ( TestContext context )
5570 {
71+
72+ AppKey = context . Properties [ "appKey" ] . ToString ( ) ;
73+ AppSecret = context . Properties [ "appSecret" ] . ToString ( ) ;
74+
75+ UserRefreshToken = context . Properties [ "userRefreshToken" ] . ToString ( ) ;
5676 UserAccessToken = context . Properties [ "userAccessToken" ] . ToString ( ) ;
5777 Client = new DropboxClient ( UserAccessToken ) ;
5878
5979 var teamToken = context . Properties [ "teamAccessToken" ] . ToString ( ) ;
6080 TeamClient = new DropboxTeamClient ( teamToken ) ;
61-
62- var appKey = context . Properties [ "appKey" ] . ToString ( ) ;
63- var appSecret = context . Properties [ "appSecret" ] . ToString ( ) ;
64-
65- AppClient = new DropboxAppClient ( appKey , appSecret ) ;
81+
82+ AppClient = new DropboxAppClient ( AppKey , AppSecret ) ;
6683 }
6784
6885 [ TestInitialize ]
@@ -91,6 +108,130 @@ public void Cleanup()
91108 }
92109 }
93110
111+ /// <summary>
112+ /// Tests creating a client with only refresh token and
113+ /// ensuring the client refreshed the token before making a call
114+ /// </summary>
115+ /// <returns>The <see cref="Task" /></returns>
116+ [ TestMethod ]
117+ public async Task TestRefreshClient ( )
118+ {
119+ var client = new DropboxClient ( UserRefreshToken , AppKey , AppSecret ) ;
120+ var result = await client . Users . GetCurrentAccountAsync ( ) ;
121+ Assert . IsNotNull ( result . Email ) ;
122+ }
123+
124+ /// <summary>
125+ /// Test get authorization url
126+ /// </summary>
127+ /// <returns>The <see cref="Task"/></returns>
128+ [ TestMethod ]
129+ public async Task TestGetAuthorizationUri ( )
130+ {
131+ string clientId = "myclientid" ;
132+ string [ ] redirectUris = new [ ] { "" , "http://127.0.0.1:52475/" } ;
133+ string [ ] states = new [ ] { "" , "state" } ;
134+ bool [ ] forceReapproves = new [ ] { false , true } ;
135+ bool [ ] disableSignups = new [ ] { false , true } ;
136+ string [ ] requireRoles = new [ ] { "" , "role" } ;
137+ bool [ ] forceReauthentications = new [ ] { false , true } ;
138+ TokenAccessType [ ] tokenAccessTypes = new [ ]
139+ { TokenAccessType . Legacy , TokenAccessType . Offline , TokenAccessType . Online } ;
140+ foreach ( string redirectUri in redirectUris )
141+ {
142+ foreach ( var state in states )
143+ {
144+ foreach ( var forceReapprove in forceReapproves )
145+ {
146+ foreach ( var disableSignup in disableSignups )
147+ {
148+ foreach ( var requireRole in requireRoles )
149+ {
150+ foreach ( var forceReauthentication in forceReauthentications )
151+ {
152+ foreach ( var tokenAccessType in tokenAccessTypes )
153+ {
154+ var authUri = DropboxOAuth2Helper . GetAuthorizeUri ( OAuthResponseType . Code ,
155+ clientId , redirectUri , state , forceReapprove , disableSignup ,
156+ requireRole , forceReauthentication , tokenAccessType ) . ToString ( ) ;
157+
158+ Assert . IsTrue ( authUri . StartsWith ( "https://www.dropbox.com/oauth2/authorize" ) ) ;
159+ Assert . IsTrue ( authUri . Contains ( "response_type=code" ) ) ;
160+ Assert . IsTrue ( authUri . Contains ( "client_id=" + clientId ) ) ;
161+
162+ if ( String . IsNullOrWhiteSpace ( state ) )
163+ {
164+ Assert . IsFalse ( authUri . Contains ( "&state=" ) ) ;
165+ }
166+ else
167+ {
168+ Assert . IsTrue ( authUri . Contains ( "&state=" + state ) ) ;
169+ }
170+
171+ if ( String . IsNullOrWhiteSpace ( redirectUri ) )
172+ {
173+ Assert . IsFalse ( authUri . Contains ( "&redirect_uri=" ) ) ;
174+ }
175+ else
176+ {
177+ Assert . IsTrue ( authUri . Contains ( "&redirect_uri=" + Uri . EscapeDataString ( redirectUri ) ) ) ;
178+ }
179+
180+ if ( forceReapprove )
181+ {
182+ Assert . IsTrue ( authUri . Contains ( "&force_reapprove=true" ) ) ;
183+ }
184+ else
185+ {
186+ Assert . IsFalse ( authUri . Contains ( "&force_reapprove=" ) ) ;
187+ }
188+
189+ if ( disableSignup )
190+ {
191+ Assert . IsTrue ( authUri . Contains ( "&disable_signup=true" ) ) ;
192+ }
193+ else
194+ {
195+ Assert . IsFalse ( authUri . Contains ( "&disable_signup=" ) ) ;
196+ }
197+
198+ if ( String . IsNullOrWhiteSpace ( requireRole ) )
199+ {
200+ Assert . IsFalse ( authUri . Contains ( "&require_role=" ) ) ;
201+ }
202+ else
203+ {
204+ Assert . IsTrue ( authUri . Contains ( "&require_role=" + requireRole ) ) ;
205+ }
206+
207+ if ( forceReauthentication )
208+ {
209+ Assert . IsTrue ( authUri . Contains ( "&force_reauthentication=true" ) ) ;
210+ }
211+ else
212+ {
213+ Assert . IsFalse ( authUri . Contains ( "&force_reauthentication=" ) ) ;
214+ }
215+
216+ if ( tokenAccessType != TokenAccessType . Legacy )
217+ {
218+ Assert . IsTrue ( authUri . Contains ( "&token_access_type=" +
219+ tokenAccessType . ToString ( ) . ToLower ( ) ) ) ;
220+ }
221+ else
222+ {
223+ Assert . IsFalse ( authUri . Contains ( "&token_access_type=" ) ) ;
224+ }
225+ }
226+ }
227+ }
228+ }
229+ }
230+ }
231+ }
232+ }
233+
234+
94235 /// <summary>
95236 /// Test get metadata.
96237 /// </summary>
0 commit comments