Skip to content

Commit f7edfc4

Browse files
committed
Added InterfaceImplementationTests unit test.
1 parent b7227ec commit f7edfc4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-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" />

0 commit comments

Comments
 (0)