Merge pull request #101 from tmenier/fix_encoding_win1251

fixed #86, fixed net461 dependicies, fixed tests, lowered dependicies…
This commit is contained in:
Todd Menier 2016-06-03 11:15:10 -05:00
commit d5b97ceccb
18 changed files with 473 additions and 467 deletions

View File

@ -2,7 +2,7 @@
<package > <package >
<metadata> <metadata>
<id>Flurl.Http</id> <id>Flurl.Http</id>
<version>1.0.0-beta5</version> <version>1.0.0-beta6-update3</version>
<title>Flurl.Http</title> <title>Flurl.Http</title>
<authors>Todd Menier</authors> <authors>Todd Menier</authors>
<projectUrl>http://tmenier.github.io/Flurl</projectUrl> <projectUrl>http://tmenier.github.io/Flurl</projectUrl>
@ -44,16 +44,23 @@
<dependencies> <dependencies>
<group targetFramework="net45"> <group targetFramework="net45">
<dependency id="Newtonsoft.Json" version="8.0.3" /> <dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="Flurl" version="2.1.0-beta5" /> <dependency id="Flurl" version="2.1.0-beta6" />
</group> </group>
<group targetFramework="net46"> <group targetFramework="net461">
<dependency id="Newtonsoft.Json" version="8.0.3" /> <dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="Flurl" version="2.1.0-beta5" /> <dependency id="Flurl" version="2.1.0-beta6" />
<dependency id="System.Dynamic.Runtime" version="4.0.10" />
<dependency id="System.IO.FileSystem" version="4.0.0" /> <dependency id="System.IO.FileSystem" version="4.0.0" />
</group> <dependency id="System.Net.Http" version="4.0.0" />
<dependency id="System.Runtime.Extensions" version="4.0.10" />
<dependency id="System.Runtime.Serialization.Primitives" version="4.0.10" />
<dependency id="System.Text.Encoding.CodePages" version="4.0.0" />
<dependency id="System.Text.RegularExpressions" version="4.0.10" />
<dependency id="System.Threading" version="4.0.10" />
</group>
<group targetFramework="monoandroid"> <group targetFramework="monoandroid">
<dependency id="Newtonsoft.Json" version="8.0.3" /> <dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="Flurl" version="2.1.0-beta5" /> <dependency id="Flurl" version="2.1.0-beta6" />
<dependency id="Microsoft.Bcl.Async" version="1.0.168" /> <dependency id="Microsoft.Bcl.Async" version="1.0.168" />
<dependency id="Microsoft.Bcl.Build" version="1.0.21" /> <dependency id="Microsoft.Bcl.Build" version="1.0.21" />
<dependency id="Microsoft.Net.Http" version="2.2.29" /> <dependency id="Microsoft.Net.Http" version="2.2.29" />
@ -61,7 +68,7 @@
</group> </group>
<group targetFramework="monotouch"> <group targetFramework="monotouch">
<dependency id="Newtonsoft.Json" version="8.0.3" /> <dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="Flurl" version="2.1.0-beta5" /> <dependency id="Flurl" version="2.1.0-beta6" />
<dependency id="Microsoft.Bcl.Async" version="1.0.168" /> <dependency id="Microsoft.Bcl.Async" version="1.0.168" />
<dependency id="Microsoft.Bcl.Build" version="1.0.21" /> <dependency id="Microsoft.Bcl.Build" version="1.0.21" />
<dependency id="Microsoft.Net.Http" version="2.2.29" /> <dependency id="Microsoft.Net.Http" version="2.2.29" />
@ -69,7 +76,7 @@
</group> </group>
<group targetFramework="xamarin.ios"> <group targetFramework="xamarin.ios">
<dependency id="Newtonsoft.Json" version="8.0.3" /> <dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="Flurl" version="2.1.0-beta5" /> <dependency id="Flurl" version="2.1.0-beta6" />
<dependency id="Microsoft.Bcl.Async" version="1.0.168" /> <dependency id="Microsoft.Bcl.Async" version="1.0.168" />
<dependency id="Microsoft.Bcl.Build" version="1.0.21" /> <dependency id="Microsoft.Bcl.Build" version="1.0.21" />
<dependency id="Microsoft.Net.Http" version="2.2.29" /> <dependency id="Microsoft.Net.Http" version="2.2.29" />
@ -77,7 +84,7 @@
</group> </group>
<group targetFramework="xamarin.mac"> <group targetFramework="xamarin.mac">
<dependency id="Newtonsoft.Json" version="8.0.3" /> <dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="Flurl" version="2.1.0-beta5" /> <dependency id="Flurl" version="2.1.0-beta6" />
<dependency id="Microsoft.Bcl.Async" version="1.0.168" /> <dependency id="Microsoft.Bcl.Async" version="1.0.168" />
<dependency id="Microsoft.Bcl.Build" version="1.0.21" /> <dependency id="Microsoft.Bcl.Build" version="1.0.21" />
<dependency id="Microsoft.Net.Http" version="2.2.29" /> <dependency id="Microsoft.Net.Http" version="2.2.29" />
@ -85,7 +92,7 @@
</group> </group>
<group targetFramework="portable45-net45+win8+wpa81"> <group targetFramework="portable45-net45+win8+wpa81">
<dependency id="Newtonsoft.Json" version="8.0.3" /> <dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="Flurl" version="2.1.0-beta5" /> <dependency id="Flurl" version="2.1.0-beta6" />
<dependency id="Microsoft.Bcl.Async" version="1.0.168" /> <dependency id="Microsoft.Bcl.Async" version="1.0.168" />
<dependency id="Microsoft.Bcl.Build" version="1.0.21" /> <dependency id="Microsoft.Bcl.Build" version="1.0.21" />
<dependency id="Microsoft.Net.Http" version="2.2.29" /> <dependency id="Microsoft.Net.Http" version="2.2.29" />
@ -93,18 +100,19 @@
</group> </group>
<group targetFramework="uap10"> <group targetFramework="uap10">
<dependency id="Newtonsoft.Json" version="8.0.3" /> <dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="Flurl" version="2.1.0-beta5" /> <dependency id="Flurl" version="2.1.0-beta6" />
</group> </group>
<group targetFramework="netstandard1.4"> <group targetFramework="netstandard1.4">
<dependency id="Newtonsoft.Json" version="8.0.3" /> <dependency id="Newtonsoft.Json" version="8.0.3" />
<dependency id="Flurl" version="2.1.0-beta5" /> <dependency id="Flurl" version="2.1.0-beta6" />
<dependency id="System.Dynamic.Runtime" version="4.0.11-rc2-24027" /> <dependency id="System.Dynamic.Runtime" version="4.0.10" />
<dependency id="System.IO.FileSystem" version="4.0.1-rc2-24027" /> <dependency id="System.IO.FileSystem" version="4.0.0" />
<dependency id="System.Net.Http" version="4.0.1-rc2-24027" /> <dependency id="System.Net.Http" version="4.0.0" />
<dependency id="System.Runtime.Extensions" version="4.1.0-rc2-24027" /> <dependency id="System.Runtime.Extensions" version="4.0.10" />
<dependency id="System.Runtime.Serialization.Primitives" version="4.1.1-rc2-24027" /> <dependency id="System.Runtime.Serialization.Primitives" version="4.0.10" />
<dependency id="System.Text.RegularExpressions" version="4.0.12-rc2-24027" /> <dependency id="System.Text.Encoding.CodePages" version="4.0.0" />
<dependency id="System.Threading" version="4.0.11-rc2-24027" /> <dependency id="System.Text.RegularExpressions" version="4.0.10" />
<dependency id="System.Threading" version="4.0.10" />
</group> </group>
</dependencies> </dependencies>
</metadata> </metadata>

