33 lines
821 B
C#
33 lines
821 B
C#
namespace ZB.MOM.WW.OtOpcUa.Tests;
|
|
|
|
internal static class FixtureCleanup
|
|
{
|
|
internal const string SecondaryExceptionKey = "FixtureCleanup.SecondaryException";
|
|
|
|
internal static async Task RunAsync(Func<Task> body, Func<Task> cleanup, Action<Exception> report)
|
|
{
|
|
Exception? primary = null;
|
|
try
|
|
{
|
|
await body();
|
|
}
|
|
catch (Exception failure)
|
|
{
|
|
primary = failure;
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
try
|
|
{
|
|
await cleanup();
|
|
}
|
|
catch (Exception secondary) when (primary is not null)
|
|
{
|
|
try { primary.Data[SecondaryExceptionKey] = secondary; } catch { }
|
|
try { report(secondary); } catch { }
|
|
}
|
|
}
|
|
}
|
|
}
|