Skip to content

Commit 0cdf399

Browse files
committed
Merge pull request #656 from issafram/master
Add AddHandler, RemoveHandler, DownloadData and ClearHandlers methods to IRestClient inteface. Add MaxRedirects and FollowRedirects properties to IRestClient interface.
2 parents 46a10a0 + f7edfc4 commit 0cdf399

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace RestSharp.Tests
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Reflection;
7+
using Xunit;
8+
9+
public class InterfaceImplementationTests
10+
{
11+
[Fact]
12+
public void IRestSharp_Has_All_RestSharp_Signatures()
13+
{
14+
// Arrange
15+
var restClientImplementationType = typeof(RestClient);
16+
var restClientInterfaceType = typeof(IRestClient);
17+
var bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
18+
19+
// Act
20+
IEnumerable<string> compareResult = CompareTypes(restClientImplementationType, restClientInterfaceType, bindingFlags);
21+
compareResult.ToList().ForEach(x => Console.WriteLine("Method {0} exists in {1} but not in {2}", x, restClientImplementationType.FullName, restClientInterfaceType.FullName));
22+
23+
// Assert
24+
Assert.Equal(0, compareResult.Count());
25+
}
26+
27+
private static IEnumerable<string> CompareTypes(Type type1, Type type2, BindingFlags bindingFlags)
28+
{
29+
MethodInfo[] typeTMethodInfo = type1.GetMethods(bindingFlags);
30+
MethodInfo[] typeXMethodInfo = type2.GetMethods(bindingFlags);
31+
32+
return typeTMethodInfo.Select(x => x.Name).Except(typeXMethodInfo.Select(x => x.Name));
33+
}
34+
}
35+
}

RestSharp.Tests/RestSharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
</Reference>
8282
</ItemGroup>
8383
<ItemGroup>
84+
<Compile Include="InterfaceImplementationTests.cs" />
8485
<Compile Include="OAuthTests.cs" />
8586
<Compile Include="SampleClasses\EmployeeTracker.cs" />
8687
<Compile Include="SampleClasses\EnumTest.cs" />

RestSharp/IRestClient.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Collections.Generic;
2020
using System.Security.Cryptography.X509Certificates;
2121
using System.Text;
22+
using RestSharp.Deserializers;
2223

2324
#if NET4 || MONODROID || MONOTOUCH || WP8
2425
using System.Threading;
@@ -32,6 +33,8 @@ public interface IRestClient
3233
#if !PocketPC
3334
CookieContainer CookieContainer { get; set; }
3435
#endif
36+
int? MaxRedirects { get; set; }
37+
3538
string UserAgent { get; set; }
3639

3740
int Timeout { get; set; }
@@ -58,6 +61,8 @@ public interface IRestClient
5861
IRestResponse Execute(IRestRequest request);
5962

6063
IRestResponse<T> Execute<T>(IRestRequest request) where T : new();
64+
65+
byte[] DownloadData(IRestRequest request);
6166
#endif
6267

6368
#if FRAMEWORK
@@ -69,6 +74,8 @@ public interface IRestClient
6974
IWebProxy Proxy { get; set; }
7075
#endif
7176

77+
bool FollowRedirects { get; set; }
78+
7279
Uri BuildUri(IRestRequest request);
7380

7481
/// <summary>
@@ -105,6 +112,12 @@ public interface IRestClient
105112
/// <param name="httpMethod">The HTTP method to execute</param>
106113
RestRequestAsyncHandle ExecuteAsyncPost<T>(IRestRequest request, Action<IRestResponse<T>, RestRequestAsyncHandle> callback, string httpMethod);
107114

115+
void AddHandler(string contentType, IDeserializer deserializer);
116+
117+
void RemoveHandler(string contentType);
118+
119+
void ClearHandlers();
120+
108121
#if FRAMEWORK
109122
IRestResponse ExecuteAsGet(IRestRequest request, string httpMethod);
110123

0 commit comments

Comments
 (0)