@@ -301,6 +301,27 @@ public void GetStandardColumnNameAndNullValueForTraceIdReturnsLogLevelKeyValue()
301301 Assert . Null ( result . Value ) ;
302302 }
303303
304+ [ Fact ]
305+ public void GetStandardColumnNameAndNullValueForTraceIdWithoutAllowNullReturnsLogLevelKeyValueEmpty ( )
306+ {
307+ // Arrange
308+ var traceId = default ( ActivityTraceId ) ;
309+ var logEvent = new LogEvent (
310+ new DateTimeOffset ( 2020 , 1 , 1 , 0 , 0 , 0 , 0 , TimeSpan . Zero ) ,
311+ LogEventLevel . Debug , null , new MessageTemplate ( new List < MessageTemplateToken > ( ) { new TextToken ( "Test message" ) } ) ,
312+ new List < LogEventProperty > ( ) , traceId , ActivitySpanId . CreateRandom ( ) ) ;
313+ var columnOptions = new MSSqlServer . ColumnOptions ( ) ;
314+ columnOptions . TraceId . AllowNull = false ;
315+ SetupSut ( columnOptions , CultureInfo . InvariantCulture ) ;
316+
317+ // Act
318+ var result = _sut . GetStandardColumnNameAndValue ( StandardColumn . TraceId , logEvent ) ;
319+
320+ // Assert
321+ Assert . Equal ( "TraceId" , result . Key ) ;
322+ Assert . Equal ( string . Empty , result . Value ) ;
323+ }
324+
304325 [ Fact ]
305326 public void GetStandardColumnNameAndValueForSpanIdReturnsLogLevelKeyValue ( )
306327 {
@@ -339,6 +360,27 @@ public void GetStandardColumnNameAndNullValueForSpanIdReturnsLogLevelKeyValue()
339360 Assert . Null ( result . Value ) ;
340361 }
341362
363+ [ Fact ]
364+ public void GetStandardColumnNameAndNullValueForSpanIdWithoutAllowNullReturnsLogLevelKeyValueEmpty ( )
365+ {
366+ // Arrange
367+ var spanId = default ( ActivitySpanId ) ;
368+ var logEvent = new LogEvent (
369+ new DateTimeOffset ( 2020 , 1 , 1 , 0 , 0 , 0 , 0 , TimeSpan . Zero ) ,
370+ LogEventLevel . Debug , null , new MessageTemplate ( new List < MessageTemplateToken > ( ) { new TextToken ( "Test message" ) } ) ,
371+ new List < LogEventProperty > ( ) , ActivityTraceId . CreateRandom ( ) , spanId ) ;
372+ var columnOptions = new MSSqlServer . ColumnOptions ( ) ;
373+ columnOptions . SpanId . AllowNull = false ;
374+ SetupSut ( columnOptions , CultureInfo . InvariantCulture ) ;
375+
376+ // Act
377+ var result = _sut . GetStandardColumnNameAndValue ( StandardColumn . SpanId , logEvent ) ;
378+
379+ // Assert
380+ Assert . Equal ( "SpanId" , result . Key ) ;
381+ Assert . Equal ( string . Empty , result . Value ) ;
382+ }
383+
342384 [ Fact ]
343385 public void GetStandardColumnNameAndValueForLogLevelReturnsLogLevelKeyValueAsEnum ( )
344386 {
@@ -487,6 +529,27 @@ public void GetStandardColumnNameAndValueForExceptionWhenCalledWithoutExceptionR
487529 Assert . Null ( result . Value ) ;
488530 }
489531
532+ [ Fact ]
533+ public void GetStandardColumnNameAndValueForExceptionWhenCalledWithoutExceptionAndNotAllowedNullReturnsEmptyValue ( )
534+ {
535+ // Arrange
536+ var logEvent = new LogEvent (
537+ new DateTimeOffset ( 2020 , 1 , 1 , 0 , 0 , 0 , 0 , TimeSpan . Zero ) ,
538+ LogEventLevel . Debug , null , new MessageTemplate ( new List < MessageTemplateToken > ( ) { new TextToken ( "Test message" ) } ) ,
539+ new List < LogEventProperty > ( ) ) ;
540+ var columnOptions = new Serilog . Sinks . MSSqlServer . ColumnOptions ( ) ;
541+ columnOptions . Level . StoreAsEnum = true ;
542+ columnOptions . Exception . AllowNull = false ;
543+ SetupSut ( columnOptions , CultureInfo . InvariantCulture ) ;
544+
545+ // Act
546+ var result = _sut . GetStandardColumnNameAndValue ( StandardColumn . Exception , logEvent ) ;
547+
548+ // Assert
549+ Assert . Equal ( "Exception" , result . Key ) ;
550+ Assert . Equal ( string . Empty , result . Value ) ;
551+ }
552+
490553 [ Fact ]
491554 public void GetStandardColumnNameAndValueForPropertiesUsesRootElementName ( )
492555 {
0 commit comments