@@ -17,11 +17,16 @@ public ClientIpEnricherTests()
1717 _contextAccessor . HttpContext . Returns ( httpContext ) ;
1818 }
1919
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 )
2226 {
2327 // Arrange
24- _contextAccessor . HttpContext . Connection . RemoteIpAddress = IPAddress . Parse ( "::1" ) ;
28+ var ipAddress = IPAddress . Parse ( ip ) ;
29+ _contextAccessor . HttpContext . Connection . RemoteIpAddress = ipAddress ;
2530
2631 var ipEnricher = new ClientIpEnricher ( _contextAccessor ) ;
2732
@@ -37,7 +42,7 @@ public void When_Enrich_Log_Event_With_IpEnricher_Should_Contain_ClientIp_Proper
3742 // Assert
3843 Assert . NotNull ( evt ) ;
3944 Assert . True ( evt . Properties . ContainsKey ( "ClientIp" ) ) ;
40- Assert . Equal ( "::1" , evt . Properties [ "ClientIp" ] . LiteralValue ( ) ) ;
45+ Assert . Equal ( ipAddress . ToString ( ) , evt . Properties [ "ClientIp" ] . LiteralValue ( ) ) ;
4146 }
4247
4348 [ Fact ]
@@ -63,12 +68,17 @@ public void When_Enrich_Log_Event_With_IpEnricher_And_Log_More_Than_Once_Should_
6368 Assert . Equal ( IPAddress . Loopback . ToString ( ) , evt . Properties [ "ClientIp" ] . LiteralValue ( ) ) ;
6469 }
6570
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 )
6877 {
6978 //Arrange
79+ var ipAddress = IPAddress . Parse ( ip ) ;
7080 _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 ( ) ) ;
7282
7383 var ipEnricher = new ClientIpEnricher ( _contextAccessor ) ;
7484
@@ -84,7 +94,7 @@ public void When_Enrich_Log_Event_With_IpEnricher_AndRequest_Contain_ForwardHead
8494 // Assert
8595 Assert . NotNull ( evt ) ;
8696 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 ( ) ) ;
8898 }
8999
90100 [ Fact ]
0 commit comments