-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepositoryPaths.Tests.cs
More file actions
67 lines (57 loc) · 2.57 KB
/
RepositoryPaths.Tests.cs
File metadata and controls
67 lines (57 loc) · 2.57 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Xunit;
namespace IntelliTect.Multitool.Tests;
public class RepositoryPathsTests
{
[Fact]
public void GetDefaultRepoRoot_ReturnsRepoRootDirectory()
{
// Makes the assumption that the repository directory for this solution is named the same as the solution
Assert.EndsWith(nameof(Multitool), RepositoryPaths.GetDefaultRepoRoot());
}
[Fact]
public void BuildVariables_BeingSetProperly()
{
Assert.Equal(3, RepositoryPaths.BuildVariables.Count);
Assert.True(RepositoryPaths.BuildVariables.TryGetValue("BuildingForLiveUnitTesting", out _));
Assert.True(RepositoryPaths.BuildVariables.TryGetValue("ProjectPath", out string? projectPath));
Assert.NotNull(projectPath);
Assert.NotEmpty(projectPath);
Assert.True(RepositoryPaths.BuildVariables.TryGetValue("SolutionDir", out string? solutionDir));
Assert.NotNull(solutionDir);
Assert.NotEmpty(solutionDir);
}
[Fact]
public void TrySearchForGitContainingDirectory_ReturnsTrueWhenFound()
{
Assert.True(RepositoryPaths.TrySearchForGitContainingDirectory(new DirectoryInfo(Directory.GetCurrentDirectory()), out string gitParentDirectory));
// Makes the assumption that the repository directory for this solution is named the same as the solution
Assert.EndsWith(nameof(Multitool), gitParentDirectory);
}
[Fact]
public void TrySearchForGitContainingDirectory_ReturnsFalseWhenNotFound()
{
string? path = Path.GetPathRoot(Directory.GetCurrentDirectory());
Assert.NotNull(path);
Assert.False(RepositoryPaths.TrySearchForGitContainingDirectory(new DirectoryInfo(path), out string gitParentDirectory));
Assert.Empty(gitParentDirectory);
}
[Fact]
public void TrySearchForGitContainingDirectory_ReturnsTrueWhenGitIsAFile()
{
// In a git worktree, .git is a file (gitfile pointer), not a directory.
// This test simulates that scenario.
string tempRoot = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
string subDir = Path.Combine(tempRoot, "subdir");
try
{
Directory.CreateDirectory(subDir);
File.WriteAllText(Path.Combine(tempRoot, ".git"), "gitdir: ../.git/worktrees/my-branch");
Assert.True(RepositoryPaths.TrySearchForGitContainingDirectory(new DirectoryInfo(subDir), out string gitParentDirectory));
Assert.Equal(tempRoot, gitParentDirectory);
}
finally
{
Directory.Delete(tempRoot, recursive: true);
}
}
}