88using Microsoft . Testing . Extensions . TrxReport . Abstractions ;
99using Microsoft . Testing . Platform . CommandLine ;
1010using Microsoft . Testing . Platform . Extensions . Messages ;
11+ using Microsoft . Testing . Platform . Extensions . OutputDevice ;
1112using Microsoft . Testing . Platform . Extensions . TestFramework ;
1213using Microsoft . Testing . Platform . Logging ;
14+ using Microsoft . Testing . Platform . OutputDevice ;
1315using Microsoft . Testing . Platform . Requests ;
1416using Xunit ;
1517using Xunit . Abstractions ;
1618using YTest . MTP . XUnit2 . Filter ;
1719
1820namespace YTest . MTP . XUnit2 ;
1921
20- internal sealed class XUnit2MTPTestFramework : Microsoft . Testing . Platform . Extensions . TestFramework . ITestFramework , IDataProducer
22+ internal sealed class XUnit2MTPTestFramework : Microsoft . Testing . Platform . Extensions . TestFramework . ITestFramework ,
23+ IDataProducer ,
24+ IOutputDeviceDataProducer
2125{
2226 private readonly XUnit2MTPTestTrxCapability _trxReportCapability ;
2327 private readonly ICommandLineOptions _commandLineOptions ;
28+ private readonly IOutputDevice _outputDevice ;
2429 private readonly ILoggerFactory _loggerFactory ;
2530 private readonly ILogger < XUnit2MTPTestFramework > _logger ;
2631
2732 public XUnit2MTPTestFramework (
2833 XUnit2MTPTestTrxCapability trxReportCapability ,
2934 ICommandLineOptions commandLineOptions ,
35+ IOutputDevice outputDevice ,
3036 ILoggerFactory loggerFactory )
3137 {
3238 _trxReportCapability = trxReportCapability ;
3339 _commandLineOptions = commandLineOptions ;
40+ _outputDevice = outputDevice ;
3441 _loggerFactory = loggerFactory ;
3542
3643 _logger = loggerFactory . CreateLogger < XUnit2MTPTestFramework > ( ) ;
@@ -102,8 +109,8 @@ private async Task DiscoverTestsAsync(
102109 string assemblyPath ,
103110 TestCaseFilterExpression ? filter )
104111 {
105- var configuration = GetConfiguration ( assemblyPath ) ;
106- var diagnosticMessageSink = GetDiagnosticMessageSink ( assemblyPath , configuration ) ;
112+ var configuration = await GetConfigurationAsync ( assemblyPath , context . CancellationToken ) ;
113+ var diagnosticMessageSink = GetDiagnosticMessageSink ( assemblyPath , configuration , context . CancellationToken ) ;
107114 using var frontController = GetFrontController ( assemblyPath , configuration , diagnosticMessageSink ) ;
108115 var testCases = await DiscoverAsync ( frontController , configuration , context . CancellationToken ) ;
109116
@@ -174,8 +181,8 @@ private async Task RunTestsAsync(
174181 string assemblyPath ,
175182 TestCaseFilterExpression ? filter )
176183 {
177- var configuration = GetConfiguration ( assemblyPath ) ;
178- var diagnosticMessageSink = GetDiagnosticMessageSink ( assemblyPath , configuration ) ;
184+ var configuration = await GetConfigurationAsync ( assemblyPath , context . CancellationToken ) ;
185+ var diagnosticMessageSink = GetDiagnosticMessageSink ( assemblyPath , configuration , context . CancellationToken ) ;
179186 using var frontController = GetFrontController ( assemblyPath , configuration , diagnosticMessageSink ) ;
180187 var testCases = await DiscoverAsync ( frontController , configuration , context . CancellationToken ) ;
181188
@@ -237,7 +244,7 @@ private static bool MatchesFilter(ITestExecutionFilter mtpFilter, TestCaseFilter
237244 } ;
238245 }
239246
240- private TestAssemblyConfiguration GetConfiguration ( string assemblyPath )
247+ private async Task < TestAssemblyConfiguration > GetConfigurationAsync ( string assemblyPath , CancellationToken cancellationToken )
241248 {
242249 var warnings = new List < string > ( ) ;
243250 var configuration = ConfigReader . Load ( assemblyPath , configFileName : null , warnings ) ;
@@ -251,6 +258,7 @@ private TestAssemblyConfiguration GetConfiguration(string assemblyPath)
251258 foreach ( var warning in warnings )
252259 {
253260 _logger . LogWarning ( warning ) ;
261+ await _outputDevice . DisplayAsync ( this , new WarningMessageOutputDeviceData ( warning ) , cancellationToken ) ;
254262 }
255263
256264 return configuration ;
@@ -267,6 +275,6 @@ private static XunitFrontController GetFrontController(string assemblyPath, Test
267275 sourceInformationProvider : null ,
268276 diagnosticMessageSink ) ;
269277
270- private MTPDiagnosticMessageSink GetDiagnosticMessageSink ( string assemblyPath , TestAssemblyConfiguration configuration )
271- => new MTPDiagnosticMessageSink ( _loggerFactory , Path . GetFileNameWithoutExtension ( assemblyPath ) , configuration . DiagnosticMessagesOrDefault ) ;
278+ private MTPDiagnosticMessageSink GetDiagnosticMessageSink ( string assemblyPath , TestAssemblyConfiguration configuration , CancellationToken cancellationToken )
279+ => new MTPDiagnosticMessageSink ( data => _outputDevice . DisplayAsync ( this , data , cancellationToken ) . GetAwaiter ( ) . GetResult ( ) , _loggerFactory , Path . GetFileNameWithoutExtension ( assemblyPath ) , configuration . DiagnosticMessagesOrDefault ) ;
272280}
0 commit comments