9
9
using RestSharp . Contrib ;
10
10
using RestSharp . IntegrationTests . Models ;
11
11
using Xunit ;
12
+ using System . IO ;
12
13
13
14
namespace RestSharp . IntegrationTests
14
15
{
@@ -20,7 +21,7 @@ public void Can_Authenticate_With_OAuth()
20
21
const string consumerKey = "" ;
21
22
const string consumerSecret = "" ;
22
23
23
- var baseUrl = new Uri ( "http ://api.twitter.com" ) ;
24
+ var baseUrl = new Uri ( "https ://api.twitter.com" ) ;
24
25
var client = new RestClient ( baseUrl ) ;
25
26
26
27
client . Authenticator = OAuth1Authenticator . ForRequestToken ( consumerKey , consumerSecret ) ;
@@ -85,6 +86,40 @@ public void Can_Authenticate_With_OAuth()
85
86
//Assert.Equal(HttpStatusCode.OK, response.StatusCode);
86
87
}
87
88
89
+ [ Fact ( Skip = "Provide your own consumer key/secret before running" ) ]
90
+ public void Can_Authenticate_Twitter ( )
91
+ {
92
+ // To pass this test, place a file config.json in the RestSharp.IntegrationTests folder
93
+ // with the following content:
94
+ //
95
+ // {
96
+ // "ConsumerKey": "",
97
+ // "ConsumerSecret": "",
98
+ // "AccessToken": "",
99
+ // "AccessSecret": ""
100
+ // }
101
+ //
102
+ // The tokens can be found on the "Keys and Access Tokens" tab on the application
103
+ // management page for your app: https://apps.twitter.com/
104
+
105
+ Assert . True ( File . Exists ( @"..\..\config.json" ) ) ;
106
+
107
+ var config = SimpleJson . DeserializeObject ( File . ReadAllText ( @"..\..\config.json" ) ) as JsonObject ;
108
+
109
+ var client = new RestClient ( "https://api.twitter.com/1.1" ) ;
110
+ client . Authenticator = OAuth1Authenticator . ForProtectedResource (
111
+ ( string ) config [ "ConsumerKey" ] , ( string ) config [ "ConsumerSecret" ] ,
112
+ ( string ) config [ "AccessToken" ] , ( string ) config [ "AccessSecret" ] ) ;
113
+
114
+ var request = new RestRequest ( "account/verify_credentials.json" ) ;
115
+ request . AddParameter ( "include_entities" , "true" , ParameterType . QueryString ) ;
116
+
117
+ var response = client . Execute ( request ) ;
118
+
119
+ Assert . NotNull ( response ) ;
120
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
121
+ }
122
+
88
123
#region Netflix test classes
89
124
90
125
[ XmlRoot ( "queue" ) ]
0 commit comments