11namespace ServiceControl . AcceptanceTesting
22{
3+ using System ;
34 using System . Linq ;
45 using System . Threading ;
6+ using NServiceBus . AcceptanceTesting ;
57 using NServiceBus . AcceptanceTesting . Customization ;
68 using NServiceBus . Logging ;
79 using NUnit . Framework ;
10+ using NUnit . Framework . Interfaces ;
11+ using NUnit . Framework . Internal ;
812
913 /// <summary>
1014 /// Base class for all the NSB test that sets up our conventions
@@ -35,5 +39,34 @@ public void SetUp()
3539 return testName + "." + endpointBuilder ;
3640 } ;
3741 }
42+
43+ [ TearDown ]
44+ public void TearDown ( )
45+ {
46+ if ( ! TestExecutionContext . CurrentContext . TryGetRunDescriptor ( out var runDescriptor ) )
47+ {
48+ return ;
49+ }
50+
51+ var scenarioContext = runDescriptor . ScenarioContext ;
52+
53+ TestContext . Out . WriteLine ( $@ "Test settings:
54+ { string . Join ( Environment . NewLine , runDescriptor . Settings . Select ( setting => $ " { setting . Key } : { setting . Value } ") ) } ") ;
55+
56+ TestContext . Out . WriteLine ( $@ "Context:
57+ { string . Join ( Environment . NewLine , scenarioContext . GetType ( ) . GetProperties ( ) . Select ( p => $ "{ p . Name } = { p . GetValue ( scenarioContext , null ) } ") ) } ") ;
58+
59+ if ( TestExecutionContext . CurrentContext . CurrentResult . ResultState == ResultState . Failure || TestExecutionContext . CurrentContext . CurrentResult . ResultState == ResultState . Error )
60+ {
61+ TestContext . Out . WriteLine ( string . Empty ) ;
62+ TestContext . Out . WriteLine ( $ "Log entries (log level: { scenarioContext . LogLevel } ):") ;
63+ TestContext . Out . WriteLine ( "--- Start log entries ---------------------------------------------------" ) ;
64+ foreach ( var logEntry in scenarioContext . Logs )
65+ {
66+ TestContext . Out . WriteLine ( $ "{ logEntry . Timestamp : T} { logEntry . Level } { logEntry . Endpoint ?? TestContext . CurrentContext . Test . Name } : { logEntry . Message } ") ;
67+ }
68+ TestContext . Out . WriteLine ( "--- End log entries ---------------------------------------------------" ) ;
69+ }
70+ }
3871 }
3972}
0 commit comments