From ca9b7be98df1bc9ed77338db0ed3b60e2ac1ab74 Mon Sep 17 00:00:00 2001 From: Eldar Singin Date: Tue, 31 Dec 2024 16:12:21 +0200 Subject: [PATCH 1/7] [API-7676]: Validate apiKey is not null when creating a Client --- Sift/Core/Client.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sift/Core/Client.cs b/Sift/Core/Client.cs index a7d8da5c..da666f64 100644 --- a/Sift/Core/Client.cs +++ b/Sift/Core/Client.cs @@ -15,11 +15,22 @@ public class Client : IDisposable public Client(String apiKey) { + if (apiKey is null) + { + 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 (apiKey is null) + { + throw new ArgumentNullException(nameof(apiKey)); + } + this.apiKey = apiKey; this.http = http; } From d8e5ab7d7419b3c22e177b9001893e26f06ab99a Mon Sep 17 00:00:00 2001 From: Eldar Singin Date: Tue, 31 Dec 2024 16:16:22 +0200 Subject: [PATCH 2/7] [API-7676]: Validate apiKey is not null when creating a Client --- Sift/Core/Client.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sift/Core/Client.cs b/Sift/Core/Client.cs index da666f64..be45012c 100644 --- a/Sift/Core/Client.cs +++ b/Sift/Core/Client.cs @@ -15,7 +15,7 @@ public class Client : IDisposable public Client(String apiKey) { - if (apiKey is null) + if (string.IsNullOrWhiteSpace(apiKey)) { throw new ArgumentNullException(nameof(apiKey)); } @@ -26,7 +26,7 @@ public Client(String apiKey) public Client(String apiKey, HttpClient http) { - if (apiKey is null) + if (string.IsNullOrWhiteSpace(apiKey)) { throw new ArgumentNullException(nameof(apiKey)); } From a65bb8fb6fed45a93cfbc4edad96afde9eed93bc Mon Sep 17 00:00:00 2001 From: Eldar Singin Date: Tue, 31 Dec 2024 16:24:41 +0200 Subject: [PATCH 3/7] [API-7676]: Validate apiKey is not null when creating a Client --- Test/Client.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Test/Client.cs diff --git a/Test/Client.cs b/Test/Client.cs new file mode 100644 index 00000000..32d4d0e9 --- /dev/null +++ b/Test/Client.cs @@ -0,0 +1,20 @@ +using Sift; +using Sift.Core; +using System.Text; +using Xunit; + +namespace Test +{ + public class Client + { + [Fact] + public void TestCreateClientWithAPIKeyNull() + { + Assert.Throws( + () => new Client(null) + ); + + } + } + +} From 81256391f1da9fc37e26836e0fefb1833df2b1b9 Mon Sep 17 00:00:00 2001 From: Eldar Singin Date: Tue, 31 Dec 2024 16:29:14 +0200 Subject: [PATCH 4/7] [API-7676]: Validate apiKey is not null when creating a Client --- Test/Client.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Client.cs b/Test/Client.cs index 32d4d0e9..1a018e14 100644 --- a/Test/Client.cs +++ b/Test/Client.cs @@ -5,7 +5,7 @@ namespace Test { - public class Client + public class ClientTest { [Fact] public void TestCreateClientWithAPIKeyNull() From 17324f7ceac99bf59b838107488f71e23e538c6d Mon Sep 17 00:00:00 2001 From: Eldar Singin Date: Tue, 31 Dec 2024 16:30:52 +0200 Subject: [PATCH 5/7] [API-7676]: Validate apiKey is not null when creating a Client --- Sift/Core/Client.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sift/Core/Client.cs b/Sift/Core/Client.cs index be45012c..be1ed2ce 100644 --- a/Sift/Core/Client.cs +++ b/Sift/Core/Client.cs @@ -15,10 +15,10 @@ public class Client : IDisposable public Client(String apiKey) { - if (string.IsNullOrWhiteSpace(apiKey)) - { - throw new ArgumentNullException(nameof(apiKey)); - } +// if (string.IsNullOrWhiteSpace(apiKey)) +// { +// throw new ArgumentNullException(nameof(apiKey)); +// } this.apiKey = apiKey; this.http = new HttpClient(); From 90905c3001e647a75dc2a02ac5856801ad9ec666 Mon Sep 17 00:00:00 2001 From: Eldar Singin Date: Tue, 31 Dec 2024 16:36:42 +0200 Subject: [PATCH 6/7] [API-7676]: Validate apiKey is not null when creating a Client --- Sift/Core/Client.cs | 16 ++++++++-------- Test/Client.cs | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Sift/Core/Client.cs b/Sift/Core/Client.cs index be1ed2ce..0c45cfea 100644 --- a/Sift/Core/Client.cs +++ b/Sift/Core/Client.cs @@ -15,10 +15,10 @@ public class Client : IDisposable public Client(String apiKey) { -// if (string.IsNullOrWhiteSpace(apiKey)) -// { -// throw new ArgumentNullException(nameof(apiKey)); -// } + if (string.IsNullOrWhiteSpace(apiKey)) + { + throw new ArgumentNullException(nameof(apiKey)); + } this.apiKey = apiKey; this.http = new HttpClient(); @@ -26,10 +26,10 @@ public Client(String apiKey) public Client(String apiKey, HttpClient http) { - if (string.IsNullOrWhiteSpace(apiKey)) - { - throw new ArgumentNullException(nameof(apiKey)); - } +// if (string.IsNullOrWhiteSpace(apiKey)) +// { +// throw new ArgumentNullException(nameof(apiKey)); +// } this.apiKey = apiKey; this.http = http; diff --git a/Test/Client.cs b/Test/Client.cs index 1a018e14..7a47576e 100644 --- a/Test/Client.cs +++ b/Test/Client.cs @@ -1,19 +1,31 @@ using Sift; -using Sift.Core; -using System.Text; using Xunit; +using System.Net.Http; namespace Test { public class ClientTest { [Fact] - public void TestCreateClientWithAPIKeyNull() + 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()) + ); } } From 20e5c13023892b13654e3da0ae49a0283e44bc52 Mon Sep 17 00:00:00 2001 From: Eldar Singin Date: Tue, 31 Dec 2024 16:40:47 +0200 Subject: [PATCH 7/7] [API-7676]: Validate apiKey is not null when creating a Client --- Sift/Core/Client.cs | 8 ++-- Test/{Client.cs => ClientTest.cs} | 64 +++++++++++++++---------------- 2 files changed, 36 insertions(+), 36 deletions(-) rename Test/{Client.cs => ClientTest.cs} (95%) diff --git a/Sift/Core/Client.cs b/Sift/Core/Client.cs index 0c45cfea..be45012c 100644 --- a/Sift/Core/Client.cs +++ b/Sift/Core/Client.cs @@ -26,10 +26,10 @@ public Client(String apiKey) public Client(String apiKey, HttpClient http) { -// if (string.IsNullOrWhiteSpace(apiKey)) -// { -// throw new ArgumentNullException(nameof(apiKey)); -// } + if (string.IsNullOrWhiteSpace(apiKey)) + { + throw new ArgumentNullException(nameof(apiKey)); + } this.apiKey = apiKey; this.http = http; diff --git a/Test/Client.cs b/Test/ClientTest.cs similarity index 95% rename from Test/Client.cs rename to Test/ClientTest.cs index 7a47576e..fa764b3c 100644 --- a/Test/Client.cs +++ b/Test/ClientTest.cs @@ -1,32 +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()) - ); - } - } - -} +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()) + ); + } + } + +}