Merge pull request #17 from TerribleDev/nullchk

null checks
This commit is contained in:
Tommy Parnell
2018-04-14 18:06:28 -04:00
committed by GitHub
5 changed files with 50 additions and 3 deletions

View File

@@ -23,6 +23,6 @@ test_script:
deploy: deploy:
- provider: NuGet - provider: NuGet
api_key: api_key:
secure: bGn7M6dHOJ3QjwYIv7e34tcY/n9cCUZmL1MnM6jRfmnJOOfwlrS+cdRj2n8Wf31n secure: //tKHlb2yqAtpxnR6p9IAtXwQNaq8UYYyIFSD0QVF3XnEasIxG2gTWdmWuG87fUX
on: on:
appveyor_repo_tag: true appveyor_repo_tag: true

View File

@@ -20,6 +20,13 @@ namespace FluentUriBuilder.Tests
Assert.Throws<ArgumentNullException>(() => tstObj.WithParameter(parameterDictionary: null)); Assert.Throws<ArgumentNullException>(() => tstObj.WithParameter(parameterDictionary: null));
Assert.Throws<ArgumentNullException>(() => tstObj.WithFragment(fragmentDictionary: null)); Assert.Throws<ArgumentNullException>(() => tstObj.WithFragment(fragmentDictionary: null));
Assert.Throws<ArgumentOutOfRangeException>(() => tstObj.WithPort(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => tstObj.WithPort(-1));
UriBuilder nullPtr = null;
Assert.Throws<ArgumentNullException>(()=>nullPtr.WithFragment("yo", "dawg"));
Assert.Throws<ArgumentNullException>(()=>nullPtr.WithParameter("yo", "dawg"));
Assert.Throws<ArgumentNullException>(()=>nullPtr.WithPathSegment("yo"));
Assert.Throws<ArgumentNullException>(()=>nullPtr.WithScheme("yo"));
Assert.Throws<ArgumentNullException>(()=>nullPtr.WithFragment("yo"));
Assert.Throws<ArgumentNullException>(()=>nullPtr.WithoutDefaultPort());
} }
} }
} }

View File

@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netcoreapp1.1;net461</TargetFrameworks> <TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />

View File

