diff --git a/Sift/Core/Client.cs b/Sift/Core/Client.cs index a7d8da5c..be45012c 100644 --- a/Sift/Core/Client.cs +++ b/Sift/Core/Client.cs @@ -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; } diff --git a/Test/ClientTest.cs b/Test/ClientTest.cs new file mode 100644 index 00000000..fa764b3c --- /dev/null +++ b/Test/ClientTest.cs @@ -0,0 +1,32 @@ +using Sift; +using Xunit; +using System.Net.Http; + +namespace Test +{ + public class ClientTest + { + [Fact] + public void TestFailsToCreateClientWithAPIKeyNull() + { + Assert.Throws( + () => new Client(null) + ); + Assert.Throws( + () => new Client(null, new HttpClient()) + ); + } + + [Fact] + public void TestFailsToCreateClientWithEmptyAPIKey() + { + Assert.Throws( + () => new Client("") + ); + Assert.Throws( + () => new Client("", new HttpClient()) + ); + } + } + +}