You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DiscordChatExporter/DiscordChatExporter.Cli.Tests/Specs/PartitioningSpecs.cs

72 lines
2.4 KiB

3 years ago
using System.IO;
using System.Threading.Tasks;
using CliFx.Infrastructure;
using DiscordChatExporter.Cli.Commands;
using DiscordChatExporter.Cli.Tests.Fixtures;
using DiscordChatExporter.Cli.Tests.Infra;
using DiscordChatExporter.Cli.Tests.TestData;
using DiscordChatExporter.Core.Exporting;
using DiscordChatExporter.Core.Exporting.Partitioning;
using FluentAssertions;
using Xunit;
3 years ago
namespace DiscordChatExporter.Cli.Tests.Specs;
[Collection(nameof(ExportWrapperCollection))]
public class PartitioningSpecs : IClassFixture<TempOutputFixture>
3 years ago
{
private readonly TempOutputFixture _tempOutput;
public PartitioningSpecs(TempOutputFixture tempOutput)
{
_tempOutput = tempOutput;
}
3 years ago
[Fact]
2 years ago
public async Task Messages_partitioned_by_count_are_split_into_a_corresponding_number_of_files()
3 years ago
{
3 years ago
// Arrange
var filePath = _tempOutput.GetTempFilePath();
3 years ago
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
// Act
await new ExportChannelsCommand
3 years ago
{
Token = Secrets.DiscordToken,
3 years ago
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
ExportFormat = ExportFormat.HtmlDark,
OutputPath = filePath,
PartitionLimit = PartitionLimit.Parse("3")
}.ExecuteAsync(new FakeConsole());
3 years ago
3 years ago
// Assert
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
.Should()
.HaveCount(3);
}
3 years ago
3 years ago
[Fact]
2 years ago
public async Task Messages_partitioned_by_file_size_are_split_into_a_corresponding_number_of_files()
3 years ago
{
// Arrange
var filePath = _tempOutput.GetTempFilePath();
3 years ago
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
3 years ago
3 years ago
// Act
await new ExportChannelsCommand
3 years ago
{
Token = Secrets.DiscordToken,
3 years ago
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
ExportFormat = ExportFormat.HtmlDark,
OutputPath = filePath,
2 years ago
PartitionLimit = PartitionLimit.Parse("1kb")
3 years ago
}.ExecuteAsync(new FakeConsole());
3 years ago
3 years ago
// Assert
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
.Should()
2 years ago
.HaveCount(8);
3 years ago
}
}