File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,22 @@ public class Client : IDisposable
1515
1616 public Client ( String apiKey )
1717 {
18+ if ( string . IsNullOrWhiteSpace ( apiKey ) )
19+ {
20+ throw new ArgumentNullException ( nameof ( apiKey ) ) ;
21+ }
22+
1823 this . apiKey = apiKey ;
1924 this . http = new HttpClient ( ) ;
2025 }
2126
22- public Client ( String apiKey , HttpClient http ) {
27+ public Client ( String apiKey , HttpClient http )
28+ {
29+ if ( string . IsNullOrWhiteSpace ( apiKey ) )
30+ {
31+ throw new ArgumentNullException ( nameof ( apiKey ) ) ;
32+ }
33+
2334 this . apiKey = apiKey ;
2435 this . http = http ;
2536 }
Original file line number Diff line number Diff line change 1+ using Sift ;
2+ using Xunit ;
3+ using System . Net . Http ;
4+
5+ namespace Test
6+ {
7+ public class ClientTest
8+ {
9+ [ Fact ]
10+ public void TestFailsToCreateClientWithAPIKeyNull ( )
11+ {
12+ Assert . Throws < ArgumentNullException > (
13+ ( ) => new Client ( null )
14+ ) ;
15+ Assert . Throws < ArgumentNullException > (
16+ ( ) => new Client ( null , new HttpClient ( ) )
17+ ) ;
18+ }
19+
20+ [ Fact ]
21+ public void TestFailsToCreateClientWithEmptyAPIKey ( )
22+ {
23+ Assert . Throws < ArgumentNullException > (
24+ ( ) => new Client ( "" )
25+ ) ;
26+ Assert . Throws < ArgumentNullException > (
27+ ( ) => new Client ( "" , new HttpClient ( ) )
28+ ) ;
29+ }
30+ }
31+
32+ }
You can’t perform that action at this time.
0 commit comments