@@ -26,6 +26,10 @@ namespace System
/// <returns></returns> /// <returns></returns>
public static UriBuilder WithParameter(this UriBuilder bld, IDictionary<string, string> parameterDictionary) public static UriBuilder WithParameter(this UriBuilder bld, IDictionary<string, string> parameterDictionary)
{ {
if(bld == null)
{
throw new ArgumentNullException(nameof(bld));
}
if(parameterDictionary == null) throw new ArgumentNullException(nameof(parameterDictionary)); if(parameterDictionary == null) throw new ArgumentNullException(nameof(parameterDictionary));
foreach(var item in parameterDictionary) foreach(var item in parameterDictionary)
{ {
@@ -43,6 +47,10 @@ namespace System
/// <returns></returns> /// <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(bld == null)
{
throw new ArgumentNullException(nameof(bld));
}
if(string.IsNullOrWhiteSpace(key)) if(string.IsNullOrWhiteSpace(key))
{ {
throw new ArgumentNullException(nameof(key)); throw new ArgumentNullException(nameof(key));
@@ -74,6 +82,10 @@ namespace System
/// <returns></returns> /// <returns></returns>
public static UriBuilder WithFragment(this UriBuilder bld, IDictionary<string, string> fragmentDictionary) public static UriBuilder WithFragment(this UriBuilder bld, IDictionary<string, string> fragmentDictionary)
{ {
if(bld == null)
{
throw new ArgumentNullException(nameof(bld));
}
if(fragmentDictionary == null) throw new ArgumentNullException(nameof(fragmentDictionary)); if(fragmentDictionary == null) throw new ArgumentNullException(nameof(fragmentDictionary));
foreach(var item in fragmentDictionary) foreach(var item in fragmentDictionary)
{ {
@@ -91,6 +103,10 @@ namespace System
/// <returns></returns> /// <returns></returns>
public static UriBuilder WithFragment(this UriBuilder bld, string key, IEnumerable<object> valuesEnum) public static UriBuilder WithFragment(this UriBuilder bld, string key, IEnumerable<object> valuesEnum)
{ {
if(bld == null)
{
throw new ArgumentNullException(nameof(bld));
}
if(string.IsNullOrWhiteSpace(key)) if(string.IsNullOrWhiteSpace(key))
{ {
throw new ArgumentNullException(nameof(key)); throw new ArgumentNullException(nameof(key));
@@ -113,6 +129,10 @@ namespace System
/// <returns></returns> /// <returns></returns>
public static UriBuilder WithPort(this UriBuilder bld, int port) public static UriBuilder WithPort(this UriBuilder bld, int port)
{ {
if(bld == null)
{
throw new ArgumentNullException(nameof(bld));
}
if(port < 1) throw new ArgumentOutOfRangeException(nameof(port)); if(port < 1) throw new ArgumentOutOfRangeException(nameof(port));
bld.Port = port; bld.Port = port;
return bld; return bld;
@@ -125,6 +145,10 @@ namespace System
/// <returns></returns> /// <returns></returns>
public static UriBuilder WithoutDefaultPort(this UriBuilder bld) public static UriBuilder WithoutDefaultPort(this UriBuilder bld)
{ {
if(bld == null)
{
throw new ArgumentNullException(nameof(bld));
}
if (bld.Uri.IsDefaultPort) bld.Port = -1; if (bld.Uri.IsDefaultPort) bld.Port = -1;
return bld; return bld;
} }
@@ -138,6 +162,10 @@ namespace System
/// <returns></returns> /// <returns></returns>
public static UriBuilder WithPathSegment(this UriBuilder bld, string pathSegment) public static UriBuilder WithPathSegment(this UriBuilder bld, string pathSegment)
{ {
if(bld == null)
{
throw new ArgumentNullException(nameof(bld));
}
if(string.IsNullOrWhiteSpace(pathSegment)) if(string.IsNullOrWhiteSpace(pathSegment))
{ {
throw new ArgumentNullException(nameof(pathSegment)); throw new ArgumentNullException(nameof(pathSegment));
@@ -156,6 +184,10 @@ namespace System
/// <returns></returns> /// <returns></returns>
public static UriBuilder WithScheme(this UriBuilder bld, string scheme) public static UriBuilder WithScheme(this UriBuilder bld, string scheme)
{ {
if(bld == null)
{
throw new ArgumentNullException(nameof(bld));
}
if(string.IsNullOrWhiteSpace(scheme)) throw new ArgumentNullException(nameof(scheme)); if(string.IsNullOrWhiteSpace(scheme)) throw new ArgumentNullException(nameof(scheme));
bld.Scheme = scheme; bld.Scheme = scheme;
return bld; return bld;
@@ -170,6 +202,10 @@ namespace System
/// <returns></returns> /// <returns></returns>
public static UriBuilder WithHost(this UriBuilder bld, string host) public static UriBuilder WithHost(this UriBuilder bld, string host)
{ {
if(bld == null)
{
throw new ArgumentNullException(nameof(bld));
}
if(string.IsNullOrWhiteSpace(host)) throw new ArgumentNullException(nameof(host)); if(string.IsNullOrWhiteSpace(host)) throw new ArgumentNullException(nameof(host));
bld.Host = host; bld.Host = host;
return bld; return bld;
@@ -185,6 +221,10 @@ namespace System
/// <returns></returns> /// <returns></returns>
public static UriBuilder UseHttps(this UriBuilder bld, bool predicate = true) public static UriBuilder UseHttps(this UriBuilder bld, bool predicate = true)
{ {
if(bld == null)
{
throw new ArgumentNullException(nameof(bld));
}
bld.Scheme = predicate ? "https" : "http"; bld.Scheme = predicate ? "https" : "http";
return bld; return bld;
} }

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<Authors>Tommy Parnell</Authors> <Authors>Tommy Parnell</Authors>
<TargetFrameworks>netstandard1.1;net40;net45</TargetFrameworks> <TargetFrameworks>netstandard1.1;net40;net45;netstandard2.0</TargetFrameworks>
<AssemblyName>UriBuilder.Fluent</AssemblyName> <AssemblyName>UriBuilder.Fluent</AssemblyName>
<PackageId>UriBuilder.Fluent</PackageId> <PackageId>UriBuilder.Fluent</PackageId>
<PackageTags>Url building;Uri;Uri building;fluent;extension</PackageTags> <PackageTags>Url building;Uri;Uri building;fluent;extension</PackageTags>