11
11
using Testing ;
12
12
13
13
[ TestFixture ]
14
- public class GitPreparerTests
14
+ public class GitRepositoryFactoryTests
15
15
{
16
16
const string DefaultBranchName = "master" ;
17
17
const string SpecificBranchName = "feature/foo" ;
@@ -41,16 +41,20 @@ public void WorksCorrectlyWithRemoteRepository(string branchName, string expecte
41
41
// Copy contents into working directory
42
42
File . Copy ( Path . Combine ( fixture . RepositoryPath , "TestFile.txt" ) , Path . Combine ( tempDir , "TestFile.txt" ) ) ;
43
43
44
- var gitPreparer = new GitPreparer ( fixture . RepositoryPath , null , new AuthenticationInfo ( ) , false , tempDir ) ;
45
- gitPreparer . Initialise ( false , branchName ) ;
46
- dynamicRepositoryPath = gitPreparer . GetDotGitDirectory ( ) ;
47
-
48
- gitPreparer . IsDynamicGitRepository . ShouldBe ( true ) ;
49
- gitPreparer . DynamicGitRepositoryPath . ShouldBe ( expectedDynamicRepoLocation + "\\ .git" ) ;
44
+ var repositoryInfo = new RepositoryInfo
45
+ {
46
+ Url = fixture . RepositoryPath ,
47
+ Branch = branchName
48
+ } ;
50
49
51
- using ( var repository = new Repository ( dynamicRepositoryPath ) )
50
+ using ( var gitRepository = GitRepositoryFactory . CreateRepository ( repositoryInfo ) )
52
51
{
53
- var currentBranch = repository . Head . CanonicalName ;
52
+ dynamicRepositoryPath = gitRepository . GetDotGitDirectory ( ) ;
53
+
54
+ gitRepository . IsDynamic . ShouldBe ( true ) ;
55
+ gitRepository . GetDotGitDirectory ( ) . ShouldBe ( expectedDynamicRepoLocation + "\\ .git" ) ;
56
+
57
+ var currentBranch = gitRepository . Repository . Head . CanonicalName ;
54
58
55
59
currentBranch . ShouldEndWith ( expectedBranchName ) ;
56
60
}
@@ -59,8 +63,11 @@ public void WorksCorrectlyWithRemoteRepository(string branchName, string expecte
59
63
finally
60
64
{
61
65
Directory . Delete ( tempDir , true ) ;
66
+
62
67
if ( dynamicRepositoryPath != null )
68
+ {
63
69
DeleteHelper . DeleteGitRepository ( dynamicRepositoryPath ) ;
70
+ }
64
71
}
65
72
}
66
73
@@ -79,26 +86,35 @@ public void UpdatesExistingDynamicRepository()
79
86
{
80
87
mainRepositoryFixture . Repository . MakeCommits ( 1 ) ;
81
88
82
- var gitPreparer = new GitPreparer ( mainRepositoryFixture . RepositoryPath , null , new AuthenticationInfo ( ) , false , tempDir ) ;
83
- gitPreparer . Initialise ( false , "master" ) ;
84
- dynamicRepositoryPath = gitPreparer . GetDotGitDirectory ( ) ;
89
+ var repositoryInfo = new RepositoryInfo
90
+ {
91
+ Url = mainRepositoryFixture . RepositoryPath ,
92
+ Branch = "master"
93
+ } ;
94
+
95
+ using ( var gitRepository = GitRepositoryFactory . CreateRepository ( repositoryInfo ) )
96
+ {
97
+ dynamicRepositoryPath = gitRepository . GetDotGitDirectory ( ) ;
98
+ }
85
99
86
100
var newCommit = mainRepositoryFixture . Repository . MakeACommit ( ) ;
87
- gitPreparer . Initialise ( false , "master" ) ;
88
101
89
- using ( var repository = new Repository ( dynamicRepositoryPath ) )
102
+ using ( var gitRepository = GitRepositoryFactory . CreateRepository ( repositoryInfo ) )
90
103
{
91
104
mainRepositoryFixture . Repository . DumpGraph ( ) ;
92
- repository . DumpGraph ( ) ;
93
- repository . Commits . ShouldContain ( c => c . Sha == newCommit . Sha ) ;
105
+ gitRepository . Repository . DumpGraph ( ) ;
106
+ gitRepository . Repository . Commits . ShouldContain ( c => c . Sha == newCommit . Sha ) ;
94
107
}
95
108
}
96
109
}
97
110
finally
98
111
{
99
112
Directory . Delete ( tempDir , true ) ;
113
+
100
114
if ( dynamicRepositoryPath != null )
115
+ {
101
116
DeleteHelper . DeleteGitRepository ( dynamicRepositoryPath ) ;
117
+ }
102
118
}
103
119
}
104
120
@@ -120,34 +136,34 @@ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
120
136
expectedDynamicRepoLocation = Path . Combine ( tempPath , fixture . RepositoryPath . Split ( '\\ ' ) . Last ( ) ) ;
121
137
Directory . CreateDirectory ( expectedDynamicRepoLocation ) ;
122
138
123
- var gitPreparer = new GitPreparer ( fixture . RepositoryPath , null , new AuthenticationInfo ( ) , false , tempDir ) ;
124
- gitPreparer . Initialise ( false , "master" ) ;
139
+ var repositoryInfo = new RepositoryInfo
140
+ {
141
+ Url = fixture . RepositoryPath ,
142
+ Branch = "master"
143
+ } ;
125
144
126
- gitPreparer . IsDynamicGitRepository . ShouldBe ( true ) ;
127
- gitPreparer . DynamicGitRepositoryPath . ShouldBe ( expectedDynamicRepoLocation + "_1\\ .git" ) ;
145
+ using ( var gitRepository = GitRepositoryFactory . CreateRepository ( repositoryInfo ) )
146
+ {
147
+ gitRepository . IsDynamic . ShouldBe ( true ) ;
148
+ gitRepository . GetDotGitDirectory ( ) . ShouldBe ( expectedDynamicRepoLocation + "_1\\ .git" ) ;
149
+ }
128
150
}
129
151
}
130
152
finally
131
153
{
132
154
Directory . Delete ( tempDir , true ) ;
133
155
if ( expectedDynamicRepoLocation != null )
156
+ {
134
157
Directory . Delete ( expectedDynamicRepoLocation , true ) ;
158
+ }
159
+
135
160
if ( expectedDynamicRepoLocation != null )
161
+ {
136
162
DeleteHelper . DeleteGitRepository ( expectedDynamicRepoLocation + "_1" ) ;
163
+ }
137
164
}
138
165
}
139
166
140
- [ Test ]
141
- public void WorksCorrectlyWithLocalRepository ( )
142
- {
143
- var tempDir = Path . GetTempPath ( ) ;
144
- var gitPreparer = new GitPreparer ( null , null , null , false , tempDir ) ;
145
- var dynamicRepositoryPath = gitPreparer . GetDotGitDirectory ( ) ;
146
-
147
- dynamicRepositoryPath . ShouldBe ( null ) ;
148
- gitPreparer . IsDynamicGitRepository . ShouldBe ( false ) ;
149
- }
150
-
151
167
[ Test ]
152
168
public void UsingDynamicRepositoryWithFeatureBranchWorks ( )
153
169
{
@@ -162,12 +178,21 @@ public void UsingDynamicRepositoryWithFeatureBranchWorks()
162
178
{
163
179
mainRepositoryFixture . Repository . MakeACommit ( ) ;
164
180
165
- var gitPreparer = new GitPreparer ( mainRepositoryFixture . RepositoryPath , null , new AuthenticationInfo ( ) , false , tempDir ) ;
166
- gitPreparer . Initialise ( true , "feature1" ) ;
181
+ var repositoryInfo = new RepositoryInfo
182
+ {
183
+ Url = mainRepositoryFixture . RepositoryPath ,
184
+ Branch = "feature1"
185
+ } ;
167
186
168
187
mainRepositoryFixture . Repository . Checkout ( mainRepositoryFixture . Repository . CreateBranch ( "feature1" ) ) ;
169
188
170
- Should . NotThrow ( ( ) => gitPreparer . Initialise ( true , "feature1" ) ) ;
189
+ Should . NotThrow ( ( ) =>
190
+ {
191
+ using ( var gitRepository = GitRepositoryFactory . CreateRepository ( repositoryInfo ) )
192
+ {
193
+ // this code shouldn't throw
194
+ }
195
+ } ) ;
171
196
}
172
197
}
173
198
finally
@@ -190,9 +215,19 @@ public void UsingDynamicRepositoryWithoutTargetBranchFails()
190
215
{
191
216
mainRepositoryFixture . Repository . MakeACommit ( ) ;
192
217
193
- var gitPreparer = new GitPreparer ( mainRepositoryFixture . RepositoryPath , null , new AuthenticationInfo ( ) , false , tempDir ) ;
218
+ var repositoryInfo = new RepositoryInfo
219
+ {
220
+ Url = mainRepositoryFixture . RepositoryPath ,
221
+ Branch = null
222
+ } ;
194
223
195
- Should . Throw < Exception > ( ( ) => gitPreparer . Initialise ( true , null ) ) ;
224
+ Should . Throw < Exception > ( ( ) =>
225
+ {
226
+ using ( var gitRepository = GitRepositoryFactory . CreateRepository ( repositoryInfo ) )
227
+ {
228
+ // this code shouldn't throw
229
+ }
230
+ } ) ;
196
231
}
197
232
}
198
233
finally
@@ -211,9 +246,19 @@ public void TestErrorThrownForInvalidRepository()
211
246
212
247
try
213
248
{
214
- var gitPreparer = new GitPreparer ( "http://127.0.0.1/testrepo.git" , null , new AuthenticationInfo ( ) , false , tempDir ) ;
249
+ var repositoryInfo = new RepositoryInfo
250
+ {
251
+ Url = "http://127.0.0.1/testrepo.git" ,
252
+ Branch = "master"
253
+ } ;
215
254
216
- Should . Throw < Exception > ( ( ) => gitPreparer . Initialise ( true , "master" ) ) ;
255
+ Should . Throw < Exception > ( ( ) =>
256
+ {
257
+ using ( var gitRepository = GitRepositoryFactory . CreateRepository ( repositoryInfo ) )
258
+ {
259
+ // this code shouldn't throw
260
+ }
261
+ } ) ;
217
262
}
218
263
finally
219
264
{
0 commit comments