mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-30 14:35:18 -04:00
Improve tests
This commit is contained in:
parent
85d53d0e94
commit
d735d2acd3
3 changed files with 121 additions and 64 deletions
3
.github/workflows/CI.yml
vendored
3
.github/workflows/CI.yml
vendored
|
@ -22,6 +22,9 @@ jobs:
|
|||
|
||||
- name: Build & test
|
||||
run: dotnet test --configuration Release --logger GitHubActions
|
||||
env:
|
||||
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
|
||||
DISCORD_TOKEN_BOT: true
|
||||
|
||||
- name: Upload coverage
|
||||
uses: codecov/codecov-action@v1.0.5
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "json");
|
||||
|
||||
// Act
|
||||
var jsonData = await GlobalCache.WrapAsync("mention-specs-output-json", async () =>
|
||||
{
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
|
@ -45,7 +47,9 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
OutputPath = outputFilePath
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var jsonData = await File.ReadAllTextAsync(outputFilePath);
|
||||
return await File.ReadAllTextAsync(outputFilePath);
|
||||
});
|
||||
|
||||
_testOutput.WriteLine(jsonData);
|
||||
|
||||
var json = Json.Parse(jsonData);
|
||||
|
@ -81,6 +85,8 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html");
|
||||
|
||||
// Act
|
||||
var htmlData = await GlobalCache.WrapAsync("mention-specs-output-html", async () =>
|
||||
{
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
|
@ -90,7 +96,9 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
OutputPath = outputFilePath
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var htmlData = await File.ReadAllTextAsync(outputFilePath);
|
||||
return await File.ReadAllTextAsync(outputFilePath);
|
||||
});
|
||||
|
||||
_testOutput.WriteLine(htmlData);
|
||||
|
||||
var html = Html.Parse(htmlData);
|
||||
|
@ -110,6 +118,8 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "json");
|
||||
|
||||
// Act
|
||||
var jsonData = await GlobalCache.WrapAsync("mention-specs-output-json", async () =>
|
||||
{
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
|
@ -119,7 +129,9 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
OutputPath = outputFilePath
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var jsonData = await File.ReadAllTextAsync(outputFilePath);
|
||||
return await File.ReadAllTextAsync(outputFilePath);
|
||||
});
|
||||
|
||||
_testOutput.WriteLine(jsonData);
|
||||
|
||||
var json = Json.Parse(jsonData);
|
||||
|
@ -148,6 +160,8 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html");
|
||||
|
||||
// Act
|
||||
var htmlData = await GlobalCache.WrapAsync("mention-specs-output-html", async () =>
|
||||
{
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
|
@ -157,7 +171,9 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
OutputPath = outputFilePath
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var htmlData = await File.ReadAllTextAsync(outputFilePath);
|
||||
return await File.ReadAllTextAsync(outputFilePath);
|
||||
});
|
||||
|
||||
_testOutput.WriteLine(htmlData);
|
||||
|
||||
var html = Html.Parse(htmlData);
|
||||
|
@ -176,6 +192,8 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "json");
|
||||
|
||||
// Act
|
||||
var jsonData = await GlobalCache.WrapAsync("mention-specs-output-json", async () =>
|
||||
{
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
|
@ -185,7 +203,9 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
OutputPath = outputFilePath
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var jsonData = await File.ReadAllTextAsync(outputFilePath);
|
||||
return await File.ReadAllTextAsync(outputFilePath);
|
||||
});
|
||||
|
||||
_testOutput.WriteLine(jsonData);
|
||||
|
||||
var json = Json.Parse(jsonData);
|
||||
|
@ -214,6 +234,8 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html");
|
||||
|
||||
// Act
|
||||
var htmlData = await GlobalCache.WrapAsync("mention-specs-output-html", async () =>
|
||||
{
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
|
@ -223,7 +245,9 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
OutputPath = outputFilePath
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var htmlData = await File.ReadAllTextAsync(outputFilePath);
|
||||
return await File.ReadAllTextAsync(outputFilePath);
|
||||
});
|
||||
|
||||
_testOutput.WriteLine(htmlData);
|
||||
|
||||
var html = Html.Parse(htmlData);
|
||||
|
@ -242,6 +266,8 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "json");
|
||||
|
||||
// Act
|
||||
var jsonData = await GlobalCache.WrapAsync("mention-specs-output-json", async () =>
|
||||
{
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
|
@ -251,7 +277,9 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
OutputPath = outputFilePath
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var jsonData = await File.ReadAllTextAsync(outputFilePath);
|
||||
return await File.ReadAllTextAsync(outputFilePath);
|
||||
});
|
||||
|
||||
_testOutput.WriteLine(jsonData);
|
||||
|
||||
var json = Json.Parse(jsonData);
|
||||
|
@ -280,6 +308,8 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html");
|
||||
|
||||
// Act
|
||||
var htmlData = await GlobalCache.WrapAsync("mention-specs-output-html", async () =>
|
||||
{
|
||||
await new ExportChannelsCommand
|
||||
{
|
||||
TokenValue = Secrets.DiscordToken,
|
||||
|
@ -289,7 +319,9 @@ namespace DiscordChatExporter.Cli.Tests
|
|||
OutputPath = outputFilePath
|
||||
}.ExecuteAsync(new FakeConsole());
|
||||
|
||||
var htmlData = await File.ReadAllTextAsync(outputFilePath);
|
||||
return await File.ReadAllTextAsync(outputFilePath);
|
||||
});
|
||||
|
||||
_testOutput.WriteLine(htmlData);
|
||||
|
||||
var html = Html.Parse(htmlData);
|
||||
|
|
22
DiscordChatExporter.Cli.Tests/Utils/GlobalCache.cs
Normal file
22
DiscordChatExporter.Cli.Tests/Utils/GlobalCache.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Utils
|
||||
{
|
||||
internal static class GlobalCache
|
||||
{
|
||||
private static readonly Dictionary<string, object?> Dictionary = new();
|
||||
|
||||
public static async Task<T> WrapAsync<T>(string key, Func<Task<T>> getAsync)
|
||||
{
|
||||
if (Dictionary.TryGetValue(key, out var value) && value is T existing)
|
||||
return existing;
|
||||
|
||||
var result = await getAsync();
|
||||
Dictionary[key] = result;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue