Skip to content

Commit 4cb81d1

Browse files
yorahnulltoken
authored andcommitted
Move Fetch tests in separate file
1 parent 8e47d87 commit 4cb81d1

File tree

3 files changed

+108
-103
lines changed

3 files changed

+108
-103
lines changed

LibGit2Sharp.Tests/FetchFixture.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System.Collections.Generic;
2+
using LibGit2Sharp.Tests.TestHelpers;
3+
using Xunit.Extensions;
4+
5+
namespace LibGit2Sharp.Tests
6+
{
7+
public class FetchFixture : BaseFixture
8+
{
9+
private const string remoteName = "testRemote";
10+
11+
[Theory]
12+
[InlineData("http://github.com/libgit2/TestGitRepository")]
13+
[InlineData("https://github.com/libgit2/TestGitRepository")]
14+
[InlineData("git://github.com/libgit2/TestGitRepository.git")]
15+
public void CanFetchIntoAnEmptyRepository(string url)
16+
{
17+
var scd = BuildSelfCleaningDirectory();
18+
using (var repo = Repository.Init(scd.RootedDirectoryPath))
19+
{
20+
Remote remote = repo.Network.Remotes.Add(remoteName, url);
21+
22+
// Set up structures for the expected results
23+
// and verifying the RemoteUpdateTips callback.
24+
TestRemoteInfo expectedResults = TestRemoteInfo.TestRemoteInstance;
25+
var expectedFetchState = new ExpectedFetchState(remoteName);
26+
27+
// Add expected branch objects
28+
foreach (KeyValuePair<string, ObjectId> kvp in expectedResults.BranchTips)
29+
{
30+
expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
31+
}
32+
33+
// Add the expected tags
34+
string[] expectedTagNames = { "blob", "commit_tree", "annotated_tag" };
35+
foreach (string tagName in expectedTagNames)
36+
{
37+
TestRemoteInfo.ExpectedTagInfo expectedTagInfo = expectedResults.Tags[tagName];
38+
expectedFetchState.AddExpectedTag(tagName, ObjectId.Zero, expectedTagInfo);
39+
}
40+
41+
// Perform the actual fetch
42+
remote.Fetch(onUpdateTips: expectedFetchState.RemoteUpdateTipsHandler);
43+
44+
// Verify the expected
45+
expectedFetchState.CheckUpdatedReferences(repo);
46+
}
47+
}
48+
49+
[SkippableFact]
50+
public void CanFetchIntoAnEmptyRepositoryWithCredentials()
51+
{
52+
InconclusiveIf(() => string.IsNullOrEmpty(Constants.PrivateRepoUrl),
53+
"Populate Constants.PrivateRepo* to run this test");
54+
55+
var scd = BuildSelfCleaningDirectory();
56+
using (var repo = Repository.Init(scd.RootedDirectoryPath))
57+
{
58+
Remote remote = repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);
59+
60+
// Perform the actual fetch
61+
remote.Fetch(credentials: new Credentials
62+
{
63+
Username = Constants.PrivateRepoUsername,
64+
Password = Constants.PrivateRepoPassword
65+
});
66+
}
67+
}
68+
69+
[Theory]
70+
[InlineData("http://github.com/libgit2/TestGitRepository")]
71+
[InlineData("https://github.com/libgit2/TestGitRepository")]
72+
[InlineData("git://github.com/libgit2/TestGitRepository.git")]
73+
public void CanFetchAllTagsIntoAnEmptyRepository(string url)
74+
{
75+
var scd = BuildSelfCleaningDirectory();
76+
using (var repo = Repository.Init(scd.RootedDirectoryPath))
77+
{
78+
Remote remote = repo.Network.Remotes.Add(remoteName, url);
79+
80+
// Set up structures for the expected results
81+
// and verifying the RemoteUpdateTips callback.
82+
TestRemoteInfo remoteInfo = TestRemoteInfo.TestRemoteInstance;
83+
var expectedFetchState = new ExpectedFetchState(remoteName);
84+
85+
// Add expected branch objects
86+
foreach (KeyValuePair<string, ObjectId> kvp in remoteInfo.BranchTips)
87+
{
88+
expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
89+
}
90+
91+
// Add expected tags
92+
foreach (KeyValuePair<string, TestRemoteInfo.ExpectedTagInfo> kvp in remoteInfo.Tags)
93+
{
94+
expectedFetchState.AddExpectedTag(kvp.Key, ObjectId.Zero, kvp.Value);
95+
}
96+
97+
// Perform the actual fetch
98+
remote.Fetch(TagFetchMode.All, onUpdateTips: expectedFetchState.RemoteUpdateTipsHandler);
99+
100+
// Verify the expected
101+
expectedFetchState.CheckUpdatedReferences(repo);
102+
}
103+
}
104+
}
105+
}

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
</ItemGroup>
6060
<ItemGroup>
6161
<Compile Include="CheckoutFixture.cs" />
62+
<Compile Include="RemoteFixture.cs" />
6263
<Compile Include="StageFixture.cs" />
6364
<Compile Include="StashFixture.cs" />
6465
<Compile Include="CloneFixture.cs" />
@@ -84,7 +85,7 @@
8485
<Compile Include="RepositoryOptionsFixture.cs" />
8586
<Compile Include="ResetHeadFixture.cs" />
8687
<Compile Include="LazyFixture.cs" />
87-
<Compile Include="RemoteFixture.cs" />
88+
<Compile Include="FetchFixture.cs" />
8889
<Compile Include="ResetIndexFixture.cs" />
8990
<Compile Include="StatusFixture.cs" />
9091
<Compile Include="TestHelpers\BaseFixture.cs" />

