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/SelfContainedSpecs.cs

53 lines
1.6 KiB

3 years ago
using System.IO;
using System.Linq;
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.Cli.Tests.Utils;
using DiscordChatExporter.Core.Exporting;
using FluentAssertions;
using Xunit;
3 years ago
namespace DiscordChatExporter.Cli.Tests.Specs;
[Collection(nameof(ExportWrapperCollection))]
public class SelfContainedSpecs : IClassFixture<TempOutputFixture>
3 years ago
{
private readonly TempOutputFixture _tempOutput;
public SelfContainedSpecs(TempOutputFixture tempOutput)
{
_tempOutput = tempOutput;
}
3 years ago
[Fact]
public async Task Messages_in_self_contained_export_only_reference_local_file_resources()
3 years ago
{
3 years ago
// Arrange
var filePath = _tempOutput.GetTempFilePath();
3 years ago
var dirPath = Path.GetDirectoryName(filePath) ?? Directory.GetCurrentDirectory();
3 years ago
3 years ago
// Act
await new ExportChannelsCommand
{
Token = Secrets.DiscordToken,
3 years ago
ChannelIds = new[] { ChannelIds.SelfContainedTestCases },
ExportFormat = ExportFormat.HtmlDark,
OutputPath = filePath,
ShouldDownloadAssets = true
3 years ago
}.ExecuteAsync(new FakeConsole());
3 years ago
3 years ago
// Assert
Html
.Parse(await File.ReadAllTextAsync(filePath))
3 years ago
.QuerySelectorAll("body [src]")
.Select(e => e.GetAttribute("src")!)
.Select(f => Path.GetFullPath(f, dirPath))
.All(File.Exists)
.Should()
.BeTrue();
3 years ago
}
}