View File

@ -2,7 +2,7 @@
<package > <package >
<metadata> <metadata>
<id>Flurl</id> <id>Flurl</id>
<version>2.1.0-beta5</version> <version>2.1.0-beta6</version>
<title>Flurl</title> <title>Flurl</title>
<authors>Todd Menier</authors> <authors>Todd Menier</authors>
<projectUrl>http://tmenier.github.io/Flurl</projectUrl> <projectUrl>http://tmenier.github.io/Flurl</projectUrl>
@ -45,9 +45,8 @@
<group targetFramework="uap10" /> <group targetFramework="uap10" />
<group targetFramework="portable40-net40+win8+wpa81" /> <group targetFramework="portable40-net40+win8+wpa81" />
<group targetFramework="netstandard1.4"> <group targetFramework="netstandard1.4">
<dependency id="System.Globalization" version= "4.0.11-rc2-24027" /> <dependency id="System.Linq" version="4.0.0" />
<dependency id="System.Linq" version="4.1.0-rc2-24027" /> <dependency id="System.Reflection.TypeExtensions" version="4.0.0" />
<dependency id="System.Reflection.TypeExtensions" version="4.1.0-rc2-24027" />
</group> </group>
</dependencies> </dependencies>
</metadata> </metadata>

View File

@ -37,11 +37,11 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Flurl, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Flurl, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.2.1.0-beta5\lib\portable40-net40+win8+wpa81\Flurl.dll</HintPath> <HintPath>..\..\packages\Flurl.2.1.0-beta6\lib\portable40-net40+win8+wpa81\Flurl.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Flurl.Http, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Flurl.Http, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.1.0.0-beta5\lib\portable45-net45+win8+wpa81\Flurl.Http.dll</HintPath> <HintPath>..\..\packages\Flurl.Http.1.0.0-beta6-update3\lib\portable45-net45+win8+wpa81\Flurl.Http.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Flurl" version="2.1.0-beta5" targetFramework="net45" /> <package id="Flurl" version="2.1.0-beta6" targetFramework="net45" />
<package id="Flurl.Http" version="1.0.0-beta5" targetFramework="net45" /> <package id="Flurl.Http" version="1.0.0-beta6-update3" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" /> <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" /> <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" /> <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" />

View File

@ -1,22 +1,3 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -35,11 +35,11 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Flurl, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Flurl, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.2.1.0-beta5\lib\netstandard1.4\Flurl.dll</HintPath> <HintPath>..\..\packages\Flurl.2.1.0-beta6\lib\netstandard1.4\Flurl.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Flurl.Http, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Flurl.Http, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.1.0.0-beta5\lib\netstandard1.4\Flurl.Http.dll</HintPath> <HintPath>..\..\packages\Flurl.Http.1.0.0-beta6-update3\lib\netstandard1.4\Flurl.Http.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
@ -56,18 +56,19 @@
<HintPath>..\..\packages\System.IO.FileSystem.Primitives.4.0.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath> <HintPath>..\..\packages\System.IO.FileSystem.Primitives.4.0.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Text.Encoding.CodePages, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Text.Encoding.CodePages.4.0.0\lib\dotnet\System.Text.Encoding.CodePages.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Net461Tester.cs" /> <Compile Include="Net461Tester.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config"> <None Include="app.config" />
<SubType>Designer</SubType> <None Include="packages.config" />
</None>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup> </ItemGroup>
<Import Project="..\PackageTester.Shared\PackageTester.Shared.projitems" Label="Shared" /> <Import Project="..\PackageTester.Shared\PackageTester.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -1,13 +1,25 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Flurl" version="2.1.0-beta5" targetFramework="net461" /> <package id="Flurl" version="2.1.0-beta6" targetFramework="net461" />
<package id="Flurl.Http" version="1.0.0-beta5" targetFramework="net461" /> <package id="Flurl.Http" version="1.0.0-beta6-update3" targetFramework="net461" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net461" /> <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net461" />
<package id="System.Collections" version="4.0.10" targetFramework="net461" />
<package id="System.Dynamic.Runtime" version="4.0.10" targetFramework="net461" />
<package id="System.Globalization" version="4.0.10" targetFramework="net461" />
<package id="System.IO" version="4.0.10" targetFramework="net461" /> <package id="System.IO" version="4.0.10" targetFramework="net461" />
<package id="System.IO.FileSystem" version="4.0.0" targetFramework="net461" /> <package id="System.IO.FileSystem" version="4.0.0" targetFramework="net461" />
<package id="System.IO.FileSystem.Primitives" version="4.0.0" targetFramework="net461" /> <package id="System.IO.FileSystem.Primitives" version="4.0.0" targetFramework="net461" />
<package id="System.Net.Http" version="4.0.0" targetFramework="net461" />
<package id="System.Reflection" version="4.0.10" targetFramework="net461" />
<package id="System.Resources.ResourceManager" version="4.0.0" targetFramework="net461" />
<package id="System.Runtime" version="4.0.20" targetFramework="net461" /> <package id="System.Runtime" version="4.0.20" targetFramework="net461" />
<package id="System.Runtime.Extensions" version="4.0.10" targetFramework="net461" />
<package id="System.Runtime.Handles" version="4.0.0" targetFramework="net461" /> <package id="System.Runtime.Handles" version="4.0.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices" version="4.0.20" targetFramework="net461" />
<package id="System.Runtime.Serialization.Primitives" version="4.0.10" targetFramework="net461" />
<package id="System.Text.Encoding" version="4.0.10" targetFramework="net461" /> <package id="System.Text.Encoding" version="4.0.10" targetFramework="net461" />
<package id="System.Threading.Tasks" version="4.0.10" targetFramework="net461" /> <package id="System.Text.Encoding.CodePages" version="4.0.0" targetFramework="net461" />
<package id="System.Text.RegularExpressions" version="4.0.10" targetFramework="net461" />
<package id="System.Threading" version="4.0.10" targetFramework="net461" />
<package id="System.Threading.Tasks" version="4.0.0" targetFramework="net461" />
</packages> </packages>

View File

@ -6,7 +6,7 @@
} }
}, },
"dependencies": { "dependencies": {
"Flurl.Http": "1.0.0-beta5" "Flurl.Http": "1.0.0-beta6-update3"
}, },
"frameworks": { "frameworks": {
"netcoreapp1.0": { "netcoreapp1.0": {

View File

@ -50,11 +50,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Flurl, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Flurl, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.2.1.0-beta5\lib\portable40-net40+win8+wpa81\Flurl.dll</HintPath> <HintPath>..\..\packages\Flurl.2.1.0-beta6\lib\portable40-net40+win8+wpa81\Flurl.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Flurl.Http, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Flurl.Http, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.1.0.0-beta5\lib\portable45-net45+win8+wpa81\Flurl.Http.dll</HintPath> <HintPath>..\..\packages\Flurl.Http.1.0.0-beta6-update3\lib\portable45-net45+win8+wpa81\Flurl.Http.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Flurl" version="2.1.0-beta5" targetFramework="portable45-net45+win8+wpa81" /> <package id="Flurl" version="2.1.0-beta6" targetFramework="portable45-net45+win8+wpa81" />
<package id="Flurl.Http" version="1.0.0-beta5" targetFramework="portable45-net45+win8+wpa81" /> <package id="Flurl.Http" version="1.0.0-beta6-update3" targetFramework="portable45-net45+win8+wpa81" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="portable45-net45+win8+wpa81" /> <package id="Microsoft.Bcl" version="1.1.10" targetFramework="portable45-net45+win8+wpa81" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="portable45-net45+win8+wpa81" /> <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="portable45-net45+win8+wpa81" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="portable45-net45+win8+wpa81" /> <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="portable45-net45+win8+wpa81" />

View File

@ -5,8 +5,7 @@
"compile": { "compile": {
"include": [ "../Flurl.Test.Shared/**/*.cs" ] "include": [ "../Flurl.Test.Shared/**/*.cs" ]
}, },
"emitEntryPoint": true, "emitEntryPoint": true
"optimize": true
}, },
"commands": { "commands": {

View File

@ -1,5 +1,5 @@
#if !NETCOREAPP1_0 using System.Linq;
using System.Linq; using System.Reflection;
using Flurl.Http; using Flurl.Http;
using NUnit.Framework; using NUnit.Framework;
@ -11,9 +11,9 @@ namespace Flurl.Test.Http
[Test] [Test]
// check that for every FlurlClient extension method, we have an equivalent Url and string extension // check that for every FlurlClient extension method, we have an equivalent Url and string extension
public void extension_methods_consistently_supported() { public void extension_methods_consistently_supported() {
var fcExts = ReflectionHelper.GetAllExtensionMethods<FlurlClient>(typeof(FlurlClient).Assembly); var fcExts = ReflectionHelper.GetAllExtensionMethods<FlurlClient>(typeof(FlurlClient).GetTypeInfo().Assembly);
var urlExts = ReflectionHelper.GetAllExtensionMethods<Url>(typeof(FlurlClient).Assembly); var urlExts = ReflectionHelper.GetAllExtensionMethods<Url>(typeof(FlurlClient).GetTypeInfo().Assembly);
var stringExts = ReflectionHelper.GetAllExtensionMethods<string>(typeof(FlurlClient).Assembly); var stringExts = ReflectionHelper.GetAllExtensionMethods<string>(typeof(FlurlClient).GetTypeInfo().Assembly);
var whitelist = new[] { "GetCookies", "WithUrl" }; // cases where Url method of the same name was excluded intentionally var whitelist = new[] { "GetCookies", "WithUrl" }; // cases where Url method of the same name was excluded intentionally
foreach (var method in fcExts) { foreach (var method in fcExts) {
@ -29,5 +29,4 @@ namespace Flurl.Test.Http
} }
} }
} }
} }
#endif

View File

