diff --git a/Telemetry.Tests/ProcessStateReset.cs b/Telemetry.Tests/ProcessStateReset.cs new file mode 100644 index 0000000..bea9832 --- /dev/null +++ b/Telemetry.Tests/ProcessStateReset.cs @@ -0,0 +1,25 @@ +using Telemetry; +using Xunit; + +[assembly: CollectionBehavior(DisableTestParallelization = true)] + +namespace Telemetry.Tests; + +internal static class ProcessStateReset +{ + private static readonly string[] Names = + [ + "RetryAfter", + "SentCount", + "FingerprintCounts", + "DrainClaimed", + ]; + + public static void Clear() + { + foreach (var name in Names) + { + ProcessState.Remove(name); + } + } +} diff --git a/Telemetry.Tests/Telemetry.Tests.csproj b/Telemetry.Tests/Telemetry.Tests.csproj new file mode 100644 index 0000000..0fb08a0 --- /dev/null +++ b/Telemetry.Tests/Telemetry.Tests.csproj @@ -0,0 +1,33 @@ + + + + net10.0-windows10.0.19041.0 + true + enable + enable + false + true + + + + + + + + + + + + + + + $(YMM4DirPath)YukkuriMovieMaker.Plugin.dll + false + + + + + + + + diff --git a/Telemetry.Tests/Ymm4AssemblyResolver.cs b/Telemetry.Tests/Ymm4AssemblyResolver.cs new file mode 100644 index 0000000..fb3ac71 --- /dev/null +++ b/Telemetry.Tests/Ymm4AssemblyResolver.cs @@ -0,0 +1,40 @@ +using System.IO; +using System.Reflection; +using System.Runtime.CompilerServices; + +namespace Telemetry.Tests; + +internal static class Ymm4AssemblyResolver +{ + private const string MetadataKey = "Ymm4Directory"; + private const string AssemblyExtension = ".dll"; + + [ModuleInitializer] + internal static void Initialize() + { + var directory = ReadDirectory(); + + if (string.IsNullOrWhiteSpace(directory)) + { + return; + } + + AppDomain.CurrentDomain.AssemblyResolve += (_, arguments) => + { + var name = new AssemblyName(arguments.Name).Name; + + if (name is null) + { + return null; + } + + var candidate = Path.Combine(directory, name + AssemblyExtension); + return File.Exists(candidate) ? Assembly.LoadFrom(candidate) : null; + }; + } + + private static string? ReadDirectory() => typeof(Ymm4AssemblyResolver).Assembly + .GetCustomAttributes() + .FirstOrDefault(attribute => string.Equals(attribute.Key, MetadataKey, StringComparison.Ordinal)) + ?.Value; +}