4
4
using System . Net . Sockets ;
5
5
using System . Security . Authentication ;
6
6
using System . Security . Cryptography . X509Certificates ;
7
+ using NexNet . IntegrationTests . Pipes ;
7
8
using NexNet . IntegrationTests . TestInterfaces ;
9
+ using NexNet . Logging ;
8
10
using NexNet . Quic ;
9
11
using NexNet . Transports ;
10
12
using NUnit . Framework ;
13
15
14
16
namespace NexNet . IntegrationTests ;
15
17
16
- public class BaseTests
18
+ internal class BaseTests
17
19
{
18
20
public enum Type
19
21
{
@@ -26,20 +28,18 @@ public enum Type
26
28
private int _counter ;
27
29
private DirectoryInfo ? _socketDirectory ;
28
30
protected UnixDomainSocketEndPoint ? CurrentPath ;
29
- //private ConsoleLogger _logger;
30
31
protected int ? CurrentTcpPort ;
31
32
protected int ? CurrentUdpPort ;
32
- //protected List<ConsoleLogger> Loggers = new List<ConsoleLogger>();
33
33
protected List < INexusServer > Servers = new List < INexusServer > ( ) ;
34
34
protected List < INexusClient > Clients = new List < INexusClient > ( ) ;
35
- private ConsoleLogger _logger = null ! ;
35
+ private RollingLogger _logger = null ! ;
36
+ private BasePipeTests . LogMode _loggerMode ;
36
37
public bool BlockForClose { get ; set ; }
37
- public ConsoleLogger Logger => _logger ;
38
+ public RollingLogger Logger => _logger ;
38
39
39
40
[ OneTimeSetUp ]
40
41
public void OneTimeSetUp ( )
41
42
{
42
- //_logger = new ConsoleLogger();
43
43
Trace . Listeners . Add ( new ConsoleTraceListener ( ) ) ;
44
44
_socketDirectory = Directory . CreateTempSubdirectory ( "socketTests" ) ;
45
45
@@ -48,25 +48,33 @@ public void OneTimeSetUp()
48
48
[ OneTimeTearDown ]
49
49
public virtual void OneTimeTearDown ( )
50
50
{
51
+ _loggerMode = BasePipeTests . LogMode . None ;
51
52
_socketDirectory ? . Delete ( true ) ;
52
53
Trace . Flush ( ) ;
53
54
}
54
55
55
56
[ SetUp ]
56
57
public virtual void SetUp ( )
57
58
{
58
- _logger = new ConsoleLogger ( ) ;
59
+ _logger = new RollingLogger ( ) ;
59
60
BlockForClose = false ;
60
61
}
61
62
62
63
[ TearDown ]
63
64
public virtual void TearDown ( )
64
65
{
65
- if ( TestContext . CurrentContext . Result . Outcome != ResultState . Success )
66
+ if ( _loggerMode == BasePipeTests . LogMode . OnTestFail )
67
+ {
68
+ if ( TestContext . CurrentContext . Result . Outcome != ResultState . Success )
69
+ {
70
+ _logger . Flush ( TestContext . Out ) ;
71
+ }
72
+ }
73
+ if ( _loggerMode == BasePipeTests . LogMode . Always )
66
74
{
67
75
_logger . Flush ( TestContext . Out ) ;
68
76
}
69
-
77
+
70
78
CurrentPath = null ;
71
79
CurrentTcpPort = null ;
72
80
CurrentUdpPort = null ;
@@ -166,9 +174,12 @@ protected ServerConfig CreateServerConfigWithLog(Type type, INexusLogger? logger
166
174
throw new InvalidOperationException ( ) ;
167
175
}
168
176
169
- protected ServerConfig CreateServerConfig ( Type type , bool log = false )
177
+ protected ServerConfig CreateServerConfig ( Type type , BasePipeTests . LogMode log = BasePipeTests . LogMode . None )
170
178
{
171
- var logger = log ? _logger . CreateLogger ( null , "SV" ) : null ;
179
+ _loggerMode = log ;
180
+ var logger = log != BasePipeTests . LogMode . None
181
+ ? _logger . CreatePrefixedLogger ( null , "SV" )
182
+ : null ;
172
183
return CreateServerConfigWithLog ( type , logger ) ;
173
184
}
174
185
@@ -234,9 +245,13 @@ protected ClientConfig CreateClientConfigWithLog(Type type, INexusLogger? logger
234
245
throw new InvalidOperationException ( ) ;
235
246
}
236
247
237
- protected ClientConfig CreateClientConfig ( Type type , bool log = false )
248
+ protected ClientConfig CreateClientConfig ( Type type , BasePipeTests . LogMode log = BasePipeTests . LogMode . None )
238
249
{
239
- var logger = log ? _logger . CreateLogger ( null , "CL" ) : null ;
250
+ _loggerMode = log ;
251
+
252
+ var logger = log != BasePipeTests . LogMode . None
253
+ ? _logger . CreatePrefixedLogger ( null , "CL" )
254
+ : null ;
240
255
241
256
return CreateClientConfigWithLog ( type , logger ) ;
242
257
}
0 commit comments