tests(git-provider): Add try .. finally to tests
This commit is contained in:
parent
fc3fe217e4
commit
adb3efc217
1 changed files with 74 additions and 51 deletions
|
|
@ -23,49 +23,60 @@ public class AddRegistrationTests
|
||||||
public Task BasicRepoRegistration((int testId, string path) testData)
|
public Task BasicRepoRegistration((int testId, string path) testData)
|
||||||
{
|
{
|
||||||
Settings.UseFileName($"{nameof(BasicRepoRegistration)}_{testData.testId}");
|
Settings.UseFileName($"{nameof(BasicRepoRegistration)}_{testData.testId}");
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance(nameof(BasicRepoRegistration));
|
var gitManager = GitManager.InternalFreshInstance(nameof(BasicRepoRegistration));
|
||||||
|
|
||||||
var repoRegistration = gitManager.RegisterRepo("Test:/some/test/repo", testData.path);
|
try
|
||||||
var sb = new StringBuilder();
|
{
|
||||||
sb.AppendLine($"Attempted to register: {testData.path}")
|
var repoRegistration = gitManager.RegisterRepo("Test:/some/test/repo", testData.path);
|
||||||
.AppendLine($"Registration result: {repoRegistration}");
|
var sb = new StringBuilder();
|
||||||
|
sb.AppendLine($"Attempted to register: {testData.path}")
|
||||||
|
.AppendLine($"Registration result: {repoRegistration}");
|
||||||
|
|
||||||
gitManager.DeleteDatabase();
|
return Verify(sb, Settings);
|
||||||
|
}
|
||||||
return Verify(sb, Settings);
|
finally
|
||||||
|
{
|
||||||
|
gitManager.DeleteDatabase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RepoRegistrationWithEmptyName()
|
public void RepoRegistrationWithEmptyName()
|
||||||
{
|
{
|
||||||
Settings.UseFileName(nameof(RepoRegistrationWithEmptyName));
|
Settings.UseFileName(nameof(RepoRegistrationWithEmptyName));
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithEmptyName));
|
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithEmptyName));
|
||||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||||
|
|
||||||
var emptyName = gitManager.RegisterRepo(testRepoAbsolutePath, "");
|
try
|
||||||
|
{
|
||||||
|
var emptyName = gitManager.RegisterRepo(testRepoAbsolutePath, "");
|
||||||
|
|
||||||
gitManager.DeleteDatabase();
|
Assert.Equal("repo", emptyName);
|
||||||
|
}
|
||||||
Assert.Equal("repo", emptyName);
|
finally
|
||||||
|
{
|
||||||
|
gitManager.DeleteDatabase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RepoRegistrationWithNullName()
|
public void RepoRegistrationWithNullName()
|
||||||
{
|
{
|
||||||
Settings.UseFileName(nameof(RepoRegistrationWithNullName));
|
Settings.UseFileName(nameof(RepoRegistrationWithNullName));
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithNullName));
|
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithNullName));
|
||||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 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!);
|
||||||
|
|
||||||
// Name is technically not-nullable, but string is a reference type so null can be passed in so we should test
|
Assert.Equal("repo", nullName);
|
||||||
// it regardless
|
}
|
||||||
var nullName = gitManager.RegisterRepo(testRepoAbsolutePath, null!);
|
finally
|
||||||
|
{
|
||||||
gitManager.DeleteDatabase();
|
gitManager.DeleteDatabase();
|
||||||
|
}
|
||||||
Assert.Equal("repo", nullName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -75,55 +86,67 @@ public class AddRegistrationTests
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
|
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var whitespaceName = gitManager.RegisterRepo(testRepoAbsolutePath, " ");
|
||||||
|
|
||||||
var whitespaceName = gitManager.RegisterRepo(testRepoAbsolutePath, " ");
|
Assert.Equal("repo", whitespaceName);
|
||||||
|
}
|
||||||
gitManager.DeleteDatabase();
|
finally
|
||||||
|
{
|
||||||
Assert.Equal("repo", whitespaceName);
|
gitManager.DeleteDatabase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DuplicateRepoRegistrationShouldFail()
|
public void DuplicateRepoRegistrationShouldFail()
|
||||||
{
|
{
|
||||||
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
|
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||||
string[] paths = ["test", "nested", "path"];
|
string[] paths = ["test", "nested", "path"];
|
||||||
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
|
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
|
||||||
|
|
||||||
var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator);
|
try
|
||||||
// TODO: make nested registrations fail in both directions and test
|
{
|
||||||
var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]));
|
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.Equal(Path.Combine(paths), firstRegistration);
|
||||||
Assert.Equal(Path.Combine(paths[..1]), secondRegistration);
|
Assert.Equal(Path.Combine(paths[..1]), secondRegistration);
|
||||||
|
|
||||||
Assert.Throws<Exception>(() => gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1])));
|
Assert.Throws<Exception>(() => gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1])));
|
||||||
|
}
|
||||||
gitManager.DeleteDatabase();
|
finally
|
||||||
|
{
|
||||||
|
gitManager.DeleteDatabase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DuplicateRepoRegistrationDifferentSlashShouldNotFail()
|
public void DuplicateRepoRegistrationDifferentSlashShouldNotFail()
|
||||||
{
|
{
|
||||||
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
|
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||||
string[] paths = ["test", "nested", "path"];
|
string[] paths = ["test", "nested", "path"];
|
||||||
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
|
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
|
||||||
|
|
||||||
var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator);
|
try
|
||||||
// TODO: make nested registrations fail in both directions and test
|
{
|
||||||
var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]));
|
var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator);
|
||||||
var differentPathSeparatorRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator);
|
// TODO: make nested registrations fail in both directions and test
|
||||||
|
var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]));
|
||||||
|
var differentPathSeparatorRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator);
|
||||||
|
|
||||||
gitManager.DeleteDatabase();
|
Assert.Equal(Path.Combine(paths), firstRegistration);
|
||||||
|
Assert.Equal(Path.Combine(paths[..1]), secondRegistration);
|
||||||
Assert.Equal(Path.Combine(paths), firstRegistration);
|
Assert.Equal(names.AltSeparator, differentPathSeparatorRegistration);
|
||||||
Assert.Equal(Path.Combine(paths[..1]), secondRegistration);
|
}
|
||||||
Assert.Equal(names.AltSeparator, differentPathSeparatorRegistration);
|
finally
|
||||||
|
{
|
||||||
|
gitManager.DeleteDatabase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue