process/src/Process.Tests/Fixtures/TestTempFile.cs

33 lines
749 B
C#
Raw Normal View History

2024-05-10 21:49:43 +02:00
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
2024-04-27 20:15:05 +02:00
using System.Reflection;
namespace Geekeey.Extensions.Process.Tests;
internal sealed class TestTempFile(string path) : IDisposable
{
public static TestTempFile Create()
{
var location = Assembly.GetExecutingAssembly().Location;
var pwd = System.IO.Path.GetDirectoryName(location) ?? Directory.GetCurrentDirectory();
var dirPath = System.IO.Path.Combine(pwd, "Temp");
Directory.CreateDirectory(dirPath);
var filePath = System.IO.Path.Combine(dirPath, Guid.NewGuid() + ".tmp");
return new TestTempFile(filePath);
}
public string Path { get; } = path;
public void Dispose()
{
try
{
File.Delete(Path);
}
catch (FileNotFoundException) { }
}
}