File tree Expand file tree Collapse file tree 2 files changed +57
-2
lines changed
src/GitLabApiClient/Internal/Http
test/GitLabApiClient.Test/Internal/Http Expand file tree Collapse file tree 2 files changed +57
-2
lines changed Original file line number Diff line number Diff line change 1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Net . Http . Headers ;
5
5
using System . Threading . Tasks ;
6
+ using GitLabApiClient . Internal . Utilities ;
6
7
7
8
namespace GitLabApiClient . Internal . Http
8
9
{
@@ -107,7 +108,7 @@ public static T GetFirstHeaderValueOrDefault<T>(
107
108
return toReturn ;
108
109
109
110
string valueString = headerValues . FirstOrDefault ( ) ;
110
- return valueString == null ? toReturn : ( T ) Convert . ChangeType ( valueString , typeof ( T ) ) ;
111
+ return valueString . IsNullOrEmpty ( ) ? toReturn : ( T ) Convert . ChangeType ( valueString , typeof ( T ) ) ;
111
112
}
112
113
}
113
114
}
Original file line number Diff line number Diff line change
1
+ using System . Net ;
2
+ using System . Net . Http ;
3
+ using System . Net . Http . Headers ;
4
+ using FluentAssertions ;
5
+ using GitLabApiClient . Internal . Http ;
6
+ using Xunit ;
7
+
8
+ namespace GitLabApiClient . Test . Internal . Http
9
+ {
10
+ public class HttpResponseHeadersExtensionsTest
11
+ {
12
+ private HttpResponseHeaders GetTestHeaders ( )
13
+ {
14
+ var response = new HttpResponseMessage ( HttpStatusCode . Created ) ;
15
+ response . Headers . Add ( "X-Fifty-Five" , "55" ) ;
16
+ response . Headers . Add ( "X-Empty" , "" ) ;
17
+
18
+ return response . Headers ;
19
+ }
20
+
21
+ [ Fact ]
22
+ public void GetFirstHeaderValueOrDefault_WithEmptyValue_ReturnDefaultValue ( )
23
+ {
24
+ int expected = 0 ;
25
+ var sut = GetTestHeaders ( ) ;
26
+
27
+ int result = sut . GetFirstHeaderValueOrDefault < int > ( "X-Empty" ) ;
28
+
29
+ result . Should ( ) . Be ( expected ) ;
30
+ }
31
+
32
+ [ Fact ]
33
+ public void GetFirstHeaderValueOrDefault_WithNotExistingKey_ReturnDefaultValue ( )
34
+ {
35
+ int expected = 0 ;
36
+ var sut = GetTestHeaders ( ) ;
37
+
38
+ int result = sut . GetFirstHeaderValueOrDefault < int > ( "X-Not-Exists" ) ;
39
+
40
+ result . Should ( ) . Be ( expected ) ;
41
+ }
42
+
43
+ [ Fact ]
44
+ public void GetFirstHeaderValueOrDefault_WithValue_ReturnValue ( )
45
+ {
46
+ int expected = 55 ;
47
+ var sut = GetTestHeaders ( ) ;
48
+
49
+ int result = sut . GetFirstHeaderValueOrDefault < int > ( "X-Fifty-Five" ) ;
50
+
51
+ result . Should ( ) . Be ( expected ) ;
52
+ }
53
+ }
54
+ }
You can’t perform that action at this time.
0 commit comments