Skip to content

Commit 2a239b0

Browse files
author
Michael Hallett
committed
cleaned up code; removed duplicate code; cleaned up references;
1 parent 6d75367 commit 2a239b0

File tree

99 files changed

+3208
-2910
lines changed

Some content is hidden

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

99 files changed

+3208
-2910
lines changed

.nuget/RestSharp.Build.dll

0 Bytes
Binary file not shown.

.nuget/Signed/RestSharp.Build.dll

0 Bytes
Binary file not shown.

RestSharp.Build/NuSpecUpdateTask.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace RestSharp.Build
99
{
1010
public class NuSpecUpdateTask : Task
1111
{
12-
private Assembly _assembly;
12+
private Assembly assembly;
1313

1414
public string Id { get; private set; }
1515

@@ -27,7 +27,7 @@ public NuSpecUpdateTask() : this(null) { }
2727

2828
public NuSpecUpdateTask(Assembly assembly)
2929
{
30-
this._assembly = assembly;
30+
this.assembly = assembly;
3131
}
3232

3333
public override bool Execute()
@@ -36,18 +36,18 @@ public override bool Execute()
3636
return false;
3737

3838
var path = Path.GetFullPath(this.SourceAssemblyFile);
39-
this._assembly = this._assembly ?? Assembly.LoadFile(path);
39+
this.assembly = this.assembly ?? Assembly.LoadFile(path);
4040

41-
var name = this._assembly.GetName();
41+
var name = this.assembly.GetName();
4242

4343
#if SIGNED
4444
this.Id = name.Name + "Signed";
4545
#else
4646
this.Id = name.Name;
4747
#endif
48-
this.Authors = this.GetAuthors(this._assembly);
49-
this.Description = this.GetDescription(this._assembly);
50-
this.Version = this.GetVersion(this._assembly);
48+
this.Authors = GetAuthors(this.assembly);
49+
this.Description = GetDescription(this.assembly);
50+
this.Version = GetVersion(this.assembly);
5151

5252
this.GenerateComputedSpecFile();
5353

@@ -59,16 +59,16 @@ private void GenerateComputedSpecFile()
5959
var doc = XDocument.Load(this.SpecFile);
6060
var metaNode = doc.Descendants("metadata").First();
6161

62-
this.ReplaceToken(metaNode, "id", this.Id);
63-
this.ReplaceToken(metaNode, "authors", this.Authors);
64-
this.ReplaceToken(metaNode, "owners", this.Authors);
65-
this.ReplaceToken(metaNode, "description", this.Description);
66-
this.ReplaceToken(metaNode, "version", this.Version);
62+
ReplaceToken(metaNode, "id", this.Id);
63+
ReplaceToken(metaNode, "authors", this.Authors);
64+
ReplaceToken(metaNode, "owners", this.Authors);
65+
ReplaceToken(metaNode, "description", this.Description);
66+
ReplaceToken(metaNode, "version", this.Version);
6767

6868
doc.Save(this.SpecFile.Replace(".nuspec", "-computed.nuspec"));
6969
}
7070

71-
private void ReplaceToken(XElement metaNode, XName name, string value)
71+
private static void ReplaceToken(XContainer metaNode, XName name, string value)
7272
{
7373
var node = metaNode.Element(name);
7474
var token = string.Format("${0}$", name.ToString().TrimEnd('s'));
@@ -78,26 +78,26 @@ private void ReplaceToken(XElement metaNode, XName name, string value)
7878
token = "$author$";
7979
}
8080

81-
if (node.Value.Equals(token, StringComparison.OrdinalIgnoreCase))
81+
if (node != null && node.Value.Equals(token, StringComparison.OrdinalIgnoreCase))
8282
{
8383
node.SetValue(value);
8484
}
8585
}
8686

87-
private string GetDescription(Assembly asm)
87+
private static string GetDescription(ICustomAttributeProvider asm)
8888
{
89-
return this.GetAttribute<AssemblyDescriptionAttribute>(asm).Description;
89+
return GetAttribute<AssemblyDescriptionAttribute>(asm).Description;
9090
}
9191

92-
private string GetAuthors(Assembly asm)
92+
private static string GetAuthors(ICustomAttributeProvider asm)
9393
{
94-
return this.GetAttribute<AssemblyCompanyAttribute>(asm).Company;
94+
return GetAttribute<AssemblyCompanyAttribute>(asm).Company;
9595
}
9696

