Capture LoggedTest.Initialize exception and re-trow in Dispose (#770)
This commit is contained in:
parent
e7cca176e5
commit
688914bb70
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
|
|
@ -12,6 +13,8 @@ namespace Microsoft.Extensions.Logging.Testing
|
|||
{
|
||||
public class LoggedTestBase : ILoggedTest
|
||||
{
|
||||
private ExceptionDispatchInfo _initializationException;
|
||||
|
||||
private IDisposable _testLog;
|
||||
|
||||
// Obsolete but keeping for back compat
|
||||
|
|
@ -47,6 +50,8 @@ namespace Microsoft.Extensions.Logging.Testing
|
|||
}
|
||||
|
||||
public virtual void Initialize(MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
try
|
||||
{
|
||||
TestOutputHelper = testOutputHelper;
|
||||
|
||||
|
|
@ -78,7 +83,16 @@ namespace Microsoft.Extensions.Logging.Testing
|
|||
LoggerFactory = loggerFactory;
|
||||
Logger = loggerFactory.CreateLogger(classType);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_initializationException = ExceptionDispatchInfo.Capture(e);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Dispose() => _testLog.Dispose();
|
||||
public virtual void Dispose()
|
||||
{
|
||||
_initializationException?.Throw();
|
||||
_testLog.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue