mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-29 09:12:40 +00:00
C#10ify
This commit is contained in:
@@ -4,28 +4,27 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting
|
||||
{
|
||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
// Act
|
||||
var document = await ExportWrapper.ExportAsCsvAsync(ChannelIds.DateRangeTestCases);
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.CsvWriting;
|
||||
|
||||
// Assert
|
||||
document.Should().ContainAll(
|
||||
"Tyrrrz#5447",
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
// Act
|
||||
var document = await ExportWrapper.ExportAsCsvAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
document.Should().ContainAll(
|
||||
"Tyrrrz#5447",
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -13,148 +13,147 @@ using FluentAssertions;
|
||||
using JsonExtensions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public record DateRangeSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||
{
|
||||
public record DateRangeSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||
[Fact]
|
||||
public async Task Messages_filtered_after_specific_date_only_include_messages_sent_after_that_date()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Messages_filtered_after_specific_date_only_include_messages_sent_after_that_date()
|
||||
// Arrange
|
||||
var after = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
// Arrange
|
||||
var after = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
After = Snowflake.FromDate(after)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
After = Snowflake.FromDate(after)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
var timestamps = document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
.ToArray();
|
||||
|
||||
var timestamps = document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
.ToArray();
|
||||
// Assert
|
||||
timestamps.All(t => t > after).Should().BeTrue();
|
||||
|
||||
// Assert
|
||||
timestamps.All(t => t > after).Should().BeTrue();
|
||||
|
||||
timestamps.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
new DateTimeOffset(2021, 07, 24, 13, 49, 13, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 38, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 39, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 40, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 09, 08, 14, 26, 35, TimeSpan.Zero)
|
||||
}, o =>
|
||||
{
|
||||
return o
|
||||
.Using<DateTimeOffset>(ctx =>
|
||||
ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromSeconds(1))
|
||||
)
|
||||
.WhenTypeIs<DateTimeOffset>();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_before_specific_date_only_include_messages_sent_before_that_date()
|
||||
timestamps.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
// Arrange
|
||||
var before = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
Before = Snowflake.FromDate(before)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
|
||||
var timestamps = document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
.ToArray();
|
||||
|
||||
// Assert
|
||||
timestamps.All(t => t < before).Should().BeTrue();
|
||||
|
||||
timestamps.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
new DateTimeOffset(2021, 07, 19, 13, 34, 18, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 19, 15, 58, 48, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 19, 17, 23, 58, TimeSpan.Zero)
|
||||
}, o =>
|
||||
{
|
||||
return o
|
||||
.Using<DateTimeOffset>(ctx =>
|
||||
ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromSeconds(1))
|
||||
)
|
||||
.WhenTypeIs<DateTimeOffset>();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_between_specific_dates_only_include_messages_sent_between_those_dates()
|
||||
new DateTimeOffset(2021, 07, 24, 13, 49, 13, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 38, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 39, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 40, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 09, 08, 14, 26, 35, TimeSpan.Zero)
|
||||
}, o =>
|
||||
{
|
||||
// Arrange
|
||||
var after = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
|
||||
var before = new DateTimeOffset(2021, 08, 01, 0, 0, 0, TimeSpan.Zero);
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
return o
|
||||
.Using<DateTimeOffset>(ctx =>
|
||||
ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromSeconds(1))
|
||||
)
|
||||
.WhenTypeIs<DateTimeOffset>();
|
||||
});
|
||||
}
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
Before = Snowflake.FromDate(before),
|
||||
After = Snowflake.FromDate(after)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
[Fact]
|
||||
public async Task Messages_filtered_before_specific_date_only_include_messages_sent_before_that_date()
|
||||
{
|
||||
// Arrange
|
||||
var before = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
Before = Snowflake.FromDate(before)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var timestamps = document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
.ToArray();
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
|
||||
// Assert
|
||||
timestamps.All(t => t < before && t > after).Should().BeTrue();
|
||||
var timestamps = document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
.ToArray();
|
||||
|
||||
timestamps.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
new DateTimeOffset(2021, 07, 24, 13, 49, 13, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 38, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 39, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 40, TimeSpan.Zero)
|
||||
}, o =>
|
||||
{
|
||||
return o
|
||||
.Using<DateTimeOffset>(ctx =>
|
||||
ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromSeconds(1))
|
||||
)
|
||||
.WhenTypeIs<DateTimeOffset>();
|
||||
});
|
||||
}
|
||||
// Assert
|
||||
timestamps.All(t => t < before).Should().BeTrue();
|
||||
|
||||
timestamps.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
new DateTimeOffset(2021, 07, 19, 13, 34, 18, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 19, 15, 58, 48, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 19, 17, 23, 58, TimeSpan.Zero)
|
||||
}, o =>
|
||||
{
|
||||
return o
|
||||
.Using<DateTimeOffset>(ctx =>
|
||||
ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromSeconds(1))
|
||||
)
|
||||
.WhenTypeIs<DateTimeOffset>();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_between_specific_dates_only_include_messages_sent_between_those_dates()
|
||||
{
|
||||
// Arrange
|
||||
var after = new DateTimeOffset(2021, 07, 24, 0, 0, 0, TimeSpan.Zero);
|
||||
var before = new DateTimeOffset(2021, 08, 01, 0, 0, 0, TimeSpan.Zero);
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
Before = Snowflake.FromDate(before),
|
||||
After = Snowflake.FromDate(after)
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
|
||||
var timestamps = document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("timestamp").GetDateTimeOffset())
|
||||
.ToArray();
|
||||
|
||||
// Assert
|
||||
timestamps.All(t => t < before && t > after).Should().BeTrue();
|
||||
|
||||
timestamps.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
new DateTimeOffset(2021, 07, 24, 13, 49, 13, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 38, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 39, TimeSpan.Zero),
|
||||
new DateTimeOffset(2021, 07, 24, 14, 52, 40, TimeSpan.Zero)
|
||||
}, o =>
|
||||
{
|
||||
return o
|
||||
.Using<DateTimeOffset>(ctx =>
|
||||
ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromSeconds(1))
|
||||
)
|
||||
.WhenTypeIs<DateTimeOffset>();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -12,124 +12,123 @@ using FluentAssertions;
|
||||
using JsonExtensions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||
{
|
||||
public record FilterSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_text_only_include_messages_that_contain_that_text()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_text_only_include_messages_that_contain_that_text()
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("some text")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("some text")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
// Assert
|
||||
document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
.Should()
|
||||
.ContainSingle("Some random text");
|
||||
}
|
||||
|
||||
// Assert
|
||||
document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
.Should()
|
||||
.ContainSingle("Some random text");
|
||||
}
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_author_only_include_messages_sent_by_that_author()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_author_only_include_messages_sent_by_that_author()
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("from:Tyrrrz")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("from:Tyrrrz")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
// Assert
|
||||
document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("author").GetProperty("name").GetString())
|
||||
.Should()
|
||||
.AllBe("Tyrrrz");
|
||||
}
|
||||
|
||||
// Assert
|
||||
document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("author").GetProperty("name").GetString())
|
||||
.Should()
|
||||
.AllBe("Tyrrrz");
|
||||
}
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_content_only_include_messages_that_have_that_content()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_content_only_include_messages_that_have_that_content()
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("has:image")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("has:image")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
// Assert
|
||||
document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
.Should()
|
||||
.ContainSingle("This has image");
|
||||
}
|
||||
|
||||
// Assert
|
||||
document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
.Should()
|
||||
.ContainSingle("This has image");
|
||||
}
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_mention_only_include_messages_that_have_that_mention()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_filtered_by_mention_only_include_messages_that_have_that_mention()
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("mentions:Tyrrrz")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.FilterTestCases },
|
||||
ExportFormat = ExportFormat.Json,
|
||||
OutputPath = filePath,
|
||||
MessageFilter = MessageFilter.Parse("mentions:Tyrrrz")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Json.Parse(data);
|
||||
|
||||
// Assert
|
||||
document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
.Should()
|
||||
.ContainSingle("This has mention");
|
||||
}
|
||||
// Assert
|
||||
document
|
||||
.GetProperty("messages")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("content").GetString())
|
||||
.Should()
|
||||
.ContainSingle("This has mention");
|
||||
}
|
||||
}
|
||||
@@ -6,88 +6,87 @@ using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||
|
||||
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
[Fact]
|
||||
public async Task Message_with_a_generic_attachment_is_rendered_correctly()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Message_with_a_generic_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885587844989612074")
|
||||
);
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885587844989612074")
|
||||
);
|
||||
|
||||
var fileUrl = message.QuerySelector("a")?.GetAttribute("href");
|
||||
var fileUrl = message.QuerySelector("a")?.GetAttribute("href");
|
||||
|
||||
// Assert
|
||||
message.Text().Should().ContainAll(
|
||||
"Generic file attachment",
|
||||
"Test.txt",
|
||||
"11 bytes"
|
||||
);
|
||||
// Assert
|
||||
message.Text().Should().ContainAll(
|
||||
"Generic file attachment",
|
||||
"Test.txt",
|
||||
"11 bytes"
|
||||
);
|
||||
|
||||
fileUrl.Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
||||
);
|
||||
}
|
||||
fileUrl.Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_image_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885654862656843786")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Message_with_an_image_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885654862656843786")
|
||||
);
|
||||
|
||||
var imageUrl = message.QuerySelector("img")?.GetAttribute("src");
|
||||
var imageUrl = message.QuerySelector("img")?.GetAttribute("src");
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Image attachment");
|
||||
// Assert
|
||||
message.Text().Should().Contain("Image attachment");
|
||||
|
||||
imageUrl.Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
||||
);
|
||||
}
|
||||
imageUrl.Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_video_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885655761919836171")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Message_with_a_video_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885655761919836171")
|
||||
);
|
||||
|
||||
var videoUrl = message.QuerySelector("video source")?.GetAttribute("src");
|
||||
var videoUrl = message.QuerySelector("video source")?.GetAttribute("src");
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Video attachment");
|
||||
// Assert
|
||||
message.Text().Should().Contain("Video attachment");
|
||||
|
||||
videoUrl.Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
|
||||
);
|
||||
}
|
||||
videoUrl.Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885656175620808734")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885656175620808734")
|
||||
);
|
||||
|
||||
var audioUrl = message.QuerySelector("audio source")?.GetAttribute("src");
|
||||
var audioUrl = message.QuerySelector("audio source")?.GetAttribute("src");
|
||||
|
||||
// Assert
|
||||
message.Text().Should().Contain("Audio attachment");
|
||||
// Assert
|
||||
message.Text().Should().Contain("Audio attachment");
|
||||
|
||||
audioUrl.Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
|
||||
);
|
||||
}
|
||||
audioUrl.Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,38 +6,37 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||
|
||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
// Act
|
||||
var messages = await ExportWrapper.GetMessagesAsHtmlAsync(ChannelIds.DateRangeTestCases);
|
||||
// Act
|
||||
var messages = await ExportWrapper.GetMessagesAsHtmlAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
messages.Select(e => e.GetAttribute("data-message-id")).Should().Equal(
|
||||
"866674314627121232",
|
||||
"866710679758045195",
|
||||
"866732113319428096",
|
||||
"868490009366396958",
|
||||
"868505966528835604",
|
||||
"868505969821364245",
|
||||
"868505973294268457",
|
||||
"885169254029213696"
|
||||
);
|
||||
// Assert
|
||||
messages.Select(e => e.GetAttribute("data-message-id")).Should().Equal(
|
||||
"866674314627121232",
|
||||
"866710679758045195",
|
||||
"866732113319428096",
|
||||
"868490009366396958",
|
||||
"868505966528835604",
|
||||
"868505969821364245",
|
||||
"868505973294268457",
|
||||
"885169254029213696"
|
||||
);
|
||||
|
||||
messages.Select(e => e.QuerySelector(".chatlog__content")?.Text().Trim()).Should().Equal(
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
messages.Select(e => e.QuerySelector(".chatlog__content")?.Text().Trim()).Should().Equal(
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,59 +6,58 @@ using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||
|
||||
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
[Fact]
|
||||
public async Task Message_with_an_embed_is_rendered_correctly()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Message_with_an_embed_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866769910729146400")
|
||||
);
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866769910729146400")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Should().ContainAll(
|
||||
"Embed author",
|
||||
"Embed title",
|
||||
"Embed description",
|
||||
"Field 1", "Value 1",
|
||||
"Field 2", "Value 2",
|
||||
"Field 3", "Value 3",
|
||||
"Embed footer"
|
||||
);
|
||||
}
|
||||
// Assert
|
||||
message.Text().Should().ContainAll(
|
||||
"Embed author",
|
||||
"Embed title",
|
||||
"Embed description",
|
||||
"Field 1", "Value 1",
|
||||
"Field 2", "Value 2",
|
||||
"Field 3", "Value 3",
|
||||
"Embed footer"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_Spotify_track_is_rendered_using_an_iframe()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("867886632203976775")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Message_with_a_Spotify_track_is_rendered_using_an_iframe()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("867886632203976775")
|
||||
);
|
||||
|
||||
var iframeSrc = message.QuerySelector("iframe")?.GetAttribute("src");
|
||||
var iframeSrc = message.QuerySelector("iframe")?.GetAttribute("src");
|
||||
|
||||
// Assert
|
||||
iframeSrc.Should().StartWithEquivalentOf("https://open.spotify.com/embed/track/1LHZMWefF9502NPfArRfvP");
|
||||
}
|
||||
// Assert
|
||||
iframeSrc.Should().StartWithEquivalentOf("https://open.spotify.com/embed/track/1LHZMWefF9502NPfArRfvP");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_YouTube_video_is_rendered_using_an_iframe()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866472508588294165")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Message_with_a_YouTube_video_is_rendered_using_an_iframe()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866472508588294165")
|
||||
);
|
||||
|
||||
var iframeSrc = message.QuerySelector("iframe")?.GetAttribute("src");
|
||||
var iframeSrc = message.QuerySelector("iframe")?.GetAttribute("src");
|
||||
|
||||
// Assert
|
||||
iframeSrc.Should().StartWithEquivalentOf("https://www.youtube.com/embed/qOWW4OlgbvE");
|
||||
}
|
||||
// Assert
|
||||
iframeSrc.Should().StartWithEquivalentOf("https://www.youtube.com/embed/qOWW4OlgbvE");
|
||||
}
|
||||
}
|
||||
@@ -6,61 +6,60 @@ using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||
|
||||
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
[Fact]
|
||||
public async Task User_mention_is_rendered_correctly()
|
||||
{
|
||||
[Fact]
|
||||
public async Task User_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866458840245076028")
|
||||
);
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866458840245076028")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("User mention: @Tyrrrz");
|
||||
message.InnerHtml.Should().Contain("Tyrrrz#5447");
|
||||
}
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("User mention: @Tyrrrz");
|
||||
message.InnerHtml.Should().Contain("Tyrrrz#5447");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Text_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459040480624680")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Text_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459040480624680")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("Text channel mention: #mention-tests");
|
||||
}
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("Text channel mention: #mention-tests");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Voice_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459175462633503")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Voice_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459175462633503")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("Voice channel mention: 🔊chaos-vc");
|
||||
}
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("Voice channel mention: 🔊chaos-vc");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Role_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459254693429258")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Role_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459254693429258")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("Role mention: @Role 1");
|
||||
}
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("Role mention: @Role 1");
|
||||
}
|
||||
}
|
||||
@@ -6,52 +6,51 @@ using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
|
||||
|
||||
public record ReplySpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
public record ReplySpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
[Fact]
|
||||
public async Task Reply_to_a_normal_message_is_rendered_correctly()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Reply_to_a_normal_message_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("866460738239725598")
|
||||
);
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("866460738239725598")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("reply to original");
|
||||
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should().Be("original");
|
||||
}
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("reply to original");
|
||||
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should().Be("original");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Reply_to_a_deleted_message_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("866460975388819486")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Reply_to_a_deleted_message_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("866460975388819486")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("reply to deleted");
|
||||
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should()
|
||||
.Be("Original message was deleted or could not be loaded.");
|
||||
}
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("reply to deleted");
|
||||
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should()
|
||||
.Be("Original message was deleted or could not be loaded.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Reply_to_a_empty_message_with_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("866462470335627294")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Reply_to_a_empty_message_with_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||
ChannelIds.ReplyTestCases,
|
||||
Snowflake.Parse("866462470335627294")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("reply to attachment");
|
||||
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should()
|
||||
.Be("Click to see attachment 🖼️");
|
||||
}
|
||||
// Assert
|
||||
message.Text().Trim().Should().Be("reply to attachment");
|
||||
message.QuerySelector(".chatlog__reference-link")?.Text().Trim().Should()
|
||||
.Be("Click to see attachment 🖼️");
|
||||
}
|
||||
}
|
||||
@@ -6,96 +6,95 @@ using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||
|
||||
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
[Fact]
|
||||
public async Task Message_with_a_generic_attachment_is_rendered_correctly()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Message_with_a_generic_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885587844989612074")
|
||||
);
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885587844989612074")
|
||||
);
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Generic file attachment");
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Generic file attachment");
|
||||
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("Test.txt");
|
||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(11);
|
||||
}
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("Test.txt");
|
||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(11);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_image_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885654862656843786")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Message_with_an_image_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885654862656843786")
|
||||
);
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Image attachment");
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Image attachment");
|
||||
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("bird-thumbnail.png");
|
||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(466335);
|
||||
}
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("bird-thumbnail.png");
|
||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(466335);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_a_video_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885655761919836171")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Message_with_a_video_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885655761919836171")
|
||||
);
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Video attachment");
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Video attachment");
|
||||
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP4_640_3MG.mp4");
|
||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(3114374);
|
||||
}
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP4_640_3MG.mp4");
|
||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(3114374);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885656175620808734")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.AttachmentTestCases,
|
||||
Snowflake.Parse("885656175620808734")
|
||||
);
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Audio attachment");
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Audio attachment");
|
||||
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP3_1MG.mp3");
|
||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(1087849);
|
||||
}
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP3_1MG.mp3");
|
||||
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(1087849);
|
||||
}
|
||||
}
|
||||
@@ -5,38 +5,37 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||
|
||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
// Act
|
||||
var messages = await ExportWrapper.GetMessagesAsJsonAsync(ChannelIds.DateRangeTestCases);
|
||||
// Act
|
||||
var messages = await ExportWrapper.GetMessagesAsJsonAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
messages.Select(j => j.GetProperty("id").GetString()).Should().Equal(
|
||||
"866674314627121232",
|
||||
"866710679758045195",
|
||||
"866732113319428096",
|
||||
"868490009366396958",
|
||||
"868505966528835604",
|
||||
"868505969821364245",
|
||||
"868505973294268457",
|
||||
"885169254029213696"
|
||||
);
|
||||
// Assert
|
||||
messages.Select(j => j.GetProperty("id").GetString()).Should().Equal(
|
||||
"866674314627121232",
|
||||
"866710679758045195",
|
||||
"866732113319428096",
|
||||
"868490009366396958",
|
||||
"868505966528835604",
|
||||
"868505969821364245",
|
||||
"868505973294268457",
|
||||
"885169254029213696"
|
||||
);
|
||||
|
||||
messages.Select(j => j.GetProperty("content").GetString()).Should().Equal(
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
messages.Select(j => j.GetProperty("content").GetString()).Should().Equal(
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,53 +6,52 @@ using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||
|
||||
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
public record EmbedSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
[Fact]
|
||||
public async Task Message_with_an_embed_is_rendered_correctly()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Message_with_an_embed_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866769910729146400")
|
||||
);
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.EmbedTestCases,
|
||||
Snowflake.Parse("866769910729146400")
|
||||
);
|
||||
|
||||
var embed = message
|
||||
.GetProperty("embeds")
|
||||
.EnumerateArray()
|
||||
.Single();
|
||||
var embed = message
|
||||
.GetProperty("embeds")
|
||||
.EnumerateArray()
|
||||
.Single();
|
||||
|
||||
var embedAuthor = embed.GetProperty("author");
|
||||
var embedThumbnail = embed.GetProperty("thumbnail");
|
||||
var embedFooter = embed.GetProperty("footer");
|
||||
var embedFields = embed.GetProperty("fields").EnumerateArray().ToArray();
|
||||
var embedAuthor = embed.GetProperty("author");
|
||||
var embedThumbnail = embed.GetProperty("thumbnail");
|
||||
var embedFooter = embed.GetProperty("footer");
|
||||
var embedFields = embed.GetProperty("fields").EnumerateArray().ToArray();
|
||||
|
||||
// Assert
|
||||
embed.GetProperty("title").GetString().Should().Be("Embed title");
|
||||
embed.GetProperty("url").GetString().Should().Be("https://example.com");
|
||||
embed.GetProperty("timestamp").GetString().Should().Be("2021-07-14T21:00:00+00:00");
|
||||
embed.GetProperty("description").GetString().Should().Be("**Embed** _description_");
|
||||
embed.GetProperty("color").GetString().Should().Be("#58B9FF");
|
||||
embedAuthor.GetProperty("name").GetString().Should().Be("Embed author");
|
||||
embedAuthor.GetProperty("url").GetString().Should().Be("https://example.com/author");
|
||||
embedAuthor.GetProperty("iconUrl").GetString().Should().NotBeNullOrWhiteSpace();
|
||||
embedThumbnail.GetProperty("url").GetString().Should().NotBeNullOrWhiteSpace();
|
||||
embedThumbnail.GetProperty("width").GetInt32().Should().Be(120);
|
||||
embedThumbnail.GetProperty("height").GetInt32().Should().Be(120);
|
||||
embedFooter.GetProperty("text").GetString().Should().Be("Embed footer");
|
||||
embedFooter.GetProperty("iconUrl").GetString().Should().NotBeNullOrWhiteSpace();
|
||||
embedFields.Should().HaveCount(3);
|
||||
embedFields[0].GetProperty("name").GetString().Should().Be("Field 1");
|
||||
embedFields[0].GetProperty("value").GetString().Should().Be("Value 1");
|
||||
embedFields[0].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||
embedFields[1].GetProperty("name").GetString().Should().Be("Field 2");
|
||||
embedFields[1].GetProperty("value").GetString().Should().Be("Value 2");
|
||||
embedFields[1].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||
embedFields[2].GetProperty("name").GetString().Should().Be("Field 3");
|
||||
embedFields[2].GetProperty("value").GetString().Should().Be("Value 3");
|
||||
embedFields[2].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||
}
|
||||
// Assert
|
||||
embed.GetProperty("title").GetString().Should().Be("Embed title");
|
||||
embed.GetProperty("url").GetString().Should().Be("https://example.com");
|
||||
embed.GetProperty("timestamp").GetString().Should().Be("2021-07-14T21:00:00+00:00");
|
||||
embed.GetProperty("description").GetString().Should().Be("**Embed** _description_");
|
||||
embed.GetProperty("color").GetString().Should().Be("#58B9FF");
|
||||
embedAuthor.GetProperty("name").GetString().Should().Be("Embed author");
|
||||
embedAuthor.GetProperty("url").GetString().Should().Be("https://example.com/author");
|
||||
embedAuthor.GetProperty("iconUrl").GetString().Should().NotBeNullOrWhiteSpace();
|
||||
embedThumbnail.GetProperty("url").GetString().Should().NotBeNullOrWhiteSpace();
|
||||
embedThumbnail.GetProperty("width").GetInt32().Should().Be(120);
|
||||
embedThumbnail.GetProperty("height").GetInt32().Should().Be(120);
|
||||
embedFooter.GetProperty("text").GetString().Should().Be("Embed footer");
|
||||
embedFooter.GetProperty("iconUrl").GetString().Should().NotBeNullOrWhiteSpace();
|
||||
embedFields.Should().HaveCount(3);
|
||||
embedFields[0].GetProperty("name").GetString().Should().Be("Field 1");
|
||||
embedFields[0].GetProperty("value").GetString().Should().Be("Value 1");
|
||||
embedFields[0].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||
embedFields[1].GetProperty("name").GetString().Should().Be("Field 2");
|
||||
embedFields[1].GetProperty("value").GetString().Should().Be("Value 2");
|
||||
embedFields[1].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||
embedFields[2].GetProperty("name").GetString().Should().Be("Field 3");
|
||||
embedFields[2].GetProperty("value").GetString().Should().Be("Value 3");
|
||||
embedFields[2].GetProperty("isInline").GetBoolean().Should().BeTrue();
|
||||
}
|
||||
}
|
||||
@@ -6,66 +6,65 @@ using DiscordChatExporter.Core.Discord;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting;
|
||||
|
||||
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
public record MentionSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
[Fact]
|
||||
public async Task User_mention_is_rendered_correctly()
|
||||
{
|
||||
[Fact]
|
||||
public async Task User_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866458840245076028")
|
||||
);
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866458840245076028")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("User mention: @Tyrrrz");
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("User mention: @Tyrrrz");
|
||||
|
||||
message
|
||||
.GetProperty("mentions")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("id").GetString())
|
||||
.Should().Contain("128178626683338752");
|
||||
}
|
||||
message
|
||||
.GetProperty("mentions")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("id").GetString())
|
||||
.Should().Contain("128178626683338752");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Text_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459040480624680")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Text_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459040480624680")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Text channel mention: #mention-tests");
|
||||
}
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Text channel mention: #mention-tests");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Voice_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459175462633503")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Voice_channel_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459175462633503")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Voice channel mention: #chaos-vc [voice]");
|
||||
}
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Voice channel mention: #chaos-vc [voice]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Role_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459254693429258")
|
||||
);
|
||||
[Fact]
|
||||
public async Task Role_mention_is_rendered_correctly()
|
||||
{
|
||||
// Act
|
||||
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||
ChannelIds.MentionTestCases,
|
||||
Snowflake.Parse("866459254693429258")
|
||||
);
|
||||
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Role mention: @Role 1");
|
||||
}
|
||||
// Assert
|
||||
message.GetProperty("content").GetString().Should().Be("Role mention: @Role 1");
|
||||
}
|
||||
}
|
||||
@@ -10,58 +10,57 @@ using DiscordChatExporter.Core.Exporting.Partitioning;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public record PartitioningSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||
{
|
||||
public record PartitioningSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||
[Fact]
|
||||
public async Task Messages_partitioned_by_count_are_split_into_multiple_files_correctly()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Messages_partitioned_by_count_are_split_into_multiple_files_correctly()
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.HtmlDark,
|
||||
OutputPath = filePath,
|
||||
PartitionLimit = PartitionLimit.Parse("3")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.HtmlDark,
|
||||
OutputPath = filePath,
|
||||
PartitionLimit = PartitionLimit.Parse("3")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
// Assert
|
||||
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
||||
.Should()
|
||||
.HaveCount(3);
|
||||
}
|
||||
|
||||
// Assert
|
||||
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
||||
.Should()
|
||||
.HaveCount(3);
|
||||
}
|
||||
[Fact]
|
||||
public async Task Messages_partitioned_by_file_size_are_split_into_multiple_files_correctly()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_partitioned_by_file_size_are_split_into_multiple_files_correctly()
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
var fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.HtmlDark,
|
||||
OutputPath = filePath,
|
||||
PartitionLimit = PartitionLimit.Parse("20kb")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.DateRangeTestCases },
|
||||
ExportFormat = ExportFormat.HtmlDark,
|
||||
OutputPath = filePath,
|
||||
PartitionLimit = PartitionLimit.Parse("20kb")
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Assert
|
||||
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
||||
.Should()
|
||||
.HaveCount(2);
|
||||
}
|
||||
// Assert
|
||||
Directory.EnumerateFiles(dirPath, fileNameWithoutExt + "*")
|
||||
.Should()
|
||||
.HaveCount(2);
|
||||
}
|
||||
}
|
||||
@@ -4,28 +4,27 @@ using DiscordChatExporter.Cli.Tests.TestData;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting
|
||||
{
|
||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
// Act
|
||||
var document = await ExportWrapper.ExportAsPlainTextAsync(ChannelIds.DateRangeTestCases);
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs.PlainTextWriting;
|
||||
|
||||
// Assert
|
||||
document.Should().ContainAll(
|
||||
"Tyrrrz#5447",
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
public record ContentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||
{
|
||||
[Fact]
|
||||
public async Task Messages_are_exported_correctly()
|
||||
{
|
||||
// Act
|
||||
var document = await ExportWrapper.ExportAsPlainTextAsync(ChannelIds.DateRangeTestCases);
|
||||
|
||||
// Assert
|
||||
document.Should().ContainAll(
|
||||
"Tyrrrz#5447",
|
||||
"Hello world",
|
||||
"Goodbye world",
|
||||
"Foo bar",
|
||||
"Hurdle Durdle",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Yeet"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,39 +11,38 @@ using DiscordChatExporter.Core.Exporting;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs
|
||||
namespace DiscordChatExporter.Cli.Tests.Specs;
|
||||
|
||||
public record SelfContainedSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||
{
|
||||
public record SelfContainedSpecs(TempOutputFixture TempOutput) : IClassFixture<TempOutputFixture>
|
||||
[Fact]
|
||||
public async Task Messages_in_self_contained_export_only_reference_local_file_resources()
|
||||
{
|
||||
[Fact]
|
||||
public async Task Messages_in_self_contained_export_only_reference_local_file_resources()
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
// Arrange
|
||||
var filePath = TempOutput.GetTempFilePath();
|
||||
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.SelfContainedTestCases },
|
||||
ExportFormat = ExportFormat.HtmlDark,
|
||||
OutputPath = filePath,
|
||||
ShouldDownloadMedia = true
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
// Act
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||
ChannelIds = new[] { ChannelIds.SelfContainedTestCases },
|
||||
ExportFormat = ExportFormat.HtmlDark,
|
||||
OutputPath = filePath,
|
||||
ShouldDownloadMedia = true
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Html.Parse(data);
|
||||
|
||||
var data = await File.ReadAllTextAsync(filePath);
|
||||
var document = Html.Parse(data);
|
||||
|
||||
// Assert
|
||||
document
|
||||
.QuerySelectorAll("body [src]")
|
||||
.Select(e => e.GetAttribute("src")!)
|
||||
.Select(f => Path.GetFullPath(f, dirPath))
|
||||
.All(File.Exists)
|
||||
.Should()
|
||||
.BeTrue();
|
||||
}
|
||||
// Assert
|
||||
document
|
||||
.QuerySelectorAll("body [src]")
|
||||
.Select(e => e.GetAttribute("src")!)
|
||||
.Select(f => Path.GetFullPath(f, dirPath))
|
||||
.All(File.Exists)
|
||||
.Should()
|
||||
.BeTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user