@@ -17,11 +17,16 @@ public ClientIpEnricherTests()
17
17
_contextAccessor . HttpContext . Returns ( httpContext ) ;
18
18
}
19
19
20
- [ Fact ]
21
- public void When_Enrich_Log_Event_With_IpEnricher_Should_Contain_ClientIp_Property ( )
20
+ [ Theory ]
21
+ [ InlineData ( "::1" ) ]
22
+ [ InlineData ( "192.168.1.1" ) ]
23
+ [ InlineData ( "2001:0db8:85a3:0000:0000:8a2e:0370:7334" ) ]
24
+ [ InlineData ( "2001:db8:85a3:8d3:1319:8a2e:370:7348" ) ]
25
+ public void When_Enrich_Log_Event_With_IpEnricher_Should_Contain_ClientIp_Property ( string ip )
22
26
{
23
27
// Arrange
24
- _contextAccessor . HttpContext . Connection . RemoteIpAddress = IPAddress . Parse ( "::1" ) ;
28
+ var ipAddress = IPAddress . Parse ( ip ) ;
29
+ _contextAccessor . HttpContext . Connection . RemoteIpAddress = ipAddress ;
25
30
26
31
var ipEnricher = new ClientIpEnricher ( _contextAccessor ) ;
27
32
@@ -37,7 +42,7 @@ public void When_Enrich_Log_Event_With_IpEnricher_Should_Contain_ClientIp_Proper
37
42
// Assert
38
43
Assert . NotNull ( evt ) ;
39
44
Assert . True ( evt . Properties . ContainsKey ( "ClientIp" ) ) ;
40
- Assert . Equal ( "::1" , evt . Properties [ "ClientIp" ] . LiteralValue ( ) ) ;
45
+ Assert . Equal ( ipAddress . ToString ( ) , evt . Properties [ "ClientIp" ] . LiteralValue ( ) ) ;
41
46
}
42
47
43
48
[ Fact ]
@@ -63,12 +68,17 @@ public void When_Enrich_Log_Event_With_IpEnricher_And_Log_More_Than_Once_Should_
63
68
Assert . Equal ( IPAddress . Loopback . ToString ( ) , evt . Properties [ "ClientIp" ] . LiteralValue ( ) ) ;
64
69
}
65
70
66
- [ Fact ]
67
- public void When_Enrich_Log_Event_With_IpEnricher_AndRequest_Contain_ForwardHeader_Should_Read_ClientIp_Value_From_Header_Value ( )
71
+ [ Theory ]
72
+ [ InlineData ( "::1" ) ]
73
+ [ InlineData ( "192.168.1.1" ) ]
74
+ [ InlineData ( "2001:0db8:85a3:0000:0000:8a2e:0370:7334" ) ]
75
+ [ InlineData ( "2001:db8:85a3:8d3:1319:8a2e:370:7348" ) ]
76
+ public void When_Enrich_Log_Event_With_IpEnricher_AndRequest_Contain_ForwardHeader_Should_Read_ClientIp_Value_From_Header_Value ( string ip )
68
77
{
69
78
//Arrange
79
+ var ipAddress = IPAddress . Parse ( ip ) ;
70
80
_contextAccessor . HttpContext . Connection . RemoteIpAddress = IPAddress . Loopback ;
71
- _contextAccessor . HttpContext . Request . Headers . Add ( ClinetIpConfiguration . XForwardHeaderName , IPAddress . Broadcast . ToString ( ) ) ;
81
+ _contextAccessor . HttpContext . Request . Headers . Add ( ClinetIpConfiguration . XForwardHeaderName , ipAddress . ToString ( ) ) ;
72
82
73
83
var ipEnricher = new ClientIpEnricher ( _contextAccessor ) ;
74
84
@@ -84,7 +94,7 @@ public void When_Enrich_Log_Event_With_IpEnricher_AndRequest_Contain_ForwardHead
84
94
// Assert
85
95
Assert . NotNull ( evt ) ;
86
96
Assert . True ( evt . Properties . ContainsKey ( "ClientIp" ) ) ;
87
- Assert . Equal ( IPAddress . Broadcast . ToString ( ) , evt . Properties [ "ClientIp" ] . LiteralValue ( ) ) ;
97
+ Assert . Equal ( ipAddress . ToString ( ) , evt . Properties [ "ClientIp" ] . LiteralValue ( ) ) ;
88
98
}
89
99
90
100
[ Fact ]
0 commit comments