Skip to content

Commit c0958f1

Browse files
author
Michael Hallett
committed
more code clean up; brought some style consistency to the project;
1 parent ed5893e commit c0958f1

File tree

104 files changed

+1626
-1171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1626
-1171
lines changed

RestSharp.IntegrationTests/App.config

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
<sources>
55
<source name="System.Net" tracemode="includehex" maxdatasize="1024">
66
<listeners>
7-
<add name="System.Net"/>
7+
<add name="System.Net" />
88
</listeners>
99
</source>
1010
</sources>
1111
<switches>
12-
<add name="System.Net" value="Verbose"/>
12+
<add name="System.Net" value="Verbose" />
1313
</switches>
1414
<sharedListeners>
15-
<add name="System.Net" type="System.Diagnostics.TextWriterTraceListener" initializeData="network.log"/>
15+
<add name="System.Net" type="System.Diagnostics.TextWriterTraceListener" initializeData="network.log" />
1616
</sharedListeners>
17-
<trace autoflush="true"/>
17+
<trace autoflush="true" />
1818
</system.diagnostics>
1919
<startup>
20-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
20+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
2121
</startup>
22-
</configuration>
22+
</configuration>

RestSharp.IntegrationTests/AsyncTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,38 +254,38 @@ public void Can_Timeout_PUT_TaskAsync()
254254
}
255255
}
256256

257-
static void UrlToStatusCodeHandler(HttpListenerContext obj)
257+
private static void UrlToStatusCodeHandler(HttpListenerContext obj)
258258
{
259259
obj.Response.StatusCode = int.Parse(obj.Request.Url.Segments.Last());
260260
}
261261

262262
public class ResponseHandler
263263
{
264-
void error(HttpListenerContext context)
264+
private void error(HttpListenerContext context)
265265
{
266266
context.Response.StatusCode = 400;
267267
context.Response.Headers.Add("Content-Type", "application/xml");
268268
context.Response.OutputStream.WriteStringUtf8(
269-
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
269+
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
270270
<Response>
271271
<Error>
272272
<Message>Not found!</Message>
273273
</Error>
274274
</Response>");
275275
}
276276

277-
void success(HttpListenerContext context)
277+
private void success(HttpListenerContext context)
278278
{
279279
context.Response.OutputStream.WriteStringUtf8(
280-
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
280+
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
281281
<Response>
282282
<Success>
283283
<Message>Works!</Message>
284284
</Success>
285285
</Response>");
286286
}
287287

288-
void timeout(HttpListenerContext context)
288+
private void timeout(HttpListenerContext context)
289289
{
290290
Thread.Sleep(1000);
291291
}

RestSharp.IntegrationTests/AuthenticationTests.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public void Can_Authenticate_With_Basic_Http_Auth()
2121
using (SimpleServer.Create(baseUrl.AbsoluteUri, UsernamePasswordEchoHandler))
2222
{
2323
RestClient client = new RestClient(baseUrl)
24-
{
25-
Authenticator = new HttpBasicAuthenticator("testuser", "testpassword")
26-
};
24+
{
25+
Authenticator = new HttpBasicAuthenticator("testuser", "testpassword")
26+
};
2727
RestRequest request = new RestRequest("test");
2828
IRestResponse response = client.Execute(request);
2929

@@ -34,7 +34,8 @@ public void Can_Authenticate_With_Basic_Http_Auth()
3434
private static void UsernamePasswordEchoHandler(HttpListenerContext context)
3535
{
3636
string header = context.Request.Headers["Authorization"];
37-
string[] parts = Encoding.ASCII.GetString(Convert.FromBase64String(header.Substring("Basic ".Length))).Split(':');
37+
string[] parts = Encoding.ASCII.GetString(Convert.FromBase64String(header.Substring("Basic ".Length)))
38+
.Split(':');
3839

3940
context.Response.OutputStream.WriteStringUtf8(string.Join("|", parts));
4041
}
@@ -44,9 +45,9 @@ public void Can_Authenticate_With_OAuth()
4445
{
4546
Uri baseUrl = new Uri("https://api.twitter.com");
4647
RestClient client = new RestClient(baseUrl)
47-
{
48-
Authenticator = OAuth1Authenticator.ForRequestToken("CONSUMER_KEY", "CONSUMER_SECRET")
49-
};
48+
{
49+
Authenticator = OAuth1Authenticator.ForRequestToken("CONSUMER_KEY", "CONSUMER_SECRET")
50+
};
5051
RestRequest request = new RestRequest("oauth/request_token");
5152
IRestResponse response = client.Execute(request);
5253

@@ -62,7 +63,8 @@ public void Can_Authenticate_With_OAuth()
6263

6364
request = new RestRequest("oauth/authorize?oauth_token=" + oauthToken);
6465

65-
string url = client.BuildUri(request).ToString();
66+
string url = client.BuildUri(request)
67+
.ToString();
6668

6769
Process.Start(url);
6870

RestSharp.IntegrationTests/CompressionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void Can_Handle_Uncompressed_Content()
5454
}
5555
}
5656

57-
static Action<HttpListenerContext> GzipEchoValue(string value)
57+
private static Action<HttpListenerContext> GzipEchoValue(string value)
5858
{
5959
return context =>
6060
{
@@ -67,7 +67,7 @@ static Action<HttpListenerContext> GzipEchoValue(string value)
6767
};
6868
}
6969

70-
static Action<HttpListenerContext> DeflateEchoValue(string value)
70+
private static Action<HttpListenerContext> DeflateEchoValue(string value)
7171
{
7272
return context =>
7373
{

RestSharp.IntegrationTests/Helpers/Handlers.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ public static Action<HttpListenerContext> EchoValue(string value)
3030
/// </summary>
3131
public static void FileHandler(HttpListenerContext context)
3232
{
33-
string pathToFile = Path.Combine(context.Request.Url.Segments.Select(s => s.Replace("/", "")).ToArray());
33+
string pathToFile = Path.Combine(context.Request.Url.Segments.Select(s => s.Replace("/", ""))
34+
.ToArray());
3435

3536
using (StreamReader reader = new StreamReader(pathToFile))
37+
{
3638
reader.BaseStream.CopyTo(context.Response.OutputStream);
39+
}
3740
}
3841

3942
/// <summary>
@@ -73,4 +76,4 @@ public static void FileHandler(HttpListenerContext context)
7376
};
7477
}
7578
}
76-
}
79+
}

RestSharp.IntegrationTests/Helpers/SimpleServer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
public class SimpleServer : IDisposable
99
{
1010
private readonly HttpListener listener;
11+
1112
private readonly Action<HttpListenerContext> handler;
13+
1214
private Thread thread;
1315

1416
private SimpleServer(HttpListener listener, Action<HttpListenerContext> handler)
@@ -20,7 +22,11 @@ private SimpleServer(HttpListener listener, Action<HttpListenerContext> handler)
2022
public static SimpleServer Create(string url, Action<HttpListenerContext> handler,
2123
AuthenticationSchemes authenticationSchemes = AuthenticationSchemes.Anonymous)
2224
{
23-
HttpListener listener = new HttpListener { Prefixes = { url }, AuthenticationSchemes = authenticationSchemes };
25+
HttpListener listener = new HttpListener
26+
{
27+
Prefixes = { url },
28+
AuthenticationSchemes = authenticationSchemes
29+
};
2430
SimpleServer server = new SimpleServer(listener, handler);
2531

2632
server.Start();

RestSharp.IntegrationTests/Models/LinkedINMemberProfile.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace RestSharp.IntegrationTests.Models
1+

2+
namespace RestSharp.IntegrationTests.Models
23
{
34
/// <summary>
45
/// Model for used by the LinkedIN integration tests.

RestSharp.IntegrationTests/MultipartFormDataTests.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ public void MultipartFormData_WithParameterAndFile_Async()
3939
using (SimpleServer.Create(baseUrl, EchoHandler))
4040
{
4141
RestClient client = new RestClient(baseUrl);
42-
RestRequest request = new RestRequest("/", Method.POST) { AlwaysMultipartFormData = true };
43-
DirectoryInfo directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
42+
RestRequest request = new RestRequest("/", Method.POST)
43+
{
44+
AlwaysMultipartFormData = true
45+
};
46+
DirectoryInfo directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory())
47+
.Parent;
4448

4549
if (directoryInfo != null)
4650
{
@@ -53,10 +57,10 @@ public void MultipartFormData_WithParameterAndFile_Async()
5357
request.AddParameter("controlName", "test", "application/json", ParameterType.RequestBody);
5458

5559
Task task = client.ExecuteTaskAsync(request)
56-
.ContinueWith(x =>
57-
{
58-
Assert.AreEqual(this.expectedFileAndBodyRequestContent, x.Result.Content);
59-
});
60+
.ContinueWith(x =>
61+
{
62+
Assert.AreEqual(this.expectedFileAndBodyRequestContent, x.Result.Content);
63+
});
6064

6165
task.Wait();
6266
}
@@ -70,13 +74,16 @@ public void MultipartFormData_WithParameterAndFile()
7074
using (SimpleServer.Create(baseUrl, EchoHandler))
7175
{
7276
RestClient client = new RestClient(baseUrl);
73-
RestRequest request = new RestRequest("/", Method.POST) { AlwaysMultipartFormData = true };
74-
DirectoryInfo directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
77+
RestRequest request = new RestRequest("/", Method.POST)
78+
{
79+
AlwaysMultipartFormData = true
80+
};
81+
DirectoryInfo directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory())
82+
.Parent;
7583

7684
if (directoryInfo != null)
7785
{
78-
string path = Path.Combine(directoryInfo.FullName,
79-
"Assets\\TestFile.txt");
86+
string path = Path.Combine(directoryInfo.FullName, "Assets\\TestFile.txt");
8087

8188
request.AddFile("fileName", path);
8289
}
@@ -96,7 +103,10 @@ public void MultipartFormDataAsync()
96103
using (SimpleServer.Create(baseUrl, EchoHandler))
97104
{
98105
RestClient client = new RestClient(baseUrl);
99-
RestRequest request = new RestRequest("/", Method.POST) { AlwaysMultipartFormData = true };
106+
RestRequest request = new RestRequest("/", Method.POST)
107+
{
108+
AlwaysMultipartFormData = true
109+
};
100110

101111
AddParameters(request);
102112

@@ -116,7 +126,10 @@ public void MultipartFormData()
116126
using (SimpleServer.Create(baseUrl, EchoHandler))
117127
{
118128
RestClient client = new RestClient(baseUrl);
119-
RestRequest request = new RestRequest("/", Method.POST) { AlwaysMultipartFormData = true };
129+
RestRequest request = new RestRequest("/", Method.POST)
130+
{
131+
AlwaysMultipartFormData = true
132+
};
120133

121134
AddParameters(request);
122135

@@ -135,10 +148,10 @@ public void AlwaysMultipartFormData_WithParameter_Execute()
135148
{
136149
RestClient client = new RestClient(baseUrl);
137150
RestRequest request = new RestRequest("?json_route=/posts")
138-
{
139-
AlwaysMultipartFormData = true,
140-
Method = Method.POST,
141-
};
151+
{
152+
AlwaysMultipartFormData = true,
153+
Method = Method.POST,
154+
};
142155

143156
request.AddParameter("title", "test", ParameterType.RequestBody);
144157

@@ -164,7 +177,8 @@ public void AlwaysMultipartFormData_WithParameter_ExecuteTaskAsync()
164177

165178
request.AddParameter("title", "test", ParameterType.RequestBody);
166179

167-
Task task = client.ExecuteTaskAsync(request).ContinueWith(x => { Assert.Null(x.Result.ErrorException); });
180+
Task task = client.ExecuteTaskAsync(request)
181+
.ContinueWith(x => { Assert.Null(x.Result.ErrorException); });
168182

169183
task.Wait();
170184
}
@@ -218,4 +232,4 @@ private static void AddParameters(IRestRequest request)
218232
request.AddParameter("a name with spaces", "somedata");
219233
}
220234
}
221-
}
235+
}

RestSharp.IntegrationTests/NonProtocolExceptionHandlingTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public void Handles_Server_Timeout_Error()
6161
using (SimpleServer.Create(baseUrl, TimeoutHandler))
6262
{
6363
RestClient client = new RestClient(baseUrl);
64-
RestRequest request = new RestRequest("404") { Timeout = 500 };
64+
RestRequest request = new RestRequest("404")
65+
{
66+
Timeout = 500
67+
};
6568
IRestResponse response = client.Execute(request);
6669

6770
Assert.NotNull(response.ErrorException);
@@ -80,7 +83,10 @@ public void Handles_Server_Timeout_Error_Async()
8083
using (SimpleServer.Create(baseUrl, TimeoutHandler))
8184
{
8285
RestClient client = new RestClient(baseUrl);
83-
RestRequest request = new RestRequest("404") { Timeout = 500 };
86+
RestRequest request = new RestRequest("404")
87+
{
88+
Timeout = 500
89+
};
8490
IRestResponse response = null;
8591

8692
client.ExecuteAsync(request, responseCb =>

RestSharp.IntegrationTests/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// General Information about an assembly is controlled through the following
55
// set of attributes. Change these attribute values to modify the information
66
// associated with an assembly.
7+
78
[assembly: AssemblyTitle("RestSharp.IntegrationTests")]
89
[assembly: AssemblyDescription("")]
910
[assembly: AssemblyConfiguration("")]
@@ -16,9 +17,11 @@
1617
// Setting ComVisible to false makes the types in this assembly not visible
1718
// to COM components. If you need to access a type in this assembly from
1819
// COM, set the ComVisible attribute to true on that type.
20+
1921
[assembly: ComVisible(false)]
2022

2123
// The following GUID is for the ID of the typelib if this project is exposed to COM
24+
2225
[assembly: Guid("d1867cb5-67ee-49c2-afd5-3c9f371b9b4c")]
2326

2427
// Version information for an assembly consists of the following four values:
@@ -31,5 +34,6 @@
3134
// You can specify all the values or you can default the Build and Revision Numbers
3235
// by using the '*' as shown below:
3336
// [assembly: AssemblyVersion("1.0.*")]
37+
3438
[assembly: AssemblyVersion("1.0.0.0")]
3539
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)