Skip to content

Commit a50f629

Browse files
author
Devin Rader
committed
Major surgery to make the portable library much more testable
1 parent 3018291 commit a50f629

File tree

60 files changed

+2289
-1228
lines changed

Some content is hidden

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

60 files changed

+2289
-1228
lines changed

.nuget/packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="xunit.runners" version="1.9.2" />
4+
</packages>

RestSharp.IntegrationTests/RestSharp.IntegrationTests.csproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
</Reference>
5454
<Reference Include="System.Data" />
5555
<Reference Include="System.Xml" />
56-
<Reference Include="xunit, Version=1.9.2.1705, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
57-
<SpecificVersion>False</SpecificVersion>
56+
<Reference Include="xunit">
5857
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
5958
</Reference>
6059
<Reference Include="xunit.extensions">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net.Http;
5+
using System.Security.Cryptography.X509Certificates;
6+
using System.Text;
7+
8+
namespace RestSharp.Portable.DesktopHandler
9+
{
10+
public class DesktopMessageHandler : DefaultMessageHandler
11+
{
12+
private WebRequestHandler _instance;
13+
14+
/// <summary>
15+
/// X509CertificateCollection to be sent with request
16+
/// </summary>
17+
public X509CertificateCollection ClientCertificates { get; set; }
18+
19+
public override HttpClientHandler Instance
20+
{
21+
get
22+
{
23+
if (_instance == null)
24+
{
25+
_instance = new WebRequestHandler();
26+
}
27+
return _instance;
28+
}
29+
30+
}
31+
32+
public override void Configure(IHttpRequest request)
33+
{
34+
base.Configure(request);
35+
36+
((WebRequestHandler)this.Instance).ClientCertificates.AddRange(ClientCertificates);
37+
}
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("RestSharp.Portable.DesktopClientHandler")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("RestSharp.Portable.DesktopClientHandler")]
13+
[assembly: AssemblyCopyright("Copyright © 2013")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("eb59a448-77a5-4eff-a293-b20afbcfc7f4")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{0CF2AE77-0328-4697-AB66-619072197B6B}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>RestSharp.Portable.DesktopHandler</RootNamespace>
11+
<AssemblyName>RestSharp.Portable.DesktopHandler</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
15+
<RestorePackages>true</RestorePackages>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Net.Http" />
38+
<Reference Include="System.Net.Http.Extensions">
39+
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net45\System.Net.Http.Extensions.dll</HintPath>
40+
</Reference>
41+
<Reference Include="System.Net.Http.Primitives">
42+
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net45\System.Net.Http.Primitives.dll</HintPath>
43+
</Reference>
44+
<Reference Include="System.Net.Http.WebRequest" />
45+
<Reference Include="System.Xml.Linq" />
46+
<Reference Include="System.Data.DataSetExtensions" />
47+
<Reference Include="Microsoft.CSharp" />
48+
<Reference Include="System.Data" />
49+
<Reference Include="System.Xml" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Compile Include="DesktopMessageHandler.cs" />
53+
<Compile Include="Properties\AssemblyInfo.cs" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<ProjectReference Include="..\RestSharp.Portable\RestSharp.Portable.csproj">
57+
<Project>{ba2352e1-cb07-4795-a2eb-f70720b2bbc9}</Project>
58+
<Name>RestSharp.Portable</Name>
59+
</ProjectReference>
60+
</ItemGroup>
61+
<ItemGroup>
62+
<None Include="packages.config" />
63+
</ItemGroup>
64+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
65+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
66+
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" />
67+
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
68+
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
69+
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
70+
</Target>
71+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
72+
Other similar extension points exist, see Microsoft.Common.targets.
73+
<Target Name="BeforeBuild">
74+
</Target>
75+
<Target Name="AfterBuild">
76+
</Target>
77+
-->
78+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.Bcl" version="1.1.6" targetFramework="net45" />
4+
<package id="Microsoft.Bcl.Build" version="1.0.13" targetFramework="net45" />
5+
<package id="Microsoft.Net.Http" version="2.2.18" targetFramework="net45" />
6+
</packages>

RestSharp.Portable.IntegrationTests/AuthenticationTests.cs

+10-13
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@
66
//using RestSharp.Authenticators;
77
//using RestSharp.Contrib;
88
using RestSharp.IntegrationTests.Helpers;
9-
//using Xunit;
10-
using NUnit;
11-
using NUnit.Framework;
9+
using Xunit;
1210

1311
namespace RestSharp.IntegrationTests
1412
{
15-
//[Trait("Integration", "Authentication Tests")]
16-
[Category("Integration [Authentication Tests]")]
13+
[Trait("Integration", "Authentication Tests")]
1714
public class AuthenticationTests
1815
{
1916
const string baseUrl = "http://localhost:8080/";
2017

21-
//[Fact]
22-
[Test]
18+
[Fact]
19+
2320
public void Does_Not_Pass_Default_Credentials_When_Server_Does_Not_Negotiate()
2421
{
2522
using (SimpleServer.Create(baseUrl, Handlers.Generic<RequestCapturer>()))
@@ -38,7 +35,7 @@ public void Does_Not_Pass_Default_Credentials_When_Server_Does_Not_Negotiate()
3835
}
3936
}
4037

41-
[Test]
38+
4239
public void Pass_Default_Credentials_When_UseDefaultCredentials_Is_True()
4340
{
4441
using (SimpleServer.Create(baseUrl, Handlers.Generic<RequestCapturer>(), AuthenticationSchemes.Negotiate))
@@ -53,13 +50,13 @@ public void Pass_Default_Credentials_When_UseDefaultCredentials_Is_True()
5350

5451
System.Diagnostics.Debug.WriteLine(response.StatusDescription);
5552

56-
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
53+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
5754
Assert.NotNull(RequestCapturer.Headers);
5855
Assert.NotNull(RequestCapturer.Headers["Authorization"]);
5956
}
6057
}
6158

62-
[Test]
59+
6360
public void Does_Not_Pass_Default_Credentials_When_UseDefaultCredentials_Is_False()
6461
{
6562
using (SimpleServer.Create(baseUrl, Handlers.Generic<RequestCapturer>(), AuthenticationSchemes.Negotiate))
@@ -75,12 +72,12 @@ public void Does_Not_Pass_Default_Credentials_When_UseDefaultCredentials_Is_Fals
7572
result.Wait();
7673
var response = result.Result;
7774

78-
Assert.AreEqual(HttpStatusCode.Unauthorized, response.StatusCode);
75+
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
7976
Assert.Null(RequestCapturer.Headers);
8077
}
8178
}
8279

83-
[Test]
80+
8481
public async void Can_Execute_GET_With_Basic_Http_Authentication()
8582
{
8683
using (SimpleServer.Create(baseUrl, Handlers.EchoBasicAuthCredentialsValue()))
@@ -92,7 +89,7 @@ public async void Can_Execute_GET_With_Basic_Http_Authentication()
9289
var response = await client.ExecuteAsync(request);
9390

9491
Assert.NotNull(response.Content);
95-
Assert.AreEqual("testuser|testpassword", response.Content);
92+
Assert.Equal("testuser|testpassword", response.Content);
9693
}
9794
}
9895

