@@ -108,5 +108,75 @@ public void WartEvent_GetResponseObject_ShouldDeserializeJsonResponse()
108108 // Assert
109109 Assert . NotNull ( deserializedResponse ) ;
110110 }
111+
112+ [ Fact ]
113+ public void WartEvent_Constructor_NullParameters_DefaultsToEmpty ( )
114+ {
115+ // Act
116+ var wartEvent = new WartEvent ( null ! , null ! , null ! ) ;
117+
118+ // Assert
119+ Assert . Equal ( string . Empty , wartEvent . HttpMethod ) ;
120+ Assert . Equal ( string . Empty , wartEvent . HttpPath ) ;
121+ Assert . Equal ( string . Empty , wartEvent . RemoteAddress ) ;
122+ }
123+
124+ [ Fact ]
125+ public void WartEvent_FullConstructor_NullRequestResponse_DoesNotThrow ( )
126+ {
127+ // Act
128+ var wartEvent = new WartEvent ( null , null , "PUT" , "/api/items" , "10.0.0.1" ) ;
129+
130+ // Assert
131+ Assert . NotEqual ( Guid . Empty , wartEvent . EventId ) ;
132+ Assert . Equal ( "PUT" , wartEvent . HttpMethod ) ;
133+ }
134+
135+ [ Fact ]
136+ public void WartEvent_ToDictionary_ContainsAllKeys ( )
137+ {
138+ // Arrange
139+ var wartEvent = new WartEvent ( "DELETE" , "/api/items/1" , "192.168.0.1" )
140+ {
141+ ExtraInfo = "test-info"
142+ } ;
143+
144+ // Act
145+ var dict = wartEvent . ToDictionary ( ) ;
146+
147+ // Assert
148+ Assert . Equal ( 9 , dict . Count ) ;
149+ Assert . Equal ( wartEvent . EventId , dict [ "EventId" ] ) ;
150+ Assert . Equal ( "DELETE" , dict [ "HttpMethod" ] ) ;
151+ Assert . Equal ( "/api/items/1" , dict [ "HttpPath" ] ) ;
152+ Assert . Equal ( "192.168.0.1" , dict [ "RemoteAddress" ] ) ;
153+ Assert . Equal ( "test-info" , dict [ "ExtraInfo" ] ) ;
154+ Assert . True ( dict . ContainsKey ( "TimeStamp" ) ) ;
155+ Assert . True ( dict . ContainsKey ( "UtcTimeStamp" ) ) ;
156+ Assert . True ( dict . ContainsKey ( "JsonRequestPayload" ) ) ;
157+ Assert . True ( dict . ContainsKey ( "JsonResponsePayload" ) ) ;
158+ }
159+
160+ [ Fact ]
161+ public void WartEvent_Timestamps_AreConsistent ( )
162+ {
163+ // Arrange & Act
164+ var before = DateTime . UtcNow ;
165+ var wartEvent = new WartEvent ( "GET" , "/" , "::1" ) ;
166+ var after = DateTime . UtcNow ;
167+
168+ // Assert
169+ Assert . InRange ( wartEvent . UtcTimeStamp , before , after ) ;
170+ Assert . Equal ( wartEvent . UtcTimeStamp . ToLocalTime ( ) , wartEvent . TimeStamp ) ;
171+ }
172+
173+ [ Fact ]
174+ public void WartEvent_EventId_IsUnique ( )
175+ {
176+ var a = new WartEvent ( "GET" , "/" , "::1" ) ;
177+ var b = new WartEvent ( "GET" , "/" , "::1" ) ;
178+
179+ Assert . NotEqual ( a . EventId , b . EventId ) ;
180+ }
111181 }
112182}
0 commit comments