-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTemporaryWorkbenchDirectory.cs
More file actions
52 lines (43 loc) · 1.6 KB
/
TemporaryWorkbenchDirectory.cs
File metadata and controls
52 lines (43 loc) · 1.6 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
namespace DotPilot.Tests;
internal sealed class TemporaryWorkbenchDirectory : IDisposable
{
private const string GitIgnoreFileName = ".gitignore";
private const string GitIgnoreContent =
"""
ignored/
*.tmp
""";
private TemporaryWorkbenchDirectory(string root)
{
Root = root;
}
public string Root { get; }
public static TemporaryWorkbenchDirectory Create(bool includeSupportedFiles = true)
{
var root = Path.Combine(
Path.GetTempPath(),
"dotpilot-workbench-tests",
Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(root);
File.WriteAllText(Path.Combine(root, GitIgnoreFileName), GitIgnoreContent);
if (includeSupportedFiles)
{
Directory.CreateDirectory(Path.Combine(root, "docs"));
Directory.CreateDirectory(Path.Combine(root, "src"));
Directory.CreateDirectory(Path.Combine(root, "ignored"));
File.WriteAllText(Path.Combine(root, "docs", "Architecture.md"), "# Architecture");
File.WriteAllText(Path.Combine(root, "src", "MainPage.xaml"), "<Page />");
File.WriteAllText(Path.Combine(root, "src", "SettingsPage.xaml"), "<Page />");
File.WriteAllText(Path.Combine(root, "ignored", "Secret.cs"), "internal sealed class Secret {}");
File.WriteAllText(Path.Combine(root, "notes.tmp"), "ignored");
}
return new(root);
}
public void Dispose()
{
if (Directory.Exists(Root))
{
Directory.Delete(Root, recursive: true);
}
}
}