97-
private string GetVersion(Assembly asm)
97+
private static string GetVersion(Assembly asm)
9898
{
9999
var version = asm.GetName().Version.ToString();
100-
var attr = this.GetAttribute<AssemblyInformationalVersionAttribute>(asm);
100+
var attr = GetAttribute<AssemblyInformationalVersionAttribute>(asm);
101101

102102
if (attr != null)
103103
{
@@ -107,7 +107,7 @@ private string GetVersion(Assembly asm)
107107
return version;
108108
}
109109

110-
private TAttr GetAttribute<TAttr>(Assembly asm) where TAttr : Attribute
110+
private static TAttr GetAttribute<TAttr>(ICustomAttributeProvider asm) where TAttr : Attribute
111111
{
112112
var attrs = asm.GetCustomAttributes(typeof(TAttr), false);
113113

RestSharp.IntegrationTests/AsyncRequestBodyTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public void Can_Have_No_Body_Added_To_POST_Request()
4444
{
4545
var client = new RestClient(BASE_URL);
4646
var request = new RestRequest(RequestBodyCapturer.RESOURCE, httpMethod);
47-
4847
var resetEvent = new ManualResetEvent(false);
4948

5049
client.ExecuteAsync(request, response => resetEvent.Set());

RestSharp.IntegrationTests/AsyncTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,22 @@ public void Can_Perform_GET_TaskAsync()
8181
public void Can_Handle_Exception_Thrown_By_OnBeforeDeserialization_Handler()
8282
{
8383
const string baseUrl = "http://localhost:8888/";
84-
const string ExceptionMessage = "Thrown from OnBeforeDeserialization";
84+
const string exceptionMessage = "Thrown from OnBeforeDeserialization";
8585

8686
using (SimpleServer.Create(baseUrl, Handlers.Generic<ResponseHandler>()))
8787
{
8888
var client = new RestClient(baseUrl);
8989
var request = new RestRequest("success");
9090

91-
request.OnBeforeDeserialization += r => { throw new Exception(ExceptionMessage); };
91+
request.OnBeforeDeserialization += r => { throw new Exception(exceptionMessage); };
9292

9393
var task = client.ExecuteTaskAsync<Response>(request);
9494

9595
task.Wait();
9696

9797
var response = task.Result;
9898

99-
Assert.AreEqual(ExceptionMessage, response.ErrorMessage);
99+
Assert.AreEqual(exceptionMessage, response.ErrorMessage);
100100
Assert.AreEqual(ResponseStatus.Error, response.ResponseStatus);
101101
}
102102
}
@@ -217,7 +217,7 @@ public void Can_Timeout_GET_TaskAsync()
217217
var client = new RestClient(baseUrl);
218218
var request = new RestRequest("timeout", Method.GET).AddBody("Body_Content");
219219

220-
//Half the value of ResponseHandler.Timeout
220+
// Half the value of ResponseHandler.Timeout
221221
request.Timeout = 500;
222222

223223
var task = client.ExecuteTaskAsync(request);
@@ -240,7 +240,7 @@ public void Can_Timeout_PUT_TaskAsync()
240240
var client = new RestClient(baseUrl);
241241
var request = new RestRequest("timeout", Method.PUT).AddBody("Body_Content");
242242

243-
//Half the value of ResponseHandler.Timeout
243+
// Half the value of ResponseHandler.Timeout
244244
request.Timeout = 500;
245245

246246
var task = client.ExecuteTaskAsync(request);

RestSharp.IntegrationTests/AuthenticationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Text;
55
using NUnit.Framework;
66
using RestSharp.Authenticators;
7-
using RestSharp.Contrib;
7+
using RestSharp.Extensions.MonoHttp;
88
using RestSharp.IntegrationTests.Helpers;
99

1010
namespace RestSharp.IntegrationTests
@@ -17,7 +17,7 @@ public void Can_Authenticate_With_Basic_Http_Auth()
1717
{
1818
Uri baseUrl = new Uri("http://localhost:8888/");
1919

20-
using(SimpleServer.Create(baseUrl.AbsoluteUri, UsernamePasswordEchoHandler))
20+
using (SimpleServer.Create(baseUrl.AbsoluteUri, UsernamePasswordEchoHandler))
2121
{
2222
var client = new RestClient(baseUrl)
2323
{

RestSharp.IntegrationTests/CompressionTests.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Can_Handle_Gzip_Compressed_Content()
1414
{
1515
Uri baseUrl = new Uri("http://localhost:8888/");
1616

17-
using(SimpleServer.Create(baseUrl.AbsoluteUri, GzipEchoValue("This is some gzipped content")))
17+
using (SimpleServer.Create(baseUrl.AbsoluteUri, GzipEchoValue("This is some gzipped content")))
1818
{
1919
var client = new RestClient(baseUrl);
2020
var request = new RestRequest("");
@@ -29,7 +29,7 @@ public void Can_Handle_Deflate_Compressed_Content()
2929
{
3030
Uri baseUrl = new Uri("http://localhost:8888/");
3131

32-
using(SimpleServer.Create(baseUrl.AbsoluteUri, DeflateEchoValue("This is some deflated content")))
32+
using (SimpleServer.Create(baseUrl.AbsoluteUri, DeflateEchoValue("This is some deflated content")))
3333
{
3434
var client = new RestClient(baseUrl);
3535
var request = new RestRequest("");
@@ -44,7 +44,7 @@ public void Can_Handle_Uncompressed_Content()
4444
{
4545
Uri baseUrl = new Uri("http://localhost:8888/");
4646

47-
using(SimpleServer.Create(baseUrl.AbsoluteUri, Handlers.EchoValue("This is some sample content")))
47+
using (SimpleServer.Create(baseUrl.AbsoluteUri, Handlers.EchoValue("This is some sample content")))
4848
{
4949
var client = new RestClient(baseUrl);
5050
var request = new RestRequest("");
@@ -57,27 +57,27 @@ public void Can_Handle_Uncompressed_Content()
5757
static Action<HttpListenerContext> GzipEchoValue(string value)
5858
{
5959
return context =>
60-
{
61-
context.Response.Headers.Add("Content-encoding", "gzip");
60+
{
61+
context.Response.Headers.Add("Content-encoding", "gzip");
6262

63-
using (var gzip = new GZipStream(context.Response.OutputStream, CompressionMode.Compress, true))
64-
{
65-
gzip.WriteStringUtf8(value);
66-
}
67-
};
63+
using (var gzip = new GZipStream(context.Response.OutputStream, CompressionMode.Compress, true))
64+
{
65+
gzip.WriteStringUtf8(value);
66+
}
67+
};
6868
}
6969

7070
static Action<HttpListenerContext> DeflateEchoValue(string value)
7171
{
7272
return context =>
73-
{
74-
context.Response.Headers.Add("Content-encoding", "deflate");
73+
{
74+
context.Response.Headers.Add("Content-encoding", "deflate");
7575

76-
using (var gzip = new DeflateStream(context.Response.OutputStream, CompressionMode.Compress, true))
77-
{
78-
gzip.WriteStringUtf8(value);
79-
}
80-
};
76+
using (var gzip = new DeflateStream(context.Response.OutputStream, CompressionMode.Compress, true))
77+
{
78+
gzip.WriteStringUtf8(value);
79+
}
80+
};
8181
}
8282
}
8383
}

RestSharp.IntegrationTests/FileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void Handles_Binary_File_Download()
1313
{
1414
Uri baseUrl = new Uri("http://localhost:8888/");
1515

16-
using(SimpleServer.Create(baseUrl.AbsoluteUri, Handlers.FileHandler))
16+
using (SimpleServer.Create(baseUrl.AbsoluteUri, Handlers.FileHandler))
1717
{
1818
var client = new RestClient(baseUrl);
1919
var request = new RestRequest("Assets/Koala.jpg");

RestSharp.IntegrationTests/Helpers/Handlers.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ public static void FileHandler(HttpListenerContext context)
5757
public static Action<HttpListenerContext> Generic<T>() where T : new()
5858
{
5959
return ctx =>
60-
{
61-
var methodName = ctx.Request.Url.Segments.Last();
62-
var method = typeof(T).GetMethod(methodName,
63-
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
60+
{
61+
var methodName = ctx.Request.Url.Segments.Last();
62+
var method = typeof(T).GetMethod(methodName,
63+
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
6464

65-
if (method.IsStatic)
66-
{
67-
method.Invoke(null, new object[] { ctx });
68-
}
69-
else
70-
{
71-
method.Invoke(new T(), new object[] { ctx });
72-
}
73-
};
65+
if (method.IsStatic)
66+
{
67+
method.Invoke(null, new object[] { ctx });
68+
}
69+
else
70+
{
71+
method.Invoke(new T(), new object[] { ctx });
72+
}
73+
};
7474
}
7575
}
7676
}

RestSharp.IntegrationTests/MultipartFormDataTests.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,23 @@ public void MultipartFormData_WithParameterAndFile_Async()
3939
{
4040
var client = new RestClient(baseUrl);
4141
var request = new RestRequest("/", Method.POST) { AlwaysMultipartFormData = true };
42-
string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "Assets\\TestFile.txt");
42+
var directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
43+
44+
if (directoryInfo != null)
45+
{
46+
string path = Path.Combine(directoryInfo.FullName,
47+
"Assets\\TestFile.txt");
48+
49+
request.AddFile("fileName", path);
50+
}
4351

44-
request.AddFile("fileName", path);
4552
request.AddParameter("controlName", "test", "application/json", ParameterType.RequestBody);
4653

47-
var task = client.ExecuteTaskAsync(request).ContinueWith(x =>
48-
{
49-
Assert.AreEqual(this.expectedFileAndBodyRequestContent, x.Result.Content);
50-
});
54+
var task = client.ExecuteTaskAsync(request)
55+
.ContinueWith(x =>
56+
{
57+
Assert.AreEqual(this.expectedFileAndBodyRequestContent, x.Result.Content);
58+
});
5159

5260
task.Wait();
5361
}
@@ -62,9 +70,16 @@ public void MultipartFormData_WithParameterAndFile()
6270
{
6371
var client = new RestClient(baseUrl);
6472
var request = new RestRequest("/", Method.POST) { AlwaysMultipartFormData = true };
65-
string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "Assets\\TestFile.txt");
73+
var directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
74+
75+
if (directoryInfo != null)
76+
{
77+
string path = Path.Combine(directoryInfo.FullName,
78+
"Assets\\TestFile.txt");
79+
80+
request.AddFile("fileName", path);
81+
}
6682

67-
request.AddFile("fileName", path);
6883
request.AddParameter("controlName", "test", "application/json", ParameterType.RequestBody);
6984

7085
var response = client.Execute(request);

0 commit comments

Comments
 (0)