RestSharp.Portable.IntegrationTests/CompressionTests.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22
using System.IO.Compression;
33
using System.Net;
44
using RestSharp.IntegrationTests.Helpers;
5-
//using Xunit;
6-
using NUnit;
7-
using NUnit.Framework;
5+
using Xunit;
86

97
namespace RestSharp.IntegrationTests
108
{
11-
//[Trait("Integration", "Compression Tests")]
12-
[Category("Integation [Compression Tests]")]
9+
[Trait("Integration", "Compression Tests")]
1310
public class CompressionTests
1411
{
1512
const string baseUrl = "http://localhost:8080/";
1613

17-
//[Fact]
18-
[Test]
14+
[Fact]
15+
1916
public async void Can_Handle_GET_Request_With_Gzip_Compressed_Response()
2017
{
2118
using(SimpleServer.Create(baseUrl, GzipEchoValue("This is some gzipped content")))
@@ -24,12 +21,12 @@ public async void Can_Handle_GET_Request_With_Gzip_Compressed_Response()
2421
var request = new RestRequest("/compressed");
2522
var response = await client.ExecuteAsync(request);
2623

27-
Assert.AreEqual("This is some gzipped content", response.Content);
24+
Assert.Equal("This is some gzipped content", response.Content);
2825
}
2926
}
3027

31-
//[Fact]
32-
[Test]
28+
[Fact]
29+
3330
public async void Can_Handle_GET_Request_With_Deflate_Compressed_Response()
3431
{
3532
using(SimpleServer.Create(baseUrl, DeflateEchoValue("This is some deflated content")))
@@ -38,7 +35,7 @@ public async void Can_Handle_GET_Request_With_Deflate_Compressed_Response()
3835
var request = new RestRequest("");
3936
var response = await client.ExecuteAsync(request);
4037

41-
Assert.AreEqual("This is some deflated content", response.Content);
38+
Assert.Equal("This is some deflated content", response.Content);
4239
}
4340
}
4441

RestSharp.Portable.IntegrationTests/FileTests.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
using System;
22
using System.IO;
33
using RestSharp.IntegrationTests.Helpers;
4-
//using Xunit;
5-
using NUnit;
4+
using Xunit;
65
using System.Reflection;
76
using System.Threading.Tasks;
8-
using NUnit.Framework;
97

108
namespace RestSharp.IntegrationTests
119
{
12-
//[Trait("Integration", "File Tests")]
13-
[Category("Integation [File Tests]")]
10+
[Trait("Integration", "File Tests")]
1411
public class FileTests
1512
{
1613
const string baseUrl = "http://localhost:8080/";
1714

18-
//[Fact]
19-
[Test]
15+
[Fact]
16+
2017
public async void Can_Handle_Binary_File_Download()
2118
{
2219
using (SimpleServer.Create(baseUrl, Handlers.FileHandler))
@@ -26,12 +23,12 @@ public async void Can_Handle_Binary_File_Download()
2623
var response = await client.DownloadDataAsync(request);
2724

2825
byte[] expected = await LoadSourceFile();
29-
Assert.AreEqual(expected, response);
26+
Assert.Equal(expected, response);
3027
}
3128
}
3229

33-
//[Fact]
34-
[Test]
30+
[Fact]
31+
3532
public async void Can_Write_Response_To_Stream()
3633
{
3734
using (SimpleServer.Create(baseUrl, Handlers.FileHandler))
@@ -47,7 +44,7 @@ public async void Can_Write_Response_To_Stream()
4744
}
4845
var fromTemp = File.ReadAllBytes(tempFile);
4946
var expected = await LoadSourceFile();
50-
Assert.AreEqual(expected, fromTemp);
47+
Assert.Equal(expected, fromTemp);
5148
}
5249
}
5350

0 commit comments

Comments
 (0)