// Copyright (c) The Geekeey Authors // SPDX-License-Identifier: EUPL-1.2 namespace Geekeey.Process.Tests; internal sealed class TestEnvironment : IDisposable { private readonly Action _action; private TestEnvironment(Action action) { _action = action; } public static TestEnvironment Create(string name, string? value) { var lastValue = Environment.GetEnvironmentVariable(name); Environment.SetEnvironmentVariable(name, value); return new TestEnvironment(() => Environment.SetEnvironmentVariable(name, lastValue)); } public static TestEnvironment ExtendPath(string path) { return Create("PATH", Environment.GetEnvironmentVariable("PATH") + Path.PathSeparator + path); } public void Dispose() { _action(); } }