From 1393abbedebf8801cff890d4407d97f250b5be45 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Sun, 10 Nov 2024 00:06:37 +0100 Subject: [PATCH 1/3] ISourceFileNameProvider as an abstraction for everything that can provide a source file name. --- test/Providers.GremlinServer.Tests/IntegrationTests.cs | 4 ++-- test/Tests.Infrastructure/ISourceFileNameProvider.cs | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 test/Tests.Infrastructure/ISourceFileNameProvider.cs diff --git a/test/Providers.GremlinServer.Tests/IntegrationTests.cs b/test/Providers.GremlinServer.Tests/IntegrationTests.cs index aa1903abc..1f03160ae 100644 --- a/test/Providers.GremlinServer.Tests/IntegrationTests.cs +++ b/test/Providers.GremlinServer.Tests/IntegrationTests.cs @@ -15,7 +15,7 @@ namespace ExRam.Gremlinq.Providers.GremlinServer.Tests { [IntegrationTest("Linux", true)] [IntegrationTest("Windows")] - public class IntegrationTests : QueryExecutionTest, IClassFixture + public class IntegrationTests : QueryExecutionTest, IClassFixture, ISourceFileNameProvider { public IntegrationTests(GremlinServerContainerFixture fixture) : base( fixture, @@ -23,7 +23,7 @@ public IntegrationTests(GremlinServerContainerFixture fixture) : base( { } - public static string ThisFilePath() => ThisFile.GetName(); + public static string GetSourceFileName() => ThisFile.GetName(); [Fact] public async Task FirstAsync() => (await _g diff --git a/test/Tests.Infrastructure/ISourceFileNameProvider.cs b/test/Tests.Infrastructure/ISourceFileNameProvider.cs new file mode 100644 index 000000000..28a6b34f1 --- /dev/null +++ b/test/Tests.Infrastructure/ISourceFileNameProvider.cs @@ -0,0 +1,7 @@ +namespace ExRam.Gremlinq.Tests.Infrastructure +{ + public interface ISourceFileNameProvider + { + static abstract string GetSourceFileName(); + } +} From 83ba76a643d5dec419b7e978999ed2680136d6eb Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Sun, 10 Nov 2024 00:11:12 +0100 Subject: [PATCH 2/3] Introduce UseSnapshotDirectoryOf for SettingsTask to make it easy to mimick another test --- .../Extensions/SettingsTaskExtensions.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/Tests.Infrastructure/Extensions/SettingsTaskExtensions.cs b/test/Tests.Infrastructure/Extensions/SettingsTaskExtensions.cs index 4cb6df175..125af3503 100644 --- a/test/Tests.Infrastructure/Extensions/SettingsTaskExtensions.cs +++ b/test/Tests.Infrastructure/Extensions/SettingsTaskExtensions.cs @@ -9,5 +9,17 @@ public static class SettingsTaskExtensions public static SettingsTask ScrubRegex(this SettingsTask task, Regex regex, string replacement) => task.ScrubLinesWithReplace(str => regex.Replace(str, replacement)); public static SettingsTask ScrubGuids(this SettingsTask task) => task.ScrubRegex(GuidRegex, "12345678-9012-3456-7890-123456789012"); + + public static SettingsTask UseSnapshotDirectoryOf(this SettingsTask task) where T : ISourceFileNameProvider + { + if (Path.GetDirectoryName(T.GetSourceFileName()) is { } directory) + { + return task + .UseDirectory(directory) + .UseTypeName(typeof(T).Name); + } + + throw new InvalidOperationException(); + } } } From 194c31c78a98f16e74e7f2807244d85db98db3b2 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Sun, 10 Nov 2024 00:28:57 +0100 Subject: [PATCH 3/3] Supress warning about opt-in-features. They are obviously in error (see https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2252). --- test/Tests.Infrastructure/ISourceFileNameProvider.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Tests.Infrastructure/ISourceFileNameProvider.cs b/test/Tests.Infrastructure/ISourceFileNameProvider.cs index 28a6b34f1..2bdb5a271 100644 --- a/test/Tests.Infrastructure/ISourceFileNameProvider.cs +++ b/test/Tests.Infrastructure/ISourceFileNameProvider.cs @@ -1,4 +1,5 @@ -namespace ExRam.Gremlinq.Tests.Infrastructure +#pragma warning disable CA2252 +namespace ExRam.Gremlinq.Tests.Infrastructure { public interface ISourceFileNameProvider {