@@ -49,6 +49,40 @@ public void LoggerShouldSubmitData()
49
49
}
50
50
}
51
51
52
+ [ Fact ]
53
+ public void LoggerShouldSubmitDataWhenEncounterDuplicates ( )
54
+ {
55
+ var healthReporterMock = new Mock < IHealthReporter > ( ) ;
56
+ var subject = new Mock < IObserver < EventData > > ( ) ;
57
+ EventData savedData = null ;
58
+ subject . Setup ( s => s . OnNext ( It . IsAny < EventData > ( ) ) ) . Callback ( ( EventData data ) => savedData = data ) ;
59
+
60
+ using ( LoggerInput target = new LoggerInput ( healthReporterMock . Object ) )
61
+ {
62
+ var diagnosticPipeline = createPipeline ( target , healthReporterMock . Object ) ;
63
+ using ( target . Subscribe ( subject . Object ) )
64
+ {
65
+ var factory = new LoggerFactory ( ) ;
66
+ factory . AddEventFlow ( diagnosticPipeline ) ;
67
+ var logger = new Logger < LoggerInputTests > ( factory ) ;
68
+ logger . LogInformation ( "log message {number} {number}" , 1 , 1 ) ;
69
+ subject . Verify ( s => s . OnNext ( It . Is < EventData > ( data => checkEventData (
70
+ data ,
71
+ "log message 1 1" ,
72
+ typeof ( LoggerInputTests ) . FullName ,
73
+ LogLevel . Informational ,
74
+ 0 ,
75
+ null ,
76
+ new Dictionary < string , object > { { "number" , 1 } } ) ) ) , Times . Exactly ( 1 ) ) ;
77
+
78
+ assertDoesNotContainDuplicate ( savedData . Payload , keyPrefix : "number" , expectedValue : 1 ) ;
79
+
80
+ healthReporterMock . Verify ( it => it . ReportWarning ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) , Times . Never ( ) ) ;
81
+ healthReporterMock . Verify ( it => it . ReportProblem ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) , Times . Never ( ) ) ;
82
+ }
83
+ }
84
+ }
85
+
52
86
[ Fact ]
53
87
public void LoggerShouldSubmitException ( )
54
88
{
@@ -516,6 +550,13 @@ private void assertContainsDuplicate(IDictionary<string, object> payload, string
516
550
Assert . Equal ( expectedValue , payload [ duplicates . First ( ) ] ) ;
517
551
}
518
552
553
+ private void assertDoesNotContainDuplicate ( IDictionary < string , object > payload , string keyPrefix , object expectedValue )
554
+ {
555
+ var singleValue = payload . Keys . Where ( k => k . StartsWith ( keyPrefix ) ) . ToArray ( ) ;
556
+ Assert . Single ( singleValue ) ;
557
+ Assert . Equal ( expectedValue , payload [ singleValue . First ( ) ] ) ;
558
+ }
559
+
519
560
private DiagnosticPipeline createPipeline ( LoggerInput input , IHealthReporter reporter )
520
561
{
521
562
return new DiagnosticPipeline ( reporter , new [ ] { input } , null , new [ ] { new EventSink ( new FakeOutput ( ) , null ) } ) ;
0 commit comments