96 lines
No EOL
3 KiB
C#
96 lines
No EOL
3 KiB
C#
using System.Text;
|
|
using ModuleCore.Calendar;
|
|
using ModuleCore.Git;
|
|
using ModuleTests.Git.TestData;
|
|
|
|
namespace ModuleTests.Git;
|
|
|
|
public class AddRegistrationTests
|
|
{
|
|
private static readonly VerifySettings Settings;
|
|
|
|
static AddRegistrationTests()
|
|
{
|
|
Settings = new VerifySettings();
|
|
var testBaseDirectory = Path.Join(TestConstants.SnapshotFolderName, nameof(AddRegistrationTests));
|
|
|
|
Settings.UseDirectory(testBaseDirectory);
|
|
Settings.DisableDiff();
|
|
}
|
|
|
|
[Theory]
|
|
[ClassData(typeof(AddRegistrationTestData))]
|
|
public Task BasicRepoRegistration((int testId, string path) testData)
|
|
{
|
|
Settings.UseFileName($"{nameof(BasicRepoRegistration)}_{testData.testId}");
|
|
|
|
var gitManager = GitManager.InternalFreshInstance;
|
|
|
|
var repoRegistration = gitManager.RegisterRepo("Test:/some/test/repo", testData.path);
|
|
var sb = new StringBuilder();
|
|
sb.AppendLine($"Attempted to register: {testData.path}")
|
|
.AppendLine($"Registration result: {repoRegistration}");
|
|
|
|
return Verify(sb, Settings);
|
|
}
|
|
|
|
[Fact]
|
|
public void RepoRegistrationWithEmptyName()
|
|
{
|
|
Settings.UseFileName(nameof(RepoRegistrationWithEmptyName));
|
|
|
|
var gitManager = GitManager.InternalFreshInstance;
|
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
|
|
|
var emptyName = gitManager.RegisterRepo(testRepoAbsolutePath, "");
|
|
|
|
Assert.Equal("repo", emptyName);
|
|
}
|
|
|
|
[Fact]
|
|
public void RepoRegistrationWithNullName()
|
|
{
|
|
Settings.UseFileName(nameof(RepoRegistrationWithNullName));
|
|
|
|
var gitManager = GitManager.InternalFreshInstance;
|
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
|
|
|
// Name is technically not-nullable, but string is a reference type so null can be passed in so we should test
|
|
// it regardless
|
|
var nullName = gitManager.RegisterRepo(testRepoAbsolutePath, null!);
|
|
|
|
Assert.Equal("repo", nullName);
|
|
}
|
|
|
|
[Fact]
|
|
public void RepoRegistrationWithWhitespaceName()
|
|
{
|
|
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
|
|
|
var gitManager = GitManager.InternalFreshInstance;
|
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
|
|
|
var whitespaceName = gitManager.RegisterRepo(testRepoAbsolutePath, " ");
|
|
|
|
Assert.Equal("repo", whitespaceName);
|
|
}
|
|
|
|
[Fact]
|
|
public void DuplicateRepoRegistrationShouldFail()
|
|
{
|
|
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
|
|
|
var gitManager = GitManager.InternalFreshInstance;
|
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
|
string[] paths = ["test", "nested", "path"];
|
|
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
|
|
|
|
var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator);
|
|
// TODO: make nested registrations fail in both directions and test
|
|
var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]));
|
|
|
|
Assert.Equal(Path.Combine(paths), firstRegistration);
|
|
|
|
Assert.Throws<Exception>(() => gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator));
|
|
}
|
|
} |