Get rid of xUnit fixtures

This commit is contained in:
Tyrrrz
2023-02-11 23:12:15 +02:00
parent 3487849eba
commit 53b8927fce
29 changed files with 221 additions and 347 deletions

View File

@@ -50,7 +50,7 @@ public class ChannelExporter
{
cancellationToken.ThrowIfCancellationRequested();
// Skips any messages that fail to pass the supplied filter
// Skip messages that fail to pass the supplied filter
if (!request.MessageFilter.IsMatch(message))
continue;

View File

@@ -78,13 +78,11 @@ internal partial class ExportAssetDownloader
internal partial class ExportAssetDownloader
{
private static string GetUrlHash(string url)
{
using var hash = SHA256.Create();
var data = hash.ComputeHash(Encoding.UTF8.GetBytes(url));
return data.ToHex().Truncate(5); // 5 chars ought to be enough for anybody
}
private static string GetUrlHash(string url) => SHA256
.HashData(Encoding.UTF8.GetBytes(url))
.ToHex()
// 5 chars ought to be enough for anybody
.Truncate(5);
private static string GetFileNameFromUrl(string url)
{

View File

@@ -26,7 +26,7 @@ internal partial class MessageExporter : IAsyncDisposable
{
await _writer.WritePostambleAsync(cancellationToken);
}
// Writer must be disposed, even if writing postamble fails
// Writer must be disposed, even if it fails to write the postamble
finally
{
await _writer.DisposeAsync();
@@ -45,16 +45,13 @@ internal partial class MessageExporter : IAsyncDisposable
_partitionIndex++;
}
// Writer is still valid - return
// Writer is still valid, return
if (_writer is not null)
return _writer;
Directory.CreateDirectory(_context.Request.OutputBaseDirPath);
var filePath = GetPartitionFilePath(_context.Request.OutputBaseFilePath, _partitionIndex);
var dirPath = Path.GetDirectoryName(_context.Request.OutputBaseFilePath);
if (!string.IsNullOrWhiteSpace(dirPath))
Directory.CreateDirectory(dirPath);
var writer = CreateMessageWriter(filePath, _context.Request.Format, _context);
await writer.WritePreambleAsync(cancellationToken);
@@ -74,7 +71,7 @@ internal partial class MessageExporter
{
private static string GetPartitionFilePath(string baseFilePath, int partitionIndex)
{
// First partition - don't change file name
// First partition, don't change file name
if (partitionIndex <= 0)
return baseFilePath;
@@ -92,19 +89,14 @@ internal partial class MessageExporter
private static MessageWriter CreateMessageWriter(
string filePath,
ExportFormat format,
ExportContext context)
{
// Stream will be disposed by the underlying writer
var stream = File.Create(filePath);
return format switch
ExportContext context) =>
format switch
{
ExportFormat.PlainText => new PlainTextMessageWriter(stream, context),
ExportFormat.Csv => new CsvMessageWriter(stream, context),
ExportFormat.HtmlDark => new HtmlMessageWriter(stream, context, "Dark"),
ExportFormat.HtmlLight => new HtmlMessageWriter(stream, context, "Light"),
ExportFormat.Json => new JsonMessageWriter(stream, context),
ExportFormat.PlainText => new PlainTextMessageWriter(File.Create(filePath), context),
ExportFormat.Csv => new CsvMessageWriter(File.Create(filePath), context),
ExportFormat.HtmlDark => new HtmlMessageWriter(File.Create(filePath), context, "Dark"),
ExportFormat.HtmlLight => new HtmlMessageWriter(File.Create(filePath), context, "Light"),
ExportFormat.Json => new JsonMessageWriter(File.Create(filePath), context),
_ => throw new ArgumentOutOfRangeException(nameof(format), $"Unknown export format '{format}'.")
};
}
}

View File

@@ -6,12 +6,10 @@ public static class BinaryExtensions
{
public static string ToHex(this byte[] data)
{
var buffer = new StringBuilder();
var buffer = new StringBuilder(2 * data.Length);
foreach (var t in data)
{
buffer.Append(t.ToString("X2"));
}
return buffer.ToString();
}