-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackendTestWorkspace.cs
More file actions
37 lines (31 loc) · 895 Bytes
/
Copy pathBackendTestWorkspace.cs
File metadata and controls
37 lines (31 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.IO;
using System.Text;
namespace AuroraScript.Tests;
internal sealed class BackendTestWorkspace : IDisposable
{
public BackendTestWorkspace()
{
Root = Path.Combine(Path.GetTempPath(), "aurora-backend-tests-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(Root);
}
public string Root { get; }
public string WriteSource(string relativePath, string source)
{
var path = Path.Combine(Root, relativePath);
var directory = Path.GetDirectoryName(path);
if (!string.IsNullOrEmpty(directory))
{
Directory.CreateDirectory(directory);
}
File.WriteAllText(path, source, Encoding.UTF8);
return path;
}
public void Dispose()
{
if (Directory.Exists(Root))
{
Directory.Delete(Root, recursive: true);
}
}
}