Skip to content
13 changes: 12 additions & 1 deletion Sift/Core/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,22 @@ public class Client : IDisposable

public Client(String apiKey)
{
if (string.IsNullOrWhiteSpace(apiKey))
{
throw new ArgumentNullException(nameof(apiKey));
}

this.apiKey = apiKey;
this.http = new HttpClient();
}

public Client(String apiKey, HttpClient http) {
public Client(String apiKey, HttpClient http)
{
if (string.IsNullOrWhiteSpace(apiKey))
{
throw new ArgumentNullException(nameof(apiKey));
}

this.apiKey = apiKey;
this.http = http;
}
Expand Down
32 changes: 32 additions & 0 deletions Test/ClientTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Sift;
using Xunit;
using System.Net.Http;

namespace Test
{
public class ClientTest
{
[Fact]
public void TestFailsToCreateClientWithAPIKeyNull()
{
Assert.Throws<ArgumentNullException>(
() => new Client(null)
);
Assert.Throws<ArgumentNullException>(
() => new Client(null, new HttpClient())
);
}

[Fact]
public void TestFailsToCreateClientWithEmptyAPIKey()
{
Assert.Throws<ArgumentNullException>(
() => new Client("")
);
Assert.Throws<ArgumentNullException>(
() => new Client("", new HttpClient())
);
}
}

}
Loading