Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 1d9563e

Browse files
committed
Add HasNoRemoteOrigin tests
1 parent 835ebb1 commit 1d9563e

File tree

1 file changed

+90
-7
lines changed

1 file changed

+90
-7
lines changed

test/GitHub.Exports.UnitTests/GitServiceIntegrationTests.cs

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,50 @@
77

88
public class GitServiceIntegrationTests
99
{
10-
public class TheCreateLocalRepositoryModelMethod : TestBaseClass
10+
public class TheCreateLocalRepositoryModelMethod
1111
{
12-
[TestCase(true)]
13-
[TestCase(false)]
14-
public void NoRepository_Same_As_Repository_With_No_CloneUrl(bool createRepository)
12+
[Test]
13+
public void Empty_Repository()
1514
{
16-
using (var temp = new TempDirectory())
15+
using (var temp = new TempRepository())
1716
{
1817
var path = temp.Directory.FullName;
19-
if (createRepository)
18+
var target = new GitService(new RepositoryFacade());
19+
20+
var model = target.CreateLocalRepositoryModel(path);
21+
22+
Assert.That(model, Is.Not.Null);
23+
Assert.That(model.LocalPath, Is.EqualTo(path));
24+
Assert.That(model.Name, Is.EqualTo(temp.Directory.Name));
25+
}
26+
}
27+
28+
[TestCase("origin", "https://github.com/github/VisualStudio", false)]
29+
[TestCase("not_origin", "https://github.com/github/VisualStudio", true)]
30+
[TestCase(null, null, false, Description = "Has no remotes")]
31+
public void Check_HasNoRemoteOrigin(string remoteName, string remoteUrl, bool hasNoRemoteOrigin)
32+
{
33+
using (var temp = new TempRepository())
34+
{
35+
if (remoteName != null)
2036
{
21-
using (var repo = new Repository(Repository.Init(path))) { }
37+
temp.Repository.Network.Remotes.Add(remoteName, remoteUrl);
2238
}
39+
var path = temp.Directory.FullName;
40+
var target = new GitService(new RepositoryFacade());
41+
42+
var model = target.CreateLocalRepositoryModel(path);
43+
44+
Assert.That(model.HasNoRemoteOrigin, Is.EqualTo(hasNoRemoteOrigin));
45+
}
46+
}
2347

48+
[Test]
49+
public void NoRepository_Same_As_Repository_With_No_CloneUrl()
50+
{
51+
using (var temp = new TempDirectory())
52+
{
53+
var path = temp.Directory.FullName;
2454
var target = new GitService(new RepositoryFacade());
2555

2656
var model = target.CreateLocalRepositoryModel(path);
@@ -234,4 +264,57 @@ static void AddTrackedBranch(Repository repo, Branch branch, Commit commit,
234264
repo.Branches.Update(branch, b => b.TrackedBranch = canonicalName);
235265
}
236266
}
267+
268+
protected class TempRepository : TempDirectory
269+
{
270+
public TempRepository()
271+
: base()
272+
{
273+
Repository = CreateRepository(Directory.FullName);
274+
}
275+
276+
static Repository CreateRepository(string path)
277+
{
278+
return new Repository(Repository.Init(path));
279+
}
280+
281+
public Repository Repository
282+
{
283+
get;
284+
}
285+
}
286+
287+
protected class TempDirectory : IDisposable
288+
{
289+
public TempDirectory()
290+
{
291+
var f = Path.GetTempFileName();
292+
var name = Path.GetFileNameWithoutExtension(f);
293+
File.Delete(f);
294+
Directory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), name));
295+
Directory.Create();
296+
}
297+
298+
public DirectoryInfo Directory { get; }
299+
300+
public void Dispose()
301+
{
302+
// Remove any read-only attributes
303+
SetFileAttributes(Directory, FileAttributes.Normal);
304+
Directory.Delete(true);
305+
}
306+
307+
static void SetFileAttributes(DirectoryInfo dir, FileAttributes attributes)
308+
{
309+
foreach (DirectoryInfo subdir in dir.GetDirectories())
310+
{
311+
SetFileAttributes(subdir, attributes);
312+
}
313+
314+
foreach (var file in dir.GetFiles())
315+
{
316+
File.SetAttributes(file.FullName, attributes);
317+
}
318+
}
319+
}
237320
}

0 commit comments

Comments
 (0)