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 . DotGitDirectory ;
53
+
54
+ gitRepository . IsDynamic . ShouldBe ( true ) ;
55
+ gitRepository . DotGitDirectory . 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 . DotGitDirectory ;
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,32 +136,46 @@ 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 . DotGitDirectory . 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
167
[ Test ]
141
- public void WorksCorrectlyWithLocalRepository ( )
168
+ public void ThrowsExceptionWhenNotEnoughInfo ( )
142
169
{
143
170
var tempDir = Path . GetTempPath ( ) ;
144
- var gitPreparer = new GitPreparer ( null , null , null , false , tempDir ) ;
145
- var dynamicRepositoryPath = gitPreparer . GetDotGitDirectory ( ) ;
146
171
147
- dynamicRepositoryPath . ShouldBe ( null ) ;
148
- gitPreparer . IsDynamicGitRepository . ShouldBe ( false ) ;
172
+ var repositoryInfo = new RepositoryInfo
173
+ {
174
+ Url = tempDir ,
175
+ Branch = "master"
176
+ } ;
177
+
178
+ Should . Throw < Exception > ( ( ) => GitRepositoryFactory . CreateRepository ( repositoryInfo ) ) ;
149
179
}
150
180
151
181
[ Test ]
@@ -162,12 +192,21 @@ public void UsingDynamicRepositoryWithFeatureBranchWorks()
162
192
{
163
193
mainRepositoryFixture . Repository . MakeACommit ( ) ;
164
194
165
- var gitPreparer = new GitPreparer ( mainRepositoryFixture . RepositoryPath , null , new AuthenticationInfo ( ) , false , tempDir ) ;
166
- gitPreparer . Initialise ( true , "feature1" ) ;
195
+ var repositoryInfo = new RepositoryInfo
196
+ {
197
+ Url = mainRepositoryFixture . RepositoryPath ,
198
+ Branch = "feature1"
199
+ } ;
167
200
168
201
mainRepositoryFixture . Repository . Checkout ( mainRepositoryFixture . Repository . CreateBranch ( "feature1" ) ) ;
169
202
170
- Should . NotThrow ( ( ) => gitPreparer . Initialise ( true , "feature1" ) ) ;
203
+ Should . NotThrow ( ( ) =>
204
+ {
205
+ using ( var gitRepository = GitRepositoryFactory . CreateRepository ( repositoryInfo ) )
206
+ {
207
+ // this code shouldn't throw
208
+ }
209
+ } ) ;
171
210
}
172
211
}
173
212
finally
@@ -190,9 +229,19 @@ public void UsingDynamicRepositoryWithoutTargetBranchFails()
190
229
{
191
230
mainRepositoryFixture . Repository . MakeACommit ( ) ;
192
231
193
- var gitPreparer = new GitPreparer ( mainRepositoryFixture . RepositoryPath , null , new AuthenticationInfo ( ) , false , tempDir ) ;
232
+ var repositoryInfo = new RepositoryInfo
233
+ {
234
+ Url = mainRepositoryFixture . RepositoryPath ,
235
+ Branch = null
236
+ } ;
194
237
195
- Should . Throw < Exception > ( ( ) => gitPreparer . Initialise ( true , null ) ) ;
238
+ Should . Throw < Exception > ( ( ) =>
239
+ {
240
+ using ( var gitRepository = GitRepositoryFactory . CreateRepository ( repositoryInfo ) )
241
+ {
242
+ // this code shouldn't throw
243
+ }
244
+ } ) ;
196
245
}
197
246
}
198
247
finally
@@ -211,9 +260,19 @@ public void TestErrorThrownForInvalidRepository()
211
260
212
261
try
213
262
{
214
- var gitPreparer = new GitPreparer ( "http://127.0.0.1/testrepo.git" , null , new AuthenticationInfo ( ) , false , tempDir ) ;
263
+ var repositoryInfo = new RepositoryInfo
264
+ {
265
+ Url = "http://127.0.0.1/testrepo.git" ,
266
+ Branch = "master"
267
+ } ;
215
268
216
- Should . Throw < Exception > ( ( ) => gitPreparer . Initialise ( true , "master" ) ) ;
269
+ Should . Throw < Exception > ( ( ) =>
270
+ {
271
+ using ( var gitRepository = GitRepositoryFactory . CreateRepository ( repositoryInfo ) )
272
+ {
273
+ // this code shouldn't throw
274
+ }
275
+ } ) ;
217
276
}
218
277
finally
219
278
{
0 commit comments