@@ -207,5 +207,71 @@ public void RemovingStashWithBadParamShouldThrow(int badIndex)
207
207
Assert . Throws < ArgumentException > ( ( ) => repo . Stashes . Remove ( badIndex ) ) ;
208
208
}
209
209
}
210
+
211
+ [ Fact ]
212
+ public void CanGetStashByIndexer ( )
213
+ {
214
+ TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
215
+ using ( var repo = new Repository ( path . RepositoryPath ) )
216
+ {
217
+ var stasher = DummySignature ;
218
+ const string firstStashMessage = "My very first stash" ;
219
+ const string secondStashMessage = "My second stash" ;
220
+ const string thirdStashMessage = "My third stash" ;
221
+
222
+ // Create first stash
223
+ Stash firstStash = repo . Stashes . Add ( stasher , firstStashMessage , StashOptions . IncludeUntracked ) ;
224
+ Assert . NotNull ( firstStash ) ;
225
+
226
+ // Create second stash
227
+ string newFileFullPath = Path . Combine ( repo . Info . WorkingDirectory , "stash_candidate.txt" ) ;
228
+ File . WriteAllText ( newFileFullPath , "Oh, I'm going to be stashed!\n " ) ;
229
+
230
+ Stash secondStash = repo . Stashes . Add ( stasher , secondStashMessage , StashOptions . IncludeUntracked ) ;
231
+ Assert . NotNull ( secondStash ) ;
232
+
233
+ // Create third stash
234
+ newFileFullPath = Path . Combine ( repo . Info . WorkingDirectory , "stash_candidate_again.txt" ) ;
235
+ File . WriteAllText ( newFileFullPath , "Oh, I'm going to be stashed!\n " ) ;
236
+
237
+
238
+ Stash thirdStash = repo . Stashes . Add ( stasher , thirdStashMessage , StashOptions . IncludeUntracked ) ;
239
+ Assert . NotNull ( thirdStash ) ;
240
+
241
+ // Get by indexer
242
+ Assert . Equal ( 3 , repo . Stashes . Count ( ) ) ;
243
+ Assert . Equal ( "stash@{0}" , repo . Stashes [ 0 ] . CanonicalName ) ;
244
+ Assert . Contains ( thirdStashMessage , repo . Stashes [ 0 ] . Message ) ;
245
+ Assert . Equal ( thirdStash . Target , repo . Stashes [ 0 ] . Target ) ;
246
+ Assert . Equal ( "stash@{1}" , repo . Stashes [ 1 ] . CanonicalName ) ;
247
+ Assert . Contains ( secondStashMessage , repo . Stashes [ 1 ] . Message ) ;
248
+ Assert . Equal ( secondStash . Target , repo . Stashes [ 1 ] . Target ) ;
249
+ Assert . Equal ( "stash@{2}" , repo . Stashes [ 2 ] . CanonicalName ) ;
250
+ Assert . Contains ( firstStashMessage , repo . Stashes [ 2 ] . Message ) ;
251
+ Assert . Equal ( firstStash . Target , repo . Stashes [ 2 ] . Target ) ;
252
+ }
253
+ }
254
+
255
+ [ Theory ]
256
+ [ InlineData ( - 1 ) ]
257
+ [ InlineData ( - 42 ) ]
258
+ public void GettingStashWithBadIndexThrows ( int badIndex )
259
+ {
260
+ using ( var repo = new Repository ( StandardTestRepoWorkingDirPath ) )
261
+ {
262
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => repo . Stashes [ badIndex ] ) ;
263
+ }
264
+ }
265
+
266
+ [ Theory ]
267
+ [ InlineData ( 28 ) ]
268
+ [ InlineData ( 42 ) ]
269
+ public void GettingAStashThatDoesNotExistReturnsNull ( int bigIndex )
270
+ {
271
+ using ( var repo = new Repository ( StandardTestRepoWorkingDirPath ) )
272
+ {
273
+ Assert . Null ( repo . Stashes [ bigIndex ] ) ;
274
+ }
275
+ }
210
276
}
211
277
}
0 commit comments