From 9c25bceabf4b751ce3b79912e98251916a9288de Mon Sep 17 00:00:00 2001 From: Tyrrrz Date: Mon, 19 Jul 2021 21:07:36 +0300 Subject: [PATCH] Fix isolation in tests --- DiscordChatExporter.Cli.Tests/EmbedSpecs.cs | 2 +- .../Fixtures/TempOutputFixture.cs | 14 ++++++++++---- DiscordChatExporter.Cli.Tests/MentionSpecs.cs | 16 ++++++++-------- DiscordChatExporter.Cli.Tests/ReplySpecs.cs | 6 +++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/DiscordChatExporter.Cli.Tests/EmbedSpecs.cs b/DiscordChatExporter.Cli.Tests/EmbedSpecs.cs index 1e38509..968a808 100644 --- a/DiscordChatExporter.Cli.Tests/EmbedSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/EmbedSpecs.cs @@ -29,7 +29,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task Message_with_YouTube_video_is_rendered_with_a_player_in_HTML() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html"); + var outputFilePath = _tempOutput.GetTempFilePath("html"); // Act var htmlData = await GlobalCache.WrapAsync("embed-specs-output-html", async () => diff --git a/DiscordChatExporter.Cli.Tests/Fixtures/TempOutputFixture.cs b/DiscordChatExporter.Cli.Tests/Fixtures/TempOutputFixture.cs index 1e9a2b7..f2991e0 100644 --- a/DiscordChatExporter.Cli.Tests/Fixtures/TempOutputFixture.cs +++ b/DiscordChatExporter.Cli.Tests/Fixtures/TempOutputFixture.cs @@ -7,19 +7,25 @@ namespace DiscordChatExporter.Cli.Tests.Fixtures { public string DirPath => Path.Combine( Path.GetDirectoryName(typeof(TempOutputFixture).Assembly.Location) ?? Directory.GetCurrentDirectory(), - "Temp" + "Temp", + Guid.NewGuid().ToString() ); public TempOutputFixture() => Directory.CreateDirectory(DirPath); - public string GetTempFilePath(string fileName) => Path.Combine(DirPath, fileName); + public string GetTempFilePath() => Path.Combine(DirPath, Guid.NewGuid().ToString()); - public string GetTempFilePath() => GetTempFilePath(Guid.NewGuid().ToString()); + public string GetTempFilePath(string extension) => Path.ChangeExtension(GetTempFilePath(), extension); public void Dispose() { - if (Directory.Exists(DirPath)) + try + { Directory.Delete(DirPath, true); + } + catch (DirectoryNotFoundException) + { + } } } } \ No newline at end of file diff --git a/DiscordChatExporter.Cli.Tests/MentionSpecs.cs b/DiscordChatExporter.Cli.Tests/MentionSpecs.cs index e02baac..b03fd7c 100644 --- a/DiscordChatExporter.Cli.Tests/MentionSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/MentionSpecs.cs @@ -33,7 +33,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task User_mention_is_rendered_correctly_in_JSON() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "json"); + var outputFilePath = _tempOutput.GetTempFilePath("json"); // Act var jsonData = await GlobalCache.WrapAsync("mention-specs-output-json", async () => @@ -82,7 +82,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task User_mention_is_rendered_correctly_in_HTML() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html"); + var outputFilePath = _tempOutput.GetTempFilePath("html"); // Act var htmlData = await GlobalCache.WrapAsync("mention-specs-output-html", async () => @@ -115,7 +115,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task Text_channel_mention_is_rendered_correctly_in_JSON() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "json"); + var outputFilePath = _tempOutput.GetTempFilePath("json"); // Act var jsonData = await GlobalCache.WrapAsync("mention-specs-output-json", async () => @@ -157,7 +157,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task Text_channel_mention_is_rendered_correctly_in_HTML() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html"); + var outputFilePath = _tempOutput.GetTempFilePath("html"); // Act var htmlData = await GlobalCache.WrapAsync("mention-specs-output-html", async () => @@ -189,7 +189,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task Voice_channel_mention_is_rendered_correctly_in_JSON() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "json"); + var outputFilePath = _tempOutput.GetTempFilePath("json"); // Act var jsonData = await GlobalCache.WrapAsync("mention-specs-output-json", async () => @@ -231,7 +231,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task Voice_channel_mention_is_rendered_correctly_in_HTML() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html"); + var outputFilePath = _tempOutput.GetTempFilePath("html"); // Act var htmlData = await GlobalCache.WrapAsync("mention-specs-output-html", async () => @@ -263,7 +263,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task Role_mention_is_rendered_correctly_in_JSON() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "json"); + var outputFilePath = _tempOutput.GetTempFilePath("json"); // Act var jsonData = await GlobalCache.WrapAsync("mention-specs-output-json", async () => @@ -305,7 +305,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task Role_mention_is_rendered_correctly_in_HTML() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html"); + var outputFilePath = _tempOutput.GetTempFilePath("html"); // Act var htmlData = await GlobalCache.WrapAsync("mention-specs-output-html", async () => diff --git a/DiscordChatExporter.Cli.Tests/ReplySpecs.cs b/DiscordChatExporter.Cli.Tests/ReplySpecs.cs index 5b1b0ea..44b0eaf 100644 --- a/DiscordChatExporter.Cli.Tests/ReplySpecs.cs +++ b/DiscordChatExporter.Cli.Tests/ReplySpecs.cs @@ -30,7 +30,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task Reply_to_a_normal_message_is_rendered_correctly_in_HTML() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html"); + var outputFilePath = _tempOutput.GetTempFilePath("html"); // Act var htmlData = await GlobalCache.WrapAsync("reply-specs-output-html", async () => @@ -64,7 +64,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task Reply_to_a_deleted_message_is_rendered_correctly_in_HTML() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html"); + var outputFilePath = _tempOutput.GetTempFilePath("html"); // Act var htmlData = await GlobalCache.WrapAsync("reply-specs-output-html", async () => @@ -98,7 +98,7 @@ namespace DiscordChatExporter.Cli.Tests public async Task Reply_to_a_empty_message_with_attachment_is_rendered_correctly_in_HTML() { // Arrange - var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html"); + var outputFilePath = _tempOutput.GetTempFilePath("html"); // Act var htmlData = await GlobalCache.WrapAsync("reply-specs-output-html", async () =>