@ -15,7 +15,7 @@ namespace Flurl.Test.Http
[TestFixture] [TestFixture]
public class RealHttpTests public class RealHttpTests
{ {
#if NET45 || NETCORE #if NET45 || NETCOREAPP1_0
[Test] [Test]
public async Task can_download_file() { public async Task can_download_file() {
var path = await "http://www.google.com".DownloadFileAsync(@"c:\a\b", "google.txt"); var path = await "http://www.google.com".DownloadFileAsync(@"c:\a\b", "google.txt");

View File

@ -1,5 +1,4 @@
#if !NETCOREAPP1_0 using System;
using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -12,7 +11,7 @@ namespace Flurl.Test
// http://stackoverflow.com/a/299526/62600 // http://stackoverflow.com/a/299526/62600
return ( return (
from type in asm.GetTypes() from type in asm.GetTypes()
where type.IsSealed && !type.IsGenericType && !type.IsNested where type.GetTypeInfo().IsSealed && !type.GetTypeInfo().IsGenericType && !type.GetTypeInfo().IsNested
from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
where method.IsDefined(typeof(ExtensionAttribute), false) where method.IsDefined(typeof(ExtensionAttribute), false)
where method.GetParameters()[0].ParameterType == typeof(T) where method.GetParameters()[0].ParameterType == typeof(T)
@ -56,9 +55,9 @@ namespace Flurl.Test
public static bool IsExtensionMethod(MethodInfo method) { public static bool IsExtensionMethod(MethodInfo method) {
var type = method.DeclaringType; var type = method.DeclaringType;
return return
type.IsSealed && type.GetTypeInfo().IsSealed &&
!type.IsGenericType && !type.GetTypeInfo().IsGenericType &&
!type.IsNested && !type.GetTypeInfo().IsNested &&
method.IsStatic && method.IsStatic &&
method.IsDefined(typeof(ExtensionAttribute), false); method.IsDefined(typeof(ExtensionAttribute), false);
} }
@ -74,8 +73,9 @@ namespace Flurl.Test
public static bool AreSameType(Type a, Type b) { public static bool AreSameType(Type a, Type b) {
if (a.IsGenericParameter && b.IsGenericParameter) { if (a.IsGenericParameter && b.IsGenericParameter) {
var constraintsA = a.GetGenericParameterConstraints();
var constraintsB = b.GetGenericParameterConstraints(); var constraintsA = a.GetTypeInfo().GetGenericParameterConstraints();
var constraintsB = b.GetTypeInfo().GetGenericParameterConstraints();
if (constraintsA.Length != constraintsB.Length) if (constraintsA.Length != constraintsB.Length)
return false; return false;
@ -87,7 +87,8 @@ namespace Flurl.Test
return true; return true;
} }
if (a.IsGenericType && b.IsGenericType) { if (a.GetTypeInfo().IsGenericType && b.GetTypeInfo().IsGenericType) {
if (a.GetGenericTypeDefinition() != b.GetGenericTypeDefinition()) if (a.GetGenericTypeDefinition() != b.GetGenericTypeDefinition())
return false; return false;
@ -108,5 +109,4 @@ namespace Flurl.Test
return a == b; return a == b;
} }
} }
} }
#endif

View File

@ -9,391 +9,388 @@ using NUnit.Framework;
namespace Flurl.Test namespace Flurl.Test
{ {
[TestFixture] [TestFixture]
public class UrlBuilderTests public class UrlBuilderTests
{ {
[Test]
// check that for every Url method, we have an equivalent string extension
public void extension_methods_consistently_supported()
{
var urlMethods = typeof(Url).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Where(m => !m.IsSpecialName);
var stringExts = ReflectionHelper.GetAllExtensionMethods<string>(typeof(Url).GetTypeInfo().Assembly);
var whitelist = new[] { "ToString", "IsValid" }; // cases where string extension of the same name was excluded intentionally
foreach (var method in urlMethods)
{
if (whitelist.Contains(method.Name))
continue;
if (!stringExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m)))
{
Assert.Fail("No equivalent string extension method found for Url.{0}", method.Name);
}
}
}
[Test]
public void Path_returns_everything_but_querystring()
{
var path = new Url("http://www.mysite.com/more?x=1&y=2").Path;
Assert.AreEqual("http://www.mysite.com/more", path);
}
[Test]
public void query_params_parse_correctly()
{
// y has 2 values, which should be grouped into an array
var q = new Url("http://www.mysite.com/more?x=1&y=2&z=3&y=4").QueryParams;
Assert.AreEqual("1", q["x"]);
CollectionAssert.AreEqual(new[] { "2", "4" }, q["y"] as IEnumerable);
Assert.AreEqual("3", q["z"]);
}
[Test]
public void can_get_query_param_array()
{
var url = new Url("http://www.mysite.com/more?x=1&y=2&x=3&z=4&x=5");
CollectionAssert.AreEqual(new[] { "1", "3", "5" }, url.QueryParams["x"] as object[]);
}
[Test]
public void can_set_query_param_array()
{
var url = new Url("http://www.mysite.com/more?x=1&y=2&x=2&z=4");
// go from 2 values to 3, order should be preserved
url.QueryParams["x"] = new[] { 8, 9, 10 };
Assert.AreEqual("http://www.mysite.com/more?x=8&y=2&x=9&z=4&x=10", url.ToString());
// go from 3 values to 2, order should be preserved
url.QueryParams["x"] = new[] { 101, 102 };
Assert.AreEqual("http://www.mysite.com/more?x=101&y=2&x=102&z=4", url.ToString());
// wipe them out. all of them.
url.QueryParams["x"] = null;
Assert.AreEqual("http://www.mysite.com/more?y=2&z=4", url.ToString());
}
[Test]
public void can_sort_query_params()
{
var url = new Url("http://www.mysite.com/more?z=1&y=2&x=3");
url.QueryParams.Sort((x, y) => x.Name.CompareTo(y.Name));
Assert.AreEqual("http://www.mysite.com/more?x=3&y=2&z=1", url.ToString());
}
[Test]
public void constructor_requires_nonnull_arg()
{
Assert.Throws<ArgumentNullException>(() => new Url(null));
}
[Test]
public void Combine_works()
{
var url = Url.Combine("http://www.foo.com/", "/too/", "/many/", "/slashes/", "too", "few", "one/two/");
Assert.AreEqual("http://www.foo.com/too/many/slashes/too/few/one/two/", url);
}
[Test]
public void GetRoot_works()
{
// simple case
var root = Url.GetRoot("http://mysite.com/one/two/three");
Assert.AreEqual("http://mysite.com", root);
// a litte more fancy
root = Url.GetRoot("https://me:you@www.site.com:8080/hello/goodbye?foo=bar");
Assert.AreEqual("https://me:you@www.site.com:8080", root);
}
[Test]
public void can_append_path_segment()
{
var url = "http://www.mysite.com".AppendPathSegment("endpoint");
Assert.AreEqual("http://www.mysite.com/endpoint", url.ToString());
}
[Test]
public void appending_null_path_segment_throws_arg_null_ex()
{
Assert.Throws<ArgumentNullException>(() => "http://www.mysite.com".AppendPathSegment(null));
}
[Test]
public void can_append_multiple_path_segments_by_multi_args()
{
var url = "http://www.mysite.com".AppendPathSegments("category", "/endpoint/");
Assert.AreEqual("http://www.mysite.com/category/endpoint/", url.ToString());
}
[Test]
public void can_append_multiple_path_segments_by_enumerable()
{
IEnumerable<string> segments = new[] { "/category/", "endpoint" };
var url = "http://www.mysite.com".AppendPathSegments(segments);
Assert.AreEqual("http://www.mysite.com/category/endpoint", url.ToString());
}
[Test]
public void can_add_query_param()
{
var url = "http://www.mysite.com".SetQueryParam("x", 1);
Assert.AreEqual("http://www.mysite.com?x=1", url.ToString());
}
[Test]
public void can_add_query_param_without_value()
{
var url = new Url("http://example.com?123456");
Assert.AreEqual("http://example.com", url.Path);
Assert.AreEqual(1, url.QueryParams.Count);
Assert.AreEqual(string.Empty, url.QueryParams["123456"]);
}
[Test]
public void can_change_query_param()
{
var url = "http://www.mysite.com?x=1".SetQueryParam("x", 2);
Assert.AreEqual("http://www.mysite.com?x=2", url.ToString());
}
[Test]
public void null_query_param_is_excluded()
{
var url = "http://www.mysite.com".SetQueryParam("x", null);
Assert.AreEqual("http://www.mysite.com", url.ToString());
}
[Test]
public void enumerable_query_param_is_split_into_multiple()
{
var url = "http://www.mysite.com".SetQueryParam("x", new[] { "a", "b", null, "c" });
Assert.AreEqual("http://www.mysite.com?x=a&x=b&x=c", url.ToString());
}
[Test]
public void can_add_multiple_query_params_from_anon_object()
{
var url = "http://www.mysite.com".SetQueryParams(new
{
x = 1,
y = 2,
z = new[] { 3, 4 },
exclude_me = (string)null
});
Assert.AreEqual("http://www.mysite.com?x=1&y=2&z=3&z=4", url.ToString());
}
[Test]
public void can_change_multiple_query_params_from_anon_object()
{
var url = "http://www.mysite.com?x=1&y=2&z=3".SetQueryParams(new
{
x = 8,
y = new[] { "a", "b" },
z = (int?)null
});
Assert.AreEqual("http://www.mysite.com?x=8&y=a&y=b", url.ToString());
}
[Test]
public void can_add_multiple_query_params_from_dictionary()
{
// let's challenge it a little with non-string keys
var url = "http://www.mysite.com".SetQueryParams(new Dictionary<int, string> { { 1, "x" }, { 2, "y" } });
Assert.AreEqual("http://www.mysite.com?1=x&2=y", url.ToString());
}
[Test]
public void can_remove_query_param()
{
var url = "http://www.mysite.com/more?x=1&y=2".RemoveQueryParam("x");
Assert.AreEqual("http://www.mysite.com/more?y=2", url.ToString());
}
[Test]
public void can_remove_query_params_by_multi_args()
{
var url = "http://www.mysite.com/more?x=1&y=2".RemoveQueryParams("x", "y");
Assert.AreEqual("http://www.mysite.com/more", url.ToString());
}
[Test]
public void can_remove_query_params_by_enumerable()
{
var url = "http://www.mysite.com/more?x=1&y=2&z=3".RemoveQueryParams(new[] { "x", "z" });
Assert.AreEqual("http://www.mysite.com/more?y=2", url.ToString());
}
[Test]
public void removing_nonexisting_query_params_is_ignored()
{
var url = "http://www.mysite.com/more".RemoveQueryParams("x", "y");
Assert.AreEqual("http://www.mysite.com/more", url.ToString());
}
#if !NETCOREAPP1_0 #if !NETCOREAPP1_0
[Test] [Test]
// check that for every Url method, we have an equivalent string extension public void url_ToString_uses_invariant_culture()
public void extension_methods_consistently_supported() {
{ Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("es-ES");
var urlMethods = typeof(Url).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Where(m => !m.IsSpecialName); var url = "http://www.mysite.com".SetQueryParam("x", 1.1);
var stringExts = ReflectionHelper.GetAllExtensionMethods<string>(typeof(Url).Assembly); Assert.AreEqual("http://www.mysite.com?x=1.1", url.ToString());
var whitelist = new[] { "ToString", "IsValid" }; // cases where string extension of the same name was excluded intentionally }
foreach (var method in urlMethods)
{
if (whitelist.Contains(method.Name))
continue;
if (!stringExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m)))
{
Assert.Fail("No equivalent string extension method found for Url.{0}", method.Name);
}
}
}
#endif #endif
[Test] [Test]
public void Path_returns_everything_but_querystring() public void can_reset_to_root()
{ {
var path = new Url("http://www.mysite.com/more?x=1&y=2").Path; var url = "http://www.mysite.com/more?x=1&y=2#foo".ResetToRoot();
Assert.AreEqual("http://www.mysite.com/more", path); Assert.AreEqual("http://www.mysite.com", url.ToString());
} }
[Test] [Test]
public void query_params_parse_correctly() public void can_do_crazy_long_fluent_expression()
{ {
// y has 2 values, which should be grouped into an array var url = "http://www.mysite.com"
var q = new Url("http://www.mysite.com/more?x=1&y=2&z=3&y=4").QueryParams; .SetQueryParams(new { a = 1, b = 2, c = 999 })
Assert.AreEqual("1", q["x"]); .SetFragment("fooey")
CollectionAssert.AreEqual(new[] { "2", "4" }, q["y"] as IEnumerable); .AppendPathSegment("category")
Assert.AreEqual("3", q["z"]); .RemoveQueryParam("c")
} .SetQueryParam("z", 55)
.RemoveQueryParams("a", "z")
.SetQueryParams(new { n = "hi", m = "bye" })
.AppendPathSegment("endpoint");
[Test] Assert.AreEqual("http://www.mysite.com/category/endpoint?b=2&n=hi&m=bye#fooey", url.ToString());
public void can_get_query_param_array() }
{
var url = new Url("http://www.mysite.com/more?x=1&y=2&x=3&z=4&x=5");
CollectionAssert.AreEqual(new[] { "1", "3", "5" }, url.QueryParams["x"] as object[]);
}
[Test] [Test]
public void can_set_query_param_array() public void encodes_invalid_path_chars()
{ {
var url = new Url("http://www.mysite.com/more?x=1&y=2&x=2&z=4"); var url = "http://www.mysite.com".AppendPathSegment("hey there how are ya");
// go from 2 values to 3, order should be preserved Assert.AreEqual("http://www.mysite.com/hey%20there%20how%20are%20ya", url.ToString());
url.QueryParams["x"] = new[] { 8, 9, 10 }; }
Assert.AreEqual("http://www.mysite.com/more?x=8&y=2&x=9&z=4&x=10", url.ToString());
// go from 3 values to 2, order should be preserved
url.QueryParams["x"] = new[] { 101, 102 };
Assert.AreEqual("http://www.mysite.com/more?x=101&y=2&x=102&z=4", url.ToString());
// wipe them out. all of them.
url.QueryParams["x"] = null;
Assert.AreEqual("http://www.mysite.com/more?y=2&z=4", url.ToString());
}
[Test] [Test]
public void can_sort_query_params() public void does_not_reencode_path_escape_chars()
{ {
var url = new Url("http://www.mysite.com/more?z=1&y=2&x=3"); var url = "http://www.mysite.com".AppendPathSegment("hey%20there%20how%20are%20ya");
url.QueryParams.Sort((x, y) => x.Name.CompareTo(y.Name)); Assert.AreEqual("http://www.mysite.com/hey%20there%20how%20are%20ya", url.ToString());
Assert.AreEqual("http://www.mysite.com/more?x=3&y=2&z=1", url.ToString()); }
}
[Test] [Test]
public void constructor_requires_nonnull_arg() public void encodes_query_params()
{ {
Assert.Throws<ArgumentNullException>(() => new Url(null)); var url = "http://www.mysite.com".SetQueryParams(new { x = "$50", y = "2+2=4" });
} Assert.AreEqual("http://www.mysite.com?x=%2450&y=2%2B2%3D4", url.ToString());
}
[Test] [Test]
public void Combine_works() public void does_not_reencode_encoded_query_values()
{ {
var url = Url.Combine("http://www.foo.com/", "/too/", "/many/", "/slashes/", "too", "few", "one/two/"); var url = "http://www.mysite.com".SetQueryParam("x", "%CD%EE%E2%FB%E9%20%E3%EE%E4", true);
Assert.AreEqual("http://www.foo.com/too/many/slashes/too/few/one/two/", url); Assert.AreEqual("http://www.mysite.com?x=%CD%EE%E2%FB%E9%20%E3%EE%E4", url.ToString());
} }
[Test] [Test]
public void GetRoot_works() public void reencodes_encoded_query_values_when_isEncoded_false()
{ {
// simple case var url = "http://www.mysite.com".SetQueryParam("x", "%CD%EE%E2%FB%E9%20%E3%EE%E4", false);
var root = Url.GetRoot("http://mysite.com/one/two/three"); Assert.AreEqual("http://www.mysite.com?x=%25CD%25EE%25E2%25FB%25E9%2520%25E3%25EE%25E4", url.ToString());
Assert.AreEqual("http://mysite.com", root); }
// a litte more fancy [Test]
root = Url.GetRoot("https://me:you@www.site.com:8080/hello/goodbye?foo=bar"); public void Url_implicitly_converts_to_string()
Assert.AreEqual("https://me:you@www.site.com:8080", root); {
} var url = new Url("http://www.mysite.com/more?x=1&y=2");
var someMethodThatTakesAString = new Action<string>(s => { });
someMethodThatTakesAString(url); // if this compiles, test passed.
}
[Test] [Test]
public void can_append_path_segment() public void interprets_plus_as_space()
{ {
var url = "http://www.mysite.com".AppendPathSegment("endpoint"); var url = new Url("http://www.mysite.com/foo+bar?x=1+2");
Assert.AreEqual("http://www.mysite.com/endpoint", url.ToString()); Assert.AreEqual("1 2", url.QueryParams["x"]);
} }
[Test] [Test]
public void appending_null_path_segment_throws_arg_null_ex() public void can_encode_space_as_plus()
{ {
Assert.Throws<ArgumentNullException>(() => "http://www.mysite.com".AppendPathSegment(null)); var url = new Url("http://www.mysite.com/foo+bar?x=1+2");
} Assert.AreEqual("http://www.mysite.com/foo+bar?x=1+2", url.ToString(true));
}
[Test] [Test]
public void can_append_multiple_path_segments_by_multi_args() public void encodes_plus()
{ {
var url = "http://www.mysite.com".AppendPathSegments("category", "/endpoint/"); var url = new Url("http://www.mysite.com").SetQueryParam("x", "1+2");
Assert.AreEqual("http://www.mysite.com/category/endpoint/", url.ToString()); Assert.AreEqual("http://www.mysite.com?x=1%2B2", url.ToString());
} }
[Test] [TestCase("http://www.mysite.com/more", true)]
public void can_append_multiple_path_segments_by_enumerable() [TestCase("http://www.mysite.com/more?x=1&y=2", true)]
{ [TestCase("http://www.mysite.com/more?x=1&y=2#frag", true)]
IEnumerable<string> segments = new[] { "/category/", "endpoint" }; [TestCase("http://www.mysite.com#frag", true)]
var url = "http://www.mysite.com".AppendPathSegments(segments); [TestCase("", false)]
Assert.AreEqual("http://www.mysite.com/category/endpoint", url.ToString()); [TestCase("blah", false)]
} [TestCase("http:/www.mysite.com", false)]
[TestCase("www.mysite.com", false)]
public void IsUrl_works(string s, bool isValid)
{
Assert.AreEqual(isValid, Url.IsValid(s));
Assert.AreEqual(isValid, new Url(s).IsValid());
}
[Test] // #56
public void can_add_query_param() [Test]
{ public void does_not_alter_url_passed_to_constructor()
var url = "http://www.mysite.com".SetQueryParam("x", 1); {
Assert.AreEqual("http://www.mysite.com?x=1", url.ToString()); var expected = "http://www.mysite.com/hi%20there/more?x=%CD%EE%E2%FB%E9%20%E3%EE%E4";
} var url = new Url(expected);
Assert.AreEqual(expected, url.ToString());
}
[Test] // #29
public void can_add_query_param_without_value() [Test]
{ public void can_add_and_remove_fragment_fluently()
var url = new Url("http://example.com?123456"); {
Assert.AreEqual("http://example.com", url.Path); var url = "http://www.mysite.com".SetFragment("foo");
Assert.AreEqual(1, url.QueryParams.Count); Assert.AreEqual("http://www.mysite.com#foo", url.ToString());
Assert.AreEqual(string.Empty, url.QueryParams["123456"]); url = "http://www.mysite.com#foo".RemoveFragment();
} Assert.AreEqual("http://www.mysite.com", url.ToString());
url = "http://www.mysite.com"
.SetFragment("foo")
.SetFragment("bar")
.AppendPathSegment("more")
.SetQueryParam("x", 1);
Assert.AreEqual("http://www.mysite.com/more?x=1#bar", url.ToString());
url = "http://www.mysite.com".SetFragment("foo").SetFragment("bar").RemoveFragment();
Assert.AreEqual("http://www.mysite.com", url.ToString());
}
[Test] [Test]
public void can_change_query_param() public void has_fragment_after_SetQueryParam()
{ {
var url = "http://www.mysite.com?x=1".SetQueryParam("x", 2); var expected = "http://www.mysite.com/more?x=1#first";
Assert.AreEqual("http://www.mysite.com?x=2", url.ToString()); var url = new Url(expected)
} .SetQueryParam("x", 3)
.SetQueryParam("y", 4);
Assert.AreEqual("http://www.mysite.com/more?x=3&y=4#first", url.ToString());
}
[Test] [TestCase("http://www.mysite.com/with/path?x=1", "http://www.mysite.com/with/path", "x=1", "")]
public void null_query_param_is_excluded() [TestCase("http://www.mysite.com/with/path?x=1#foo", "http://www.mysite.com/with/path", "x=1", "foo")]
{ [TestCase("http://www.mysite.com/with/path?x=1?y=2", "http://www.mysite.com/with/path", "x=1?y=2", "")]
var url = "http://www.mysite.com".SetQueryParam("x", null); [TestCase("http://www.mysite.com/#with/path?x=1?y=2", "http://www.mysite.com/", "", "with/path?x=1?y=2")]
Assert.AreEqual("http://www.mysite.com", url.ToString()); public void constructor_parses_url_correctly(string full, string path, string query, string fragment)
} {
var url = new Url(full);
Assert.AreEqual(path, url.Path);
Assert.AreEqual(query, url.Query);
Assert.AreEqual(fragment, url.Fragment);
Assert.AreEqual(full, url.ToString());
}
[Test] //public void QueryParams
public void enumerable_query_param_is_split_into_multiple() }
{
var url = "http://www.mysite.com".SetQueryParam("x", new[] { "a", "b", null, "c" });
Assert.AreEqual("http://www.mysite.com?x=a&x=b&x=c", url.ToString());
}
[Test]
public void can_add_multiple_query_params_from_anon_object()
{
var url = "http://www.mysite.com".SetQueryParams(new
{
x = 1,
y = 2,
z = new[] { 3, 4 },
exclude_me = (string)null
});
Assert.AreEqual("http://www.mysite.com?x=1&y=2&z=3&z=4", url.ToString());
}
[Test]
public void can_change_multiple_query_params_from_anon_object()
{
var url = "http://www.mysite.com?x=1&y=2&z=3".SetQueryParams(new
{
x = 8,
y = new[] { "a", "b" },
z = (int?)null
});
Assert.AreEqual("http://www.mysite.com?x=8&y=a&y=b", url.ToString());
}
[Test]
public void can_add_multiple_query_params_from_dictionary()
{
// let's challenge it a little with non-string keys
var url = "http://www.mysite.com".SetQueryParams(new Dictionary<int, string> { { 1, "x" }, { 2, "y" } });
Assert.AreEqual("http://www.mysite.com?1=x&2=y", url.ToString());
}
[Test]
public void can_remove_query_param()
{
var url = "http://www.mysite.com/more?x=1&y=2".RemoveQueryParam("x");
Assert.AreEqual("http://www.mysite.com/more?y=2", url.ToString());
}
[Test]
public void can_remove_query_params_by_multi_args()
{
var url = "http://www.mysite.com/more?x=1&y=2".RemoveQueryParams("x", "y");
Assert.AreEqual("http://www.mysite.com/more", url.ToString());
}
[Test]
public void can_remove_query_params_by_enumerable()
{
var url = "http://www.mysite.com/more?x=1&y=2&z=3".RemoveQueryParams(new[] { "x", "z" });
Assert.AreEqual("http://www.mysite.com/more?y=2", url.ToString());
}
[Test]
public void removing_nonexisting_query_params_is_ignored()
{
var url = "http://www.mysite.com/more".RemoveQueryParams("x", "y");
Assert.AreEqual("http://www.mysite.com/more", url.ToString());
}
#if !NETCOREAPP1_0
[Test]
public void url_ToString_uses_invariant_culture()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("es-ES");
var url = "http://www.mysite.com".SetQueryParam("x", 1.1);
Assert.AreEqual("http://www.mysite.com?x=1.1", url.ToString());
}
#endif
[Test]
public void can_reset_to_root()
{
var url = "http://www.mysite.com/more?x=1&y=2#foo".ResetToRoot();
Assert.AreEqual("http://www.mysite.com", url.ToString());
}
[Test]
public void can_do_crazy_long_fluent_expression()
{
var url = "http://www.mysite.com"
.SetQueryParams(new { a = 1, b = 2, c = 999 })
.SetFragment("fooey")
.AppendPathSegment("category")
.RemoveQueryParam("c")
.SetQueryParam("z", 55)
.RemoveQueryParams("a", "z")
.SetQueryParams(new { n = "hi", m = "bye" })
.AppendPathSegment("endpoint");
Assert.AreEqual("http://www.mysite.com/category/endpoint?b=2&n=hi&m=bye#fooey", url.ToString());
}
[Test]
public void encodes_invalid_path_chars()
{
var url = "http://www.mysite.com".AppendPathSegment("hey there how are ya");
Assert.AreEqual("http://www.mysite.com/hey%20there%20how%20are%20ya", url.ToString());
}
[Test]
public void does_not_reencode_path_escape_chars()
{
var url = "http://www.mysite.com".AppendPathSegment("hey%20there%20how%20are%20ya");
Assert.AreEqual("http://www.mysite.com/hey%20there%20how%20are%20ya", url.ToString());
}
[Test]
public void encodes_query_params()
{
var url = "http://www.mysite.com".SetQueryParams(new { x = "$50", y = "2+2=4" });
Assert.AreEqual("http://www.mysite.com?x=%2450&y=2%2B2%3D4", url.ToString());
}
[Test]
public void does_not_reencode_encoded_query_values()
{
var url = "http://www.mysite.com".SetQueryParam("x", "%CD%EE%E2%FB%E9%20%E3%EE%E4", true);
Assert.AreEqual("http://www.mysite.com?x=%CD%EE%E2%FB%E9%20%E3%EE%E4", url.ToString());
}
[Test]
public void reencodes_encoded_query_values_when_isEncoded_false()
{
var url = "http://www.mysite.com".SetQueryParam("x", "%CD%EE%E2%FB%E9%20%E3%EE%E4", false);
Assert.AreEqual("http://www.mysite.com?x=%25CD%25EE%25E2%25FB%25E9%2520%25E3%25EE%25E4", url.ToString());
}
[Test]
public void Url_implicitly_converts_to_string()
{
var url = new Url("http://www.mysite.com/more?x=1&y=2");
var someMethodThatTakesAString = new Action<string>(s => { });
someMethodThatTakesAString(url); // if this compiles, test passed.
}
[Test]
public void interprets_plus_as_space()
{
var url = new Url("http://www.mysite.com/foo+bar?x=1+2");
Assert.AreEqual("1 2", url.QueryParams["x"]);
}
[Test]
public void can_encode_space_as_plus()
{
var url = new Url("http://www.mysite.com/foo+bar?x=1+2");
Assert.AreEqual("http://www.mysite.com/foo+bar?x=1+2", url.ToString(true));
}
[Test]
public void encodes_plus()
{
var url = new Url("http://www.mysite.com").SetQueryParam("x", "1+2");
Assert.AreEqual("http://www.mysite.com?x=1%2B2", url.ToString());
}
[TestCase("http://www.mysite.com/more", true)]
[TestCase("http://www.mysite.com/more?x=1&y=2", true)]
[TestCase("http://www.mysite.com/more?x=1&y=2#frag", true)]
[TestCase("http://www.mysite.com#frag", true)]
[TestCase("", false)]
[TestCase("blah", false)]
[TestCase("http:/www.mysite.com", false)]
[TestCase("www.mysite.com", false)]
public void IsUrl_works(string s, bool isValid)
{
Assert.AreEqual(isValid, Url.IsValid(s));
Assert.AreEqual(isValid, new Url(s).IsValid());
}
// #56
[Test]
public void does_not_alter_url_passed_to_constructor()
{
var expected = "http://www.mysite.com/hi%20there/more?x=%CD%EE%E2%FB%E9%20%E3%EE%E4";
var url = new Url(expected);
Assert.AreEqual(expected, url.ToString());
}
// #29
[Test]
public void can_add_and_remove_fragment_fluently()
{
var url = "http://www.mysite.com".SetFragment("foo");
Assert.AreEqual("http://www.mysite.com#foo", url.ToString());
url = "http://www.mysite.com#foo".RemoveFragment();
Assert.AreEqual("http://www.mysite.com", url.ToString());
url = "http://www.mysite.com"
.SetFragment("foo")
.SetFragment("bar")
.AppendPathSegment("more")
.SetQueryParam("x", 1);
Assert.AreEqual("http://www.mysite.com/more?x=1#bar", url.ToString());
url = "http://www.mysite.com".SetFragment("foo").SetFragment("bar").RemoveFragment();
Assert.AreEqual("http://www.mysite.com", url.ToString());
}
[Test]
public void has_fragment_after_SetQueryParam()
{
var expected = "http://www.mysite.com/more?x=1#first";
var url = new Url(expected)
.SetQueryParam("x", 3)
.SetQueryParam("y", 4);
Assert.AreEqual("http://www.mysite.com/more?x=3&y=4#first", url.ToString());
}
[TestCase("http://www.mysite.com/with/path?x=1", "http://www.mysite.com/with/path", "x=1", "")]
[TestCase("http://www.mysite.com/with/path?x=1#foo", "http://www.mysite.com/with/path", "x=1", "foo")]
[TestCase("http://www.mysite.com/with/path?x=1?y=2", "http://www.mysite.com/with/path", "x=1?y=2", "")]
[TestCase("http://www.mysite.com/#with/path?x=1?y=2", "http://www.mysite.com/", "", "with/path?x=1?y=2")]
public void constructor_parses_url_correctly(string full, string path, string query, string fragment)
{
var url = new Url(full);
Assert.AreEqual(path, url.Path);
Assert.AreEqual(query, url.Query);
Assert.AreEqual(fragment, url.Fragment);
Assert.AreEqual(full, url.ToString());
}
//public void QueryParams
}
} }

