process/src/process.tests/_fixture/TestEnvironment.cs
Louis Seubert 0de3af3033
All checks were successful
release / dotnet-release-workflow (push) Successful in 1m12s
default / dotnet-default-workflow (push) Successful in 1m14s
build: initial project release
2026-01-21 22:27:57 +01:00

32 lines
No EOL
741 B
C#

// 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();
}
}