55using C3D . Extensions . Logging . Xunit . Utilities ;
66using System . Runtime . CompilerServices ;
77using Xunit . Abstractions ;
8+ using Microsoft . Extensions . Time . Testing ;
89
910namespace C3D . Extensions . Logging . Xunit . Test ;
1011
@@ -53,40 +54,72 @@ private IServiceCollection CreateServices()
5354 return ( wrapper , factory ) ;
5455 }
5556
57+ const string debug = "Here is some debugging" ;
58+ const string info = "Here is some information" ;
59+
5660 [ Fact ]
5761 public void CreateLogger ( )
5862 {
5963 WriteFunctionName ( ) ;
6064
6165 var log = output . CreateLogger < TestOutputHelperTests > ( ) ;
62-
66+
6367 Assert . NotNull ( log ) ;
64-
65- log . LogInformation ( "Here is some information" ) ;
68+
69+ log . LogInformation ( info ) ;
6670 }
6771
6872 [ Fact ]
6973 public void CreateLoggerWithTimestamp ( )
7074 {
7175 WriteFunctionName ( ) ;
7276
73- var log = output . CreateLogger < TestOutputHelperTests > ( configure=> configure . TimeStamp = XunitLoggerTimeStamp . DateTime ) ;
77+ var wrapper = new LoggingTestOutputHelper ( output ) ;
78+ var utcNow = new DateTimeOffset ( 2020 , 10 , 9 , 8 , 7 , 6 , TimeSpan . Zero ) ;
79+ var tp = new FakeTimeProvider ( utcNow ) ;
80+
81+ var log = wrapper . CreateLogger < TestOutputHelperTests > ( configure => configure
82+ . WithTimeStamp ( XunitLoggerTimeStamp . DateTime )
83+ . UseTimeProvider ( tp )
84+ . UseCulture ( System . Globalization . CultureInfo . InvariantCulture )
85+ ) ;
7486
7587 Assert . NotNull ( log ) ;
7688
77- log . LogInformation ( "Here is some information" ) ;
89+ log . LogInformation ( info ) ;
90+
91+ var messages = wrapper . Messages ;
92+
93+ var s = Assert . Single ( messages ) ;
94+ Assert . Equal ( "| 2020-10-09 08:07:06Z C3D.Extensions.Logging.Xunit.Test.TestOutputHelperTests Information | Here is some information" , s ) ;
7895 }
7996
8097 [ Fact ]
8198 public void CreateLoggerWithOffset ( )
8299 {
83100 WriteFunctionName ( ) ;
84101
85- var log = output . CreateLogger < TestOutputHelperTests > ( configure => configure . TimeStamp = XunitLoggerTimeStamp . Offset ) ;
102+ var wrapper = new LoggingTestOutputHelper ( output ) ;
103+ var utcNow = DateTime . UtcNow ;
104+ var tp = new FakeTimeProvider ( utcNow ) ;
105+
106+ // "| -0:00:00:00.0007472 C3D.Extensions.Logging.Xunit.Test.TestOutputHelperTests Information | Here is some information"
107+
108+
109+ var log = wrapper . CreateLogger < TestOutputHelperTests > ( configure => configure
110+ . WithTimeStamp ( XunitLoggerTimeStamp . Offset )
111+ . UseTimeProvider ( tp )
112+ . Restart ( )
113+ . UseCulture ( System . Globalization . CultureInfo . InvariantCulture )
114+ ) ;
86115
87116 Assert . NotNull ( log ) ;
88117
89- log . LogInformation ( "Here is some information" ) ;
118+ log . LogInformation ( info ) ;
119+
120+ var messages = wrapper . Messages ;
121+ var s = Assert . Single ( messages ) ;
122+ Assert . Equal ( "| 0:00:00:00.0000000 C3D.Extensions.Logging.Xunit.Test.TestOutputHelperTests Information | Here is some information" , s ) ;
90123 }
91124
92125 [ Fact ]
@@ -100,9 +133,6 @@ public void CreateLoggerFiltersMessages()
100133
101134 Assert . NotNull ( log ) ;
102135
103- const string debug = "Here is some debugging" ;
104- const string info = "Here is some information" ;
105-
106136 log . LogDebug ( debug ) ;
107137 log . LogInformation ( info ) ;
108138
@@ -122,9 +152,6 @@ public void CreateLoggerFromServices()
122152
123153 Assert . NotNull ( log ) ;
124154
125- const string debug = "Here is some debugging" ;
126- const string info = "Here is some information" ;
127-
128155 log . LogDebug ( debug ) ;
129156 log . LogInformation ( info ) ;
130157
@@ -134,7 +161,7 @@ public void CreateLoggerFromServices()
134161
135162 var messages = wrapper . Messages ;
136163
137- Assert . Collection ( messages , s=> s . EndsWith ( debug ) , s => s . EndsWith ( info ) ) ;
164+ Assert . Collection ( messages , s => s . EndsWith ( debug ) , s => s . EndsWith ( info ) ) ;
138165 }
139166
140167 [ Fact ]
@@ -148,9 +175,6 @@ public void CreateLoggerFromFactory()
148175
149176 Assert . NotNull ( log ) ;
150177
151- const string debug = "Here is some debugging" ;
152- const string info = "Here is some information" ;
153-
154178 log . LogDebug ( debug ) ;
155179 log . LogInformation ( info ) ;
156180
0 commit comments