@@ -299,6 +299,32 @@ public void Verify_a_structured_message_using_wildcards_with_parameters_names_an
299
299
. WithMessage ( "*.LogInformation*" ) ;
300
300
}
301
301
302
+ [ Fact ]
303
+ public void Verify_a_message_using_wildcards_with_interpolated_message_it_verifies ( )
304
+ {
305
+ var loggerMock = new Mock < ILogger < object > > ( ) ;
306
+ var interpolatedMessageArg = "Arg" ;
307
+ loggerMock . Object . LogInformation ( $ "Test message { interpolatedMessageArg } ") ;
308
+
309
+ Action act = ( ) => loggerMock . VerifyLog ( c => c . LogInformation ( $ "*{ interpolatedMessageArg } *") ) ;
310
+
311
+ act . Should ( ) . NotThrow ( ) ;
312
+ }
313
+
314
+ [ Fact ]
315
+ public void Verify_a_message_using_wildcards_with_interpolated_message_it_throws ( )
316
+ {
317
+ var loggerMock = new Mock < ILogger < object > > ( ) ;
318
+ var interpolatedMessageArg1 = "Arg 1" ;
319
+ var interpolatedMessageArg2 = "Arg 2" ;
320
+ loggerMock . Object . LogInformation ( $ "Test message { interpolatedMessageArg1 } ") ;
321
+
322
+ Action act = ( ) => loggerMock . VerifyLog ( c => c . LogInformation ( $ "*{ interpolatedMessageArg2 } *") ) ;
323
+
324
+ act . Should ( ) . ThrowExactly < VerifyLogException > ( )
325
+ . WithMessage ( "*.LogInformation*" ) ;
326
+ }
327
+
302
328
[ Fact ]
303
329
public void Verify_a_structured_message_when_parameters_differ_it_throws ( )
304
330
{
@@ -390,10 +416,36 @@ public void Verify_a_message_with_a_different_one_from_a_method_call_it_throws()
390
416
391
417
act . Should ( ) . ThrowExactly < VerifyLogException > ( )
392
418
. WithMessage ( "*.LogInformation(VerifyLogExtensionsTests.GetNotAMessage(), new[] { })*" )
393
- . Which . InnerException ! . Message . Should ( ) . Match ( "*logger => logger.Log<It.IsAnyType>(LogLevel.Information, It.IsAny<EventId>(), It.Is<It.IsAnyType>((v, t) => VerifyLogExtensions.CompareMessages(v.ToString(), VerifyLogExpression, \" Not a test message\" )), It.IsAny<Exception>(), (Func<It.IsAnyType, Exception, string>)It.IsAny<object>())*" ) ;
419
+ . Which . InnerException ! . Message . Should ( ) . Match ( "*logger => logger.Log<It.IsAnyType>(LogLevel.Information, It.IsAny<EventId>(), It.Is<It.IsAnyType>((v, t) => VerifyLogExtensions.CompareMessages(\" Not a test message\" , VerifyLogExpression, v.ToString() )), It.IsAny<Exception>(), (Func<It.IsAnyType, Exception, string>)It.IsAny<object>())*" ) ;
394
420
}
395
421
string GetNotAMessage ( ) => "Not a test message" ;
396
422
423
+ [ Fact ]
424
+ public void Verify_a_wildcard_message_with_method_call_it_verifies ( )
425
+ {
426
+ var loggerMock = new Mock < ILogger < object > > ( ) ;
427
+ loggerMock . Object . LogInformation ( "Test message" ) ;
428
+
429
+ Action act = ( ) => loggerMock . VerifyLog ( c => c . LogInformation ( GetWildcardMessage ( ) ) ) ;
430
+
431
+ act . Should ( ) . NotThrow ( ) ;
432
+ }
433
+ string GetWildcardMessage ( ) => "*message*" ;
434
+
435
+ [ Fact ]
436
+ public void Verify_a_wildcard_message_with_a_different_one_from_a_method_call_it_throws ( )
437
+ {
438
+ var loggerMock = new Mock < ILogger < object > > ( ) ;
439
+ loggerMock . Object . LogInformation ( "Test message" ) ;
440
+
441
+ Action act = ( ) => loggerMock . VerifyLog ( c => c . LogInformation ( GetWildcardNotAMessage ( ) ) ) ;
442
+
443
+ act . Should ( ) . ThrowExactly < VerifyLogException > ( )
444
+ . WithMessage ( "*.LogInformation(VerifyLogExtensionsTests.GetWildcardNotAMessage(), new[] { })*" )
445
+ . Which . InnerException ! . Message . Should ( ) . Match ( "*logger => logger.Log<It.IsAnyType>(LogLevel.Information, It.IsAny<EventId>(), It.Is<It.IsAnyType>((v, t) => VerifyLogExtensions.CompareMessages(\" *no match*\" , VerifyLogExpression, v.ToString())), It.IsAny<Exception>(), (Func<It.IsAnyType, Exception, string>)It.IsAny<object>())*" ) ;
446
+ }
447
+ string GetWildcardNotAMessage ( ) => "*no match*" ;
448
+
397
449
[ Fact ]
398
450
public void Verify_a_message_one_constructed_call_it_throws ( )
399
451
{
@@ -404,7 +456,7 @@ public void Verify_a_message_one_constructed_call_it_throws()
404
456
405
457
act . Should ( ) . ThrowExactly < VerifyLogException > ( )
406
458
. WithMessage ( "*.LogInformation(new string(new[] { a }), new[] { })*" )
407
- . Which . InnerException ! . Message . Should ( ) . Match ( "*logger => logger.Log<It.IsAnyType>(LogLevel.Information, It.IsAny<EventId>(), It.Is<It.IsAnyType>((v, t) => VerifyLogExtensions.CompareMessages(v.ToString(), VerifyLogExpression, \" a\" )), It.IsAny<Exception>(), (Func<It.IsAnyType, Exception, string>)It.IsAny<object>())*" ) ;
459
+ . Which . InnerException ! . Message . Should ( ) . Match ( "*logger => logger.Log<It.IsAnyType>(LogLevel.Information, It.IsAny<EventId>(), It.Is<It.IsAnyType>((v, t) => VerifyLogExtensions.CompareMessages(\" a\" , VerifyLogExpression, v.ToString() )), It.IsAny<Exception>(), (Func<It.IsAnyType, Exception, string>)It.IsAny<object>())*" ) ;
408
460
}
409
461
410
462
[ Fact ]
0 commit comments