@@ -115,6 +115,25 @@ public void SimplifyDictionaryHandlesOptionOmitElementIfEmpty()
115
115
Assert . Equal ( "<dictionary><item key='Key2'>Value2</item></dictionary>" , result ) ;
116
116
}
117
117
118
+ [ Fact ]
119
+ public void SimplifyDictionaryUsesCustomItemElementName ( )
120
+ {
121
+ // Arrange
122
+ var input = new DictionaryValue ( new List < KeyValuePair < ScalarValue , LogEventPropertyValue > >
123
+ {
124
+ new KeyValuePair < ScalarValue , LogEventPropertyValue > ( new ScalarValue ( "Key1" ) , new ScalarValue ( "Value1" ) ) ,
125
+ new KeyValuePair < ScalarValue , LogEventPropertyValue > ( new ScalarValue ( "Key2" ) , new ScalarValue ( 2 ) )
126
+ } ) ;
127
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { ItemElementName = "customitem" } ;
128
+ var sut = new XmlPropertyFormatter ( ) ;
129
+
130
+ // Act
131
+ var result = sut . Simplify ( input , options ) ;
132
+
133
+ // Assert
134
+ Assert . Equal ( "<dictionary><customitem key='Key1'>Value1</customitem><customitem key='Key2'>2</customitem></dictionary>" , result ) ;
135
+ }
136
+
118
137
[ Fact ]
119
138
public void SimplifyDictionaryHandlesOptionOmitDictionaryContainerElement ( )
120
139
{
@@ -153,6 +172,253 @@ public void SimplifyDictionaryUsesCustomDictionaryElementName()
153
172
Assert . Equal ( "<list><item key='Key1'>Value1</item><item key='Key2'>Value2</item></list>" , result ) ;
154
173
}
155
174
175
+ [ Fact ]
176
+ public void SimplifySequenceRendersElements ( )
177
+ {
178
+ // Arrange
179
+ var input = new SequenceValue ( new List < LogEventPropertyValue >
180
+ {
181
+ new ScalarValue ( "Value1" ) ,
182
+ new ScalarValue ( 2 )
183
+ } ) ;
184
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions ( ) ;
185
+ var sut = new XmlPropertyFormatter ( ) ;
186
+
187
+ // Act
188
+ var result = sut . Simplify ( input , options ) ;
189
+
190
+ // Assert
191
+ Assert . Equal ( "<sequence><item>Value1</item><item>2</item></sequence>" , result ) ;
192
+ }
193
+
194
+ [ Fact ]
195
+ public void SimplifySequenceReplacesXmlInvalidCharsInValue ( )
196
+ {
197
+ // Arrange
198
+ var input = new SequenceValue ( new List < LogEventPropertyValue >
199
+ {
200
+ new ScalarValue ( "some<allowed>words&inbetween" )
201
+ } ) ;
202
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions ( ) ;
203
+ var sut = new XmlPropertyFormatter ( ) ;
204
+
205
+ // Act
206
+ var result = sut . Simplify ( input , options ) ;
207
+
208
+ // Assert
209
+ Assert . Equal ( "<sequence><item>some<allowed>words&inbetween</item></sequence>" , result ) ;
210
+ }
211
+
212
+ [ Fact ]
213
+ public void SimplifySequenceHandlesOptionOmitElementIfEmpty ( )
214
+ {
215
+ // Arrange
216
+ var input = new SequenceValue ( new List < LogEventPropertyValue >
217
+ {
218
+ new ScalarValue ( string . Empty ) ,
219
+ new ScalarValue ( "Value2" ) ,
220
+ new ScalarValue ( null )
221
+ } ) ;
222
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { OmitElementIfEmpty = true } ;
223
+ var sut = new XmlPropertyFormatter ( ) ;
224
+
225
+ // Act
226
+ var result = sut . Simplify ( input , options ) ;
227
+
228
+ // Assert
229
+ Assert . Equal ( "<sequence><item>Value2</item></sequence>" , result ) ;
230
+ }
231
+
232
+ [ Fact ]
233
+ public void SimplifySequenceHandlesOptionOmitSequenceContainerElement ( )
234
+ {
235
+ // Arrange
236
+ var input = new SequenceValue ( new List < LogEventPropertyValue >
237
+ {
238
+ new ScalarValue ( "Value1" ) ,
239
+ new ScalarValue ( "Value2" )
240
+ } ) ;
241
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { OmitSequenceContainerElement = true } ;
242
+ var sut = new XmlPropertyFormatter ( ) ;
243
+
244
+ // Act
245
+ var result = sut . Simplify ( input , options ) ;
246
+
247
+ // Assert
248
+ Assert . Equal ( "<item>Value1</item><item>Value2</item>" , result ) ;
249
+ }
250
+
251
+ [ Fact ]
252
+ public void SimplifySequenceUsesCustomSequenceElementName ( )
253
+ {
254
+ // Arrange
255
+ var input = new SequenceValue ( new List < LogEventPropertyValue >
256
+ {
257
+ new ScalarValue ( "Value1" ) ,
258
+ new ScalarValue ( "Value2" )
259
+ } ) ;
260
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { SequenceElementName = "list" } ;
261
+ var sut = new XmlPropertyFormatter ( ) ;
262
+
263
+ // Act
264
+ var result = sut . Simplify ( input , options ) ;
265
+
266
+ // Assert
267
+ Assert . Equal ( "<list><item>Value1</item><item>Value2</item></list>" , result ) ;
268
+ }
269
+
270
+ [ Fact ]
271
+ public void SimplifySequenceUsesCustomItemElementName ( )
272
+ {
273
+ // Arrange
274
+ var input = new SequenceValue ( new List < LogEventPropertyValue >
275
+ {
276
+ new ScalarValue ( "Value1" ) ,
277
+ new ScalarValue ( "Value2" )
278
+ } ) ;
279
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { ItemElementName = "element" } ;
280
+ var sut = new XmlPropertyFormatter ( ) ;
281
+
282
+ // Act
283
+ var result = sut . Simplify ( input , options ) ;
284
+
285
+ // Assert
286
+ Assert . Equal ( "<sequence><element>Value1</element><element>Value2</element></sequence>" , result ) ;
287
+ }
288
+
289
+ [ Fact ]
290
+ public void SimplifyStructureRendersElements ( )
291
+ {
292
+ // Arrange
293
+ var input = new StructureValue ( new List < LogEventProperty >
294
+ {
295
+ new LogEventProperty ( "Key1" , new ScalarValue ( "Value1" ) ) ,
296
+ new LogEventProperty ( "Key2" , new ScalarValue ( 2 ) )
297
+ } ) ;
298
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions ( ) ;
299
+ var sut = new XmlPropertyFormatter ( ) ;
300
+
301
+ // Act
302
+ var result = sut . Simplify ( input , options ) ;
303
+
304
+ // Assert
305
+ Assert . Equal ( "<structure type=''><property key='Key1'>Value1</property><property key='Key2'>2</property></structure>" , result ) ;
306
+ }
307
+
308
+ [ Fact ]
309
+ public void SimplifyStructureHandlesOptionUsePropertyKeyAsElementName ( )
310
+ {
311
+ // Arrange
312
+ var input = new StructureValue ( new List < LogEventProperty >
313
+ {
314
+ new LogEventProperty ( "Key1" , new ScalarValue ( "Value1" ) ) ,
315
+ new LogEventProperty ( "Key2" , new ScalarValue ( 2 ) )
316
+ } , "structuretype" ) ;
317
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { UsePropertyKeyAsElementName = true } ;
318
+ var sut = new XmlPropertyFormatter ( ) ;
319
+
320
+ // Act
321
+ var result = sut . Simplify ( input , options ) ;
322
+
323
+ // Assert
324
+ Assert . Equal ( "<structuretype><Key1>Value1</Key1><Key2>2</Key2></structuretype>" , result ) ;
325
+ }
326
+
327
+ [ Fact ]
328
+ public void SimplifyStructureFixesElementNamesIfUsePropertyKeyAsElementNameIsTrue ( )
329
+ {
330
+ // Arrange
331
+ var input = new StructureValue ( new List < LogEventProperty >
332
+ {
333
+ new LogEventProperty ( "xml Key With Space" , new ScalarValue ( "Value1" ) )
334
+ } , "5structure\t type" ) ;
335
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { UsePropertyKeyAsElementName = true } ;
336
+ var sut = new XmlPropertyFormatter ( ) ;
337
+
338
+ // Act
339
+ var result = sut . Simplify ( input , options ) ;
340
+
341
+ // Assert
342
+ Assert . Equal ( "<x5structure_type><xxml_Key_With_Space>Value1</xxml_Key_With_Space></x5structure_type>" , result ) ;
343
+ }
344
+
345
+ [ Fact ]
346
+ public void SimplifyStructureHandlesOptionOmitElementIfEmpty ( )
347
+ {
348
+ // Arrange
349
+ var input = new StructureValue ( new List < LogEventProperty >
350
+ {
351
+ new LogEventProperty ( "Key1" , new ScalarValue ( string . Empty ) ) ,
352
+ new LogEventProperty ( "Key2" , new ScalarValue ( "Value2" ) ) ,
353
+ new LogEventProperty ( "Key3" , new ScalarValue ( null ) )
354
+ } ) ;
355
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { OmitElementIfEmpty = true } ;
356
+ var sut = new XmlPropertyFormatter ( ) ;
357
+
358
+ // Act
359
+ var result = sut . Simplify ( input , options ) ;
360
+
361
+ // Assert
362
+ Assert . Equal ( "<structure type=''><property key='Key2'>Value2</property></structure>" , result ) ;
363
+ }
364
+
365
+ [ Fact ]
366
+ public void SimplifyStructureUsesCustomPropertyElementName ( )
367
+ {
368
+ // Arrange
369
+ var input = new StructureValue ( new List < LogEventProperty >
370
+ {
371
+ new LogEventProperty ( "Key1" , new ScalarValue ( "Value1" ) ) ,
372
+ new LogEventProperty ( "Key2" , new ScalarValue ( 2 ) )
373
+ } ) ;
374
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { PropertyElementName = "propertyitem" } ;
375
+ var sut = new XmlPropertyFormatter ( ) ;
376
+
377
+ // Act
378
+ var result = sut . Simplify ( input , options ) ;
379
+
380
+ // Assert
381
+ Assert . Equal ( "<structure type=''><propertyitem key='Key1'>Value1</propertyitem><propertyitem key='Key2'>2</propertyitem></structure>" , result ) ;
382
+ }
383
+
384
+ [ Fact ]
385
+ public void SimplifyStructureHandlesOptionOmitStructureContainerElement ( )
386
+ {
387
+ // Arrange
388
+ var input = new StructureValue ( new List < LogEventProperty >
389
+ {
390
+ new LogEventProperty ( "Key1" , new ScalarValue ( "Value1" ) ) ,
391
+ new LogEventProperty ( "Key2" , new ScalarValue ( 2 ) )
392
+ } ) ;
393
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { OmitStructureContainerElement = true } ;
394
+ var sut = new XmlPropertyFormatter ( ) ;
395
+
396
+ // Act
397
+ var result = sut . Simplify ( input , options ) ;
398
+
399
+ // Assert
400
+ Assert . Equal ( "<property key='Key1'>Value1</property><property key='Key2'>2</property>" , result ) ;
401
+ }
402
+
403
+ [ Fact ]
404
+ public void SimplifyStructureHandlesUsesCustomStructureElementName ( )
405
+ {
406
+ // Arrange
407
+ var input = new StructureValue ( new List < LogEventProperty >
408
+ {
409
+ new LogEventProperty ( "Key1" , new ScalarValue ( "Value1" ) ) ,
410
+ new LogEventProperty ( "Key2" , new ScalarValue ( 2 ) )
411
+ } ) ;
412
+ var options = new Serilog . Sinks . MSSqlServer . ColumnOptions . PropertiesColumnOptions { StructureElementName = "propertylist" } ;
413
+ var sut = new XmlPropertyFormatter ( ) ;
414
+
415
+ // Act
416
+ var result = sut . Simplify ( input , options ) ;
417
+
418
+ // Assert
419
+ Assert . Equal ( "<propertylist type=''><property key='Key1'>Value1</property><property key='Key2'>2</property></propertylist>" , result ) ;
420
+ }
421
+
156
422
[ Fact ]
157
423
public void GetValidElementNameReturnsValidNameOnNull ( )
158
424
{
0 commit comments