Fix file lock not getting disposed when postamble throws an exception

This commit is contained in:
Tyrrrz
2023-01-30 12:04:33 +02:00
parent a68df7a065
commit bf76f10030
3 changed files with 26 additions and 12 deletions

View File

@@ -34,13 +34,22 @@ public class ExportWrapperFixture : IDisposable
// Perform export only if it hasn't been done before
if (!File.Exists(filePath))
{
await new ExportChannelsCommand
try
{
Token = Secrets.DiscordToken,
ChannelIds = new[] { channelId },
ExportFormat = format,
OutputPath = filePath
}.ExecuteAsync(new FakeConsole());
await new ExportChannelsCommand
{
Token = Secrets.DiscordToken,
ChannelIds = new[] { channelId },
ExportFormat = format,
OutputPath = filePath
}.ExecuteAsync(new FakeConsole());
}
catch
{
// If the export fails, delete the file to prevent it from being used by tests
File.Delete(filePath);
throw;
}
}
return await File.ReadAllTextAsync(filePath);