View File

@ -1,9 +1,9 @@
{ {
"title": "Flurl.Http", "title": "Flurl.Http",
"version": "1.0.0-beta5", "version": "1.0.0-beta6-update3",
"dependencies": { "dependencies": {
"Flurl": "2.1.0-beta5", "Flurl": "2.1.0-beta6",
"Newtonsoft.Json": "8.0.3" "Newtonsoft.Json": "8.0.3"
}, },
@ -40,13 +40,14 @@
"netstandard1.4": { "netstandard1.4": {
"imports": "dnxcore50", "imports": "dnxcore50",
"dependencies": { "dependencies": {
"System.Dynamic.Runtime": "4.0.11-rc2-24027", "System.Dynamic.Runtime": "4.0.10",
"System.IO.FileSystem": "4.0.1-rc2-24027", "System.IO.FileSystem": "4.0.0",
"System.Net.Http": "4.0.1-rc2-24027", "System.Net.Http": "4.0.0",
"System.Runtime.Extensions": "4.1.0-rc2-24027", "System.Runtime.Extensions": "4.0.10",
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-24027", "System.Runtime.Serialization.Primitives": "4.0.10",
"System.Text.RegularExpressions": "4.0.12-rc2-24027", "System.Text.Encoding.CodePages": "4.0.0",
"System.Threading": "4.0.11-rc2-24027" "System.Text.RegularExpressions": "4.0.10",
"System.Threading": "4.0.10"
} }
} }
} }

View File

@ -3,6 +3,9 @@ using System.Collections.Generic;
using System.Dynamic; using System.Dynamic;
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
#if NETSTANDARD1_4
using System.Text;
#endif
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Flurl.Http namespace Flurl.Http
@ -15,9 +18,10 @@ namespace Flurl.Http
/// <summary> /// <summary>
/// Deserializes JSON-formatted HTTP response body to object of type T. Intended to chain off an async HTTP. /// Deserializes JSON-formatted HTTP response body to object of type T. Intended to chain off an async HTTP.
/// </summary> /// </summary>
/// <typeparam name="T">A type whose structure matches the expected JSON response.</typeparam> /// <typeparam name="T">A type whose structure matches the expected JSON response.</typeparam>
/// <returns>A Task whose result is an object containing data in the response body.</returns> /// <returns>A Task whose result is an object containing data in the response body.</returns>
/// <example>x = await url.PostAsync(data).ReceiveJson&lt;T&gt;()</example> /// <example>x = await url.PostAsync(data).ReceiveJson&lt;T&gt;()</example>
/// <exception cref="FlurlHttpException">Condition.</exception>
public static async Task<T> ReceiveJson<T>(this Task<HttpResponseMessage> response) { public static async Task<T> ReceiveJson<T>(this Task<HttpResponseMessage> response) {
var resp = await response.ConfigureAwait(false); var resp = await response.ConfigureAwait(false);
var call = HttpCall.Get(resp.RequestMessage); var call = HttpCall.Get(resp.RequestMessage);
@ -27,7 +31,7 @@ namespace Flurl.Http
} }
catch (Exception ex) { catch (Exception ex) {
call.Exception = ex; call.Exception = ex;
throw new FlurlHttpException(call); throw new FlurlHttpException(call, ex);
} }
} }
@ -36,6 +40,7 @@ namespace Flurl.Http
/// </summary> /// </summary>
/// <returns>A Task whose result is a dynamic object containing data in the response body.</returns> /// <returns>A Task whose result is a dynamic object containing data in the response body.</returns>
/// <example>d = await url.PostAsync(data).ReceiveJson()</example> /// <example>d = await url.PostAsync(data).ReceiveJson()</example>
/// <exception cref="FlurlHttpException">Condition.</exception>
public static async Task<dynamic> ReceiveJson(this Task<HttpResponseMessage> response) { public static async Task<dynamic> ReceiveJson(this Task<HttpResponseMessage> response) {
return await response.ReceiveJson<ExpandoObject>().ConfigureAwait(false); return await response.ReceiveJson<ExpandoObject>().ConfigureAwait(false);
} }
@ -45,6 +50,7 @@ namespace Flurl.Http
/// </summary> /// </summary>
/// <returns>A Task whose result is a list of dynamic objects containing data in the response body.</returns> /// <returns>A Task whose result is a list of dynamic objects containing data in the response body.</returns>
/// <example>d = await url.PostAsync(data).ReceiveJsonList()</example> /// <example>d = await url.PostAsync(data).ReceiveJsonList()</example>
/// <exception cref="FlurlHttpException">Condition.</exception>
public static async Task<IList<dynamic>> ReceiveJsonList(this Task<HttpResponseMessage> response) { public static async Task<IList<dynamic>> ReceiveJsonList(this Task<HttpResponseMessage> response) {
dynamic[] d = await response.ReceiveJson<ExpandoObject[]>().ConfigureAwait(false); dynamic[] d = await response.ReceiveJson<ExpandoObject[]>().ConfigureAwait(false);
return d; return d;
@ -56,6 +62,9 @@ namespace Flurl.Http
/// <returns>A Task whose result is the response body as a string.</returns> /// <returns>A Task whose result is the response body as a string.</returns>
/// <example>s = await url.PostAsync(data).ReceiveString()</example> /// <example>s = await url.PostAsync(data).ReceiveString()</example>
public static async Task<string> ReceiveString(this Task<HttpResponseMessage> response) { public static async Task<string> ReceiveString(this Task<HttpResponseMessage> response) {
#if NETSTANDARD1_4
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#endif
return await (await response.ConfigureAwait(false)).Content.ReadAsStringAsync().ConfigureAwait(false); return await (await response.ConfigureAwait(false)).Content.ReadAsStringAsync().ConfigureAwait(false);
} }
@ -77,4 +86,4 @@ namespace Flurl.Http
return await (await response.ConfigureAwait(false)).Content.ReadAsByteArrayAsync().ConfigureAwait(false); return await (await response.ConfigureAwait(false)).Content.ReadAsByteArrayAsync().ConfigureAwait(false);
} }
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"title": "Flurl", "title": "Flurl",
"version": "2.1.0-beta5", "version": "2.1.0-beta6",
"buildOptions": { "buildOptions": {
"compile": { "compile": {
@ -20,10 +20,10 @@
} }
}, },
"netstandard1.4": { "netstandard1.4": {
"imports": "dotnet",
"dependencies": { "dependencies": {
"System.Globalization": "4.0.11-rc2-24027", "System.Linq": "4.0.0",
"System.Linq": "4.1.0-rc2-24027", "System.Reflection.TypeExtensions": "4.0.0"
"System.Reflection.TypeExtensions": "4.1.0-rc2-24027"
} }
} }
} }