LibGit2Sharp.Tests/RemoteFixture.cs

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Collections.Generic;
2-
using LibGit2Sharp.Tests.TestHelpers;
1+
using LibGit2Sharp.Tests.TestHelpers;
32
using Xunit;
43
using Xunit.Extensions;
54

@@ -68,106 +67,6 @@ public void CanCheckEqualityOfRemote()
6867
}
6968
}
7069

71-
[Theory]
72-
[InlineData("http://github.com/libgit2/TestGitRepository")]
73-
[InlineData("https://github.com/libgit2/TestGitRepository")]
74-
[InlineData("git://github.com/libgit2/TestGitRepository.git")]
75-
public void CanFetchIntoAnEmptyRepository(string url)
76-
{
77-
string remoteName = "testRemote";
78-
79-
var scd = BuildSelfCleaningDirectory();
80-
using (var repo = Repository.Init(scd.RootedDirectoryPath))
81-
{
82-
Remote remote = repo.Network.Remotes.Add(remoteName, url);
83-
84-
// Set up structures for the expected results
85-
// and verifying the RemoteUpdateTips callback.
86-
TestRemoteInfo expectedResults = TestRemoteInfo.TestRemoteInstance;
87-
ExpectedFetchState expectedFetchState = new ExpectedFetchState(remoteName);
88-
89-
// Add expected branch objects
90-
foreach (KeyValuePair<string, ObjectId> kvp in expectedResults.BranchTips)
91-
{
92-
expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
93-
}
94-
95-
// Add the expected tags
96-
string[] expectedTagNames = { "blob", "commit_tree", "annotated_tag" };
97-
foreach (string tagName in expectedTagNames)
98-
{
99-
TestRemoteInfo.ExpectedTagInfo expectedTagInfo = expectedResults.Tags[tagName];
100-
expectedFetchState.AddExpectedTag(tagName, ObjectId.Zero, expectedTagInfo);
101-
}
102-
103-
// Perform the actual fetch
104-
remote.Fetch(onUpdateTips: expectedFetchState.RemoteUpdateTipsHandler);
105-
106-
// Verify the expected
107-
expectedFetchState.CheckUpdatedReferences(repo);
108-
}
109-
}
110-
111-
[SkippableFact]
112-
public void CanFetchIntoAnEmptyRepositoryWithCredentials()
113-
{
114-
InconclusiveIf(() => string.IsNullOrEmpty(Constants.PrivateRepoUrl),
115-
"Populate Constants.PrivateRepo* to run this test");
116-
117-
string remoteName = "testRemote";
118-
119-
var scd = BuildSelfCleaningDirectory();
120-
using (var repo = Repository.Init(scd.RootedDirectoryPath))
121-
{
122-
Remote remote = repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);
123-
124-
// Perform the actual fetch
125-
remote.Fetch(credentials: new Credentials
126-
{
127-
Username = Constants.PrivateRepoUsername,
128-
Password = Constants.PrivateRepoPassword
129-
});
130-
}
131-
}
132-
133-
[Theory]
134-
[InlineData("http://github.com/libgit2/TestGitRepository")]
135-
[InlineData("https://github.com/libgit2/TestGitRepository")]
136-
[InlineData("git://github.com/libgit2/TestGitRepository.git")]
137-
public void CanFetchAllTagsIntoAnEmptyRepository(string url)
138-
{
139-
string remoteName = "testRemote";
140-
141-
var scd = BuildSelfCleaningDirectory();
142-
using (var repo = Repository.Init(scd.RootedDirectoryPath))
143-
{
144-
Remote remote = repo.Network.Remotes.Add(remoteName, url);
145-
146-
// Set up structures for the expected results
147-
// and verifying the RemoteUpdateTips callback.
148-
TestRemoteInfo remoteInfo = TestRemoteInfo.TestRemoteInstance;
149-
ExpectedFetchState expectedFetchState = new ExpectedFetchState(remoteName);
150-
151-
// Add expected branch objects
152-
foreach (KeyValuePair<string, ObjectId> kvp in remoteInfo.BranchTips)
153-
{
154-
expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
155-
}
156-
157-
// Add expected tags
158-
foreach (KeyValuePair<string, TestRemoteInfo.ExpectedTagInfo> kvp in remoteInfo.Tags)
159-
{
160-
expectedFetchState.AddExpectedTag(kvp.Key, ObjectId.Zero, kvp.Value);
161-
}
162-
163-
// Perform the actual fetch
164-
remote.Fetch(TagFetchMode.All, onUpdateTips: expectedFetchState.RemoteUpdateTipsHandler);
165-
166-
// Verify the expected
167-
expectedFetchState.CheckUpdatedReferences(repo);
168-
}
169-
}
170-
17170
[Fact]
17271
public void CreatingANewRemoteAddsADefaultRefSpec()
17372
{

0 commit comments

Comments
 (0)