Compare commits
28 Commits
1.0.0
...
objectSeri
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a80ec08760 | ||
|
|
b4c3914e73 | ||
|
|
8b053f0f77 | ||
|
|
b68af327ab | ||
|
|
68bf719c27 | ||
|
|
3ff3165a42 | ||
|
|
16f96b9b27 | ||
|
|
04e2090a95 | ||
|
|
176659d0cb | ||
|
|
ad60fd47d9 | ||
|
|
3c3641a4f5 | ||
|
|
d7fc6865c1 | ||
|
|
1911b4a3e7 | ||
|
|
6e3e23061a | ||
|
|
91579a1700 | ||
|
|
d6c78f2193 | ||
|
|
dbb9f5b404 | ||
|
|
5bfe876f57 | ||
|
|
6a31a1968e | ||
|
|
43bcbb3c30 | ||
|
|
c66614c2fe | ||
|
|
2885118175 | ||
|
|
9b5bd3769f | ||
|
|
0b1b20f5df | ||
|
|
a15ad38a86 | ||
|
|
0a14c742e1 | ||
|
|
103bab1eb7 | ||
|
|
e1817ab447 |
@@ -1,6 +1,11 @@
|
|||||||
|
if($env:APPVEYOR_REPO_TAG -eq "true")
|
||||||
|
{
|
||||||
|
"do not publish coverall data on tag builds"
|
||||||
|
return
|
||||||
|
}
|
||||||
nuget install OpenCover -Version 4.6.519 -OutputDirectory tools
|
nuget install OpenCover -Version 4.6.519 -OutputDirectory tools
|
||||||
nuget install coveralls.net -Version 0.7.0 -OutputDirectory tools
|
nuget install coveralls.net -Version 0.7.0 -OutputDirectory tools
|
||||||
|
|
||||||
.\tools\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:" test "".\src\UriBuilder.Fluent.UnitTests"" -f net461" -register:user -filter:"+[UriBuilder*]* -[*Tests]*" -returntargetcode -output:opencover_results.xml
|
.\tools\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:" test "".\src\UriBuilder.Fluent.UnitTests"" -f net462" -register:user -filter:"+[UriBuilder*]* -[*Tests]*" -returntargetcode -output:opencover_results.xml
|
||||||
|
|
||||||
.\tools\coveralls.net.0.7.0\tools\csmacnz.Coveralls.exe --opencover -i .\opencover_results.xml
|
.\tools\coveralls.net.0.7.0\tools\csmacnz.Coveralls.exe --opencover -i .\opencover_results.xml
|
||||||
22
Readme.md
22
Readme.md
@@ -1,6 +1,7 @@
|
|||||||
## UriBuilder.Fluent
|
## UriBuilder.Fluent
|
||||||
|
[](https://coveralls.io/github/TerribleDev/UriBuilder.Fluent) [](https://ci.appveyor.com/project/tparnell8/uribuilder-fluent/branch/master)
|
||||||
|
|
||||||
This places extension methods over System.UriBuilder to help deal with query string parameters, and create more of a fluent interface. Unlike other projects this builds ontop of trusty UriBuilder, and does not use custom Uri generators, or have outside dependencies.
|
This places extension methods over System.UriBuilder to help deal with query string parameters, and create more of a fluent interface. Unlike other projects, this NetStandardLibrary compliant package builds ontop of trusty UriBuilder, does not use custom Uri generators, or have outside dependencies. Unit tests continue to be a first class citizen!
|
||||||
|
|
||||||
This lets you do things like
|
This lets you do things like
|
||||||
|
|
||||||
@@ -28,7 +29,22 @@ new UriBuilder("https://awesome.com/yo)
|
|||||||
.WithParameter("id", "5")
|
.WithParameter("id", "5")
|
||||||
.ToString();
|
.ToString();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
result: `https://awesome.com/yo?id=5`
|
result: `https://awesome.com/yo?id=5`
|
||||||
|
|
||||||
|
you can even pass a dictionary of parameters
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var dictionary = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
["yo"] = "dawg"
|
||||||
|
};
|
||||||
|
new UriBuilder("http://awesome.com")
|
||||||
|
.WithParameter(dictionary);
|
||||||
|
http://awesome.com/?yo=dawg
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Just install the nuget package `install-package UriBuilder.Fluent` and thats it. The extension methods should be available to you!
|
||||||
13
appveyor.yml
13
appveyor.yml
@@ -4,7 +4,7 @@ nuget:
|
|||||||
account_feed: true
|
account_feed: true
|
||||||
project_feed: true
|
project_feed: true
|
||||||
artifacts:
|
artifacts:
|
||||||
- path: '**\*.nupkg'
|
- path: 'src\**\*.nupkg'
|
||||||
|
|
||||||
init:
|
init:
|
||||||
- git config --global core.autocrlf true
|
- git config --global core.autocrlf true
|
||||||
@@ -12,19 +12,20 @@ init:
|
|||||||
before_build:
|
before_build:
|
||||||
- ps: invoke-webrequest https://go.microsoft.com/fwlink/?LinkID=827524 -OutFile core.exe
|
- ps: invoke-webrequest https://go.microsoft.com/fwlink/?LinkID=827524 -OutFile core.exe
|
||||||
- ps: .\core.exe /install /quiet /norestart
|
- ps: .\core.exe /install /quiet /norestart
|
||||||
|
- ps: iwr -Uri https://download.microsoft.com/download/E/F/D/EFD52638-B804-4865-BB57-47F4B9C80269/NDP462-DevPack-KB3151934-ENU.exe -OutFile net452.exe
|
||||||
|
- ps: start-process .\net452.exe -Wait '/install /quiet /norestart'
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- ps: dotnet restore
|
- ps: dotnet restore
|
||||||
- ps: dotnet build -c Release .\src\UriBuilder.Fluent
|
- ps: dotnet build -c Release .\src\UriBuilder.Fluent
|
||||||
- ps: dotnet build -c Release .\src\UriBuilder.Fluent.UnitTests
|
- ps: dotnet publish -c Release .\src\UriBuilder.Fluent.UnitTests
|
||||||
- ps: .\update-projectjson.ps1
|
|
||||||
- ps: dotnet restore
|
|
||||||
- ps: dotnet pack -c Release .\src\UriBuilder.Fluent
|
|
||||||
|
|
||||||
|
|
||||||
test_script:
|
test_script:
|
||||||
- ps: dotnet test -c Release .\src\UriBuilder.Fluent.UnitTests
|
|
||||||
- ps: .\Coverage.ps1
|
- ps: .\Coverage.ps1
|
||||||
|
- ps: .\update-projectjson.ps1
|
||||||
|
- ps: dotnet restore
|
||||||
|
- ps: dotnet pack -c Release .\src\UriBuilder.Fluent
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
- provider: NuGet
|
- provider: NuGet
|
||||||
|
|||||||
@@ -97,6 +97,16 @@ namespace FluentUriBuilder.Tests
|
|||||||
Assert.Equal(url.Host, "yodawg.com");
|
Assert.Equal(url.Host, "yodawg.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AddParamWithNoValue()
|
||||||
|
{
|
||||||
|
var url = new UriBuilder("http://awesome.com")
|
||||||
|
.WithParameter("awesome", "yodawg")
|
||||||
|
.WithParameter("fun", null)
|
||||||
|
.WithParameter("cool", string.Empty);
|
||||||
|
Assert.Equal("http://awesome.com/?awesome=yodawg&fun&cool", url.Uri.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestAddTwoUrlParameters()
|
public void TestAddTwoUrlParameters()
|
||||||
{
|
{
|
||||||
@@ -106,5 +116,29 @@ namespace FluentUriBuilder.Tests
|
|||||||
.WithParameter("supgf", "no22");
|
.WithParameter("supgf", "no22");
|
||||||
Assert.Equal("http://awesome.com/?awesome=yodawg&supg=no2&supgf=no22", url.Uri.ToString());
|
Assert.Equal("http://awesome.com/?awesome=yodawg&supg=no2&supgf=no22", url.Uri.ToString());
|
||||||
}
|
}
|
||||||
|
[Fact]
|
||||||
|
public void TestSerializedParameters()
|
||||||
|
{
|
||||||
|
var url = new UriBuilder("http://awesome.com")
|
||||||
|
.WithSerializedObject(new {yo="dawg"});
|
||||||
|
Assert.Equal("http://awesome.com/?yo=dawg", url.Uri.ToString());
|
||||||
|
url = new UriBuilder("http://awesome.com")
|
||||||
|
.WithSerializedObject(new {yo=""});
|
||||||
|
Assert.Equal("http://awesome.com/?yo", url.Uri.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AddDictOfParams()
|
||||||
|
{
|
||||||
|
var dictionary = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
["yo"] = "dawg",
|
||||||
|
["troll"] = "toll",
|
||||||
|
["hammer"] = string.Empty
|
||||||
|
};
|
||||||
|
var url = new UriBuilder("http://awesome.com")
|
||||||
|
.WithParameter(dictionary);
|
||||||
|
Assert.Equal("http://awesome.com/?yo=dawg&troll=toll&hammer", url.Uri.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ namespace FluentUriBuilder.Tests
|
|||||||
Assert.Throws<ArgumentNullException>(() => tstObj.WithPathSegment(null));
|
Assert.Throws<ArgumentNullException>(() => tstObj.WithPathSegment(null));
|
||||||
Assert.Throws<ArgumentNullException>(() => tstObj.WithScheme(null));
|
Assert.Throws<ArgumentNullException>(() => tstObj.WithScheme(null));
|
||||||
Assert.Throws<ArgumentNullException>(() => tstObj.WithHost(null));
|
Assert.Throws<ArgumentNullException>(() => tstObj.WithHost(null));
|
||||||
|
Assert.Throws<ArgumentNullException>(() => tstObj.WithParameter(parameterDictionary: null));
|
||||||
Assert.Throws<ArgumentOutOfRangeException>(() => tstObj.WithPort(-1));
|
Assert.Throws<ArgumentOutOfRangeException>(() => tstObj.WithPort(-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net461": {},
|
"net462": {
|
||||||
|
},
|
||||||
"netcoreapp1.0": {
|
"netcoreapp1.0": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.NETCore.App": {
|
"Microsoft.NETCore.App": {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -8,8 +9,40 @@ namespace System
|
|||||||
{
|
{
|
||||||
public static class TerribleDevUriExtensions
|
public static class TerribleDevUriExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Appends a query string parameter with a key, and many values. Multiple values will be comma seperated. If only 1 value is passed and its null or value, the key will be added to the QS.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bld"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="values"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static UriBuilder WithParameter(this UriBuilder bld, string key, params string[] values) => bld.WithParameter(key, valuesEnum: values);
|
public static UriBuilder WithParameter(this UriBuilder bld, string key, params string[] values) => bld.WithParameter(key, valuesEnum: values);
|
||||||
|
|
||||||
|
public static UriBuilder WithParameter(this UriBuilder bld, string key, object value) => bld.WithParameter(key, new object[1] { value });
|
||||||
|
/// <summary>
|
||||||
|
/// Appends query strings from dictionary
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bld"></param>
|
||||||
|
/// <param name="parameterDictionary"></param>
|
||||||
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static UriBuilder WithParameter(this UriBuilder bld, IDictionary<string, string> parameterDictionary)
|
||||||
|
{
|
||||||
|
if(parameterDictionary == null) throw new ArgumentNullException(nameof(parameterDictionary));
|
||||||
|
foreach(var item in parameterDictionary)
|
||||||
|
{
|
||||||
|
bld.WithParameter(item.Key, item.Value);
|
||||||
|
}
|
||||||
|
return bld;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Appends a query string parameter with a key, and many values. Multiple values will be comma seperated. If only 1 value is passed and its null or value, the key will be added to the QS.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bld"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="valuesEnum"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static UriBuilder WithParameter(this UriBuilder bld, string key, IEnumerable<object> valuesEnum)
|
public static UriBuilder WithParameter(this UriBuilder bld, string key, IEnumerable<object> valuesEnum)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrWhiteSpace(key))
|
if(string.IsNullOrWhiteSpace(key))
|
||||||
@@ -20,8 +53,7 @@ namespace System
|
|||||||
{
|
{
|
||||||
valuesEnum = new string[0];
|
valuesEnum = new string[0];
|
||||||
}
|
}
|
||||||
var isfirst = string.IsNullOrWhiteSpace(bld.Query);
|
var intitialValue = string.IsNullOrWhiteSpace(bld.Query) ? "" : $"{bld.Query.TrimStart('?')}&";
|
||||||
var intitialValue = isfirst ? "" : $"{bld.Query.TrimStart('?')}&";
|
|
||||||
var sb = new StringBuilder($"{intitialValue}{key}");
|
var sb = new StringBuilder($"{intitialValue}{key}");
|
||||||
var validValueHit = false;
|
var validValueHit = false;
|
||||||
foreach(var value in valuesEnum)
|
foreach(var value in valuesEnum)
|
||||||
@@ -37,6 +69,13 @@ namespace System
|
|||||||
return bld;
|
return bld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the port to be the port number
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bld"></param>
|
||||||
|
/// <param name="port"></param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Throws if port is less than one</exception>
|
||||||
|
/// <returns></returns>
|
||||||
public static UriBuilder WithPort(this UriBuilder bld, int port)
|
public static UriBuilder WithPort(this UriBuilder bld, int port)
|
||||||
{
|
{
|
||||||
if(port < 1) throw new ArgumentOutOfRangeException(nameof(port));
|
if(port < 1) throw new ArgumentOutOfRangeException(nameof(port));
|
||||||
@@ -44,6 +83,13 @@ namespace System
|
|||||||
return bld;
|
return bld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// appends a path segment to the path. Can be called multiple times to append multiple segments
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bld"></param>
|
||||||
|
/// <param name="pathSegment"></param>
|
||||||
|
/// <exception cref="ArgumentNullException">You pass a string as a path segment</exception>
|
||||||
|
/// <returns></returns>
|
||||||
public static UriBuilder WithPathSegment(this UriBuilder bld, string pathSegment)
|
public static UriBuilder WithPathSegment(this UriBuilder bld, string pathSegment)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrWhiteSpace(pathSegment))
|
if(string.IsNullOrWhiteSpace(pathSegment))
|
||||||
@@ -51,15 +97,17 @@ namespace System
|
|||||||
throw new ArgumentNullException(nameof(pathSegment));
|
throw new ArgumentNullException(nameof(pathSegment));
|
||||||
}
|
}
|
||||||
var path = pathSegment.TrimStart('/');
|
var path = pathSegment.TrimStart('/');
|
||||||
if(string.IsNullOrWhiteSpace(bld.Path))
|
|
||||||
{
|
|
||||||
bld.Path = path;
|
|
||||||
return bld;
|
|
||||||
}
|
|
||||||
bld.Path = $"{bld.Path.TrimEnd('/')}/{path}";
|
bld.Path = $"{bld.Path.TrimEnd('/')}/{path}";
|
||||||
return bld;
|
return bld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets your Uri Scheme
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bld"></param>
|
||||||
|
/// <param name="scheme"></param>
|
||||||
|
/// <exception cref="ArgumentNullException">You must pass a scheme</exception>
|
||||||
|
/// <returns></returns>
|
||||||
public static UriBuilder WithScheme(this UriBuilder bld, string scheme)
|
public static UriBuilder WithScheme(this UriBuilder bld, string scheme)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrWhiteSpace(scheme)) throw new ArgumentNullException(nameof(scheme));
|
if(string.IsNullOrWhiteSpace(scheme)) throw new ArgumentNullException(nameof(scheme));
|
||||||
@@ -67,6 +115,13 @@ namespace System
|
|||||||
return bld;
|
return bld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bld"></param>
|
||||||
|
/// <param name="host"></param>
|
||||||
|
/// <exception cref="ArgumentNullException">You must pass a ho0st</exception>
|
||||||
|
/// <returns></returns>
|
||||||
public static UriBuilder WithHost(this UriBuilder bld, string host)
|
public static UriBuilder WithHost(this UriBuilder bld, string host)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrWhiteSpace(host)) throw new ArgumentNullException(nameof(host));
|
if(string.IsNullOrWhiteSpace(host)) throw new ArgumentNullException(nameof(host));
|
||||||
@@ -74,10 +129,31 @@ namespace System
|
|||||||
return bld;
|
return bld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Use Https?
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bld"></param>
|
||||||
|
/// <param name="predicate">default true, if false sets scheme to http</param>
|
||||||
|
/// <returns></returns>
|
||||||
public static UriBuilder UseHttps(this UriBuilder bld, bool predicate = true)
|
public static UriBuilder UseHttps(this UriBuilder bld, bool predicate = true)
|
||||||
{
|
{
|
||||||
bld.Scheme = predicate ? "https" : "http";
|
bld.Scheme = predicate ? "https" : "http";
|
||||||
return bld;
|
return bld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (netstandard15)
|
||||||
|
|
||||||
|
public static UriBuilder WithSerializedObject(this UriBuilder bld, object serialize)
|
||||||
|
{
|
||||||
|
var types = serialize.GetType().GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty);
|
||||||
|
foreach(var type in types)
|
||||||
|
{
|
||||||
|
bld.WithParameter(type.Name, type.GetValue(serialize, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
return bld;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
"Tommy Parnell"
|
"Tommy Parnell"
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"url":"https://github.com/TerribleDev/UriBuilder.Fluent"
|
"url": "https://github.com/TerribleDev/UriBuilder.Fluent"
|
||||||
},
|
},
|
||||||
"summary": "Fluent extensions for UriBuilder",
|
"summary": "Fluent extensions for UriBuilder",
|
||||||
"tags": [
|
"tags": [
|
||||||
@@ -16,13 +16,33 @@
|
|||||||
"extension"
|
"extension"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"authors": [
|
||||||
|
"Tommy Parnell"
|
||||||
|
],
|
||||||
|
"frameworks": {
|
||||||
|
"netstandard1.1": {
|
||||||
|
"buildOptions": {
|
||||||
|
"define": [ "netstandard11" ]
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"NETStandard.Library": "1.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"netstandard1.5": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"NETStandard.Library": "1.6.0"
|
"NETStandard.Library": "1.6.0"
|
||||||
},
|
},
|
||||||
|
"buildOptions": {
|
||||||
"frameworks": {
|
"define": [ "netstandard15" ]
|
||||||
"netstandard1.3": {
|
}
|
||||||
"imports": "dnxcore50"
|
},
|
||||||
|
"net45":{
|
||||||
|
"buildOptions": {
|
||||||
|
"define": [ "netstandard15" ]
|
||||||
|
},
|
||||||
|
"frameworkAssemblies": {
|
||||||
|
"System.Runtime":"4.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user