1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Diagnostics ;
4
+ using System . Linq ;
5
+ using NUnit . Framework ;
6
+
7
+ namespace LibGit2Sharp . Tests
8
+ {
9
+ [ TestFixture ]
10
+ public class TagFixture
11
+ {
12
+ private readonly List < string > expectedTags = new List < string > { "test" , "very-simple" } ;
13
+
14
+ private static readonly Signature signature = new Signature ( "Tim Clem" , "timothy.clem@gail.com" , DateTimeOffset . UtcNow ) ;
15
+
16
+ [ Test ]
17
+ public void CanCreateTag ( )
18
+ {
19
+ using ( var path = new TemporaryRepositoryPath ( ) )
20
+ using ( var repo = new Repository ( path . RepositoryPath ) )
21
+ {
22
+ var newTag = repo . Tags . Create ( "unit_test" , "refs/heads/master" , signature , "a new tag" ) ;
23
+ newTag . ShouldNotBeNull ( ) ;
24
+ }
25
+ }
26
+
27
+ [ Test ]
28
+ public void CanCreateTagFromSha ( )
29
+ {
30
+ using ( var path = new TemporaryRepositoryPath ( ) )
31
+ using ( var repo = new Repository ( path . RepositoryPath ) )
32
+ {
33
+ var newTag = repo . Tags . Create ( "unit_test" , "b25fa35b38051e4ae45d4222e795f9df2e43f1d1" , signature , "a new tag" ) ;
34
+ newTag . ShouldNotBeNull ( ) ;
35
+ }
36
+ }
37
+
38
+ [ Test ]
39
+ [ Ignore ( "TODO: the very-simple tag is coming back with an odd name." ) ]
40
+ public void CanListTags ( )
41
+ {
42
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
43
+ {
44
+ foreach ( var tag in repo . Tags )
45
+ {
46
+ Trace . WriteLine ( tag . Name ) ;
47
+ expectedTags . Contains ( tag . Name ) . ShouldBeTrue ( ) ;
48
+ }
49
+ repo . Tags . Count ( ) . ShouldEqual ( 2 ) ;
50
+ }
51
+ }
52
+
53
+ [ Test ]
54
+ public void CanLookupTag ( )
55
+ {
56
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
57
+ {
58
+ var tag = repo . Tags [ "test" ] ;
59
+ tag . ShouldNotBeNull ( ) ;
60
+ tag . Name . ShouldEqual ( "test" ) ;
61
+ tag . Sha . ShouldEqual ( "b25fa35b38051e4ae45d4222e795f9df2e43f1d1" ) ;
62
+ tag . Tagger . Email . ShouldEqual ( "tanoku@gmail.com" ) ;
63
+ tag . Tagger . Name . ShouldEqual ( "Vicent Marti" ) ;
64
+ tag . Tagger . When . ToSecondsSinceEpoch ( ) . ShouldEqual ( 1281578440 ) ;
65
+ tag . Message . ShouldEqual ( "This is a test tag\n " ) ;
66
+ }
67
+ }
68
+
69
+ [ Test ]
70
+ public void CreateTagWithEmptyMessageThrows ( )
71
+ {
72
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
73
+ {
74
+ Assert . Throws < ArgumentException > ( ( ) => repo . Tags . Create ( "test_tag" , "refs/heads/master" , signature , string . Empty ) ) ;
75
+ }
76
+ }
77
+
78
+ [ Test ]
79
+ public void CreateTagWithEmptyNameThrows ( )
80
+ {
81
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
82
+ {
83
+ Assert . Throws < ArgumentException > ( ( ) => repo . Tags . Create ( string . Empty , "refs/heads/master" , signature , "message" ) ) ;
84
+ }
85
+ }
86
+
87
+ [ Test ]
88
+ public void CreateTagWithEmptyTargetThrows ( )
89
+ {
90
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
91
+ {
92
+ Assert . Throws < ArgumentException > ( ( ) => repo . Tags . Create ( "test_tag" , string . Empty , signature , "message" ) ) ;
93
+ }
94
+ }
95
+
96
+ [ Test ]
97
+ public void CreateTagWithNullMessageThrows ( )
98
+ {
99
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
100
+ {
101
+ Assert . Throws < ArgumentNullException > ( ( ) => repo . Tags . Create ( "test_tag" , "refs/heads/master" , signature , null ) ) ;
102
+ }
103
+ }
104
+
105
+ [ Test ]
106
+ public void CreateTagWithNullNameThrows ( )
107
+ {
108
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
109
+ {
110
+ Assert . Throws < ArgumentNullException > ( ( ) => repo . Tags . Create ( null , "refs/heads/master" , signature , "message" ) ) ;
111
+ }
112
+ }
113
+
114
+ [ Test ]
115
+ public void CreateTagWithNullSignatureThrows ( )
116
+ {
117
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
118
+ {
119
+ Assert . Throws < ArgumentNullException > ( ( ) => repo . Tags . Create ( "test_tag" , "refs/heads/master" , null , "message" ) ) ;
120
+ }
121
+ }
122
+
123
+ [ Test ]
124
+ public void CreateTagWithNullTargetThrows ( )
125
+ {
126
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
127
+ {
128
+ Assert . Throws < ArgumentNullException > ( ( ) => repo . Tags . Create ( "test_tag" , null , signature , "message" ) ) ;
129
+ }
130
+ }
131
+
132
+ [ Test ]
133
+ public void LookupEmptyTagNameThrows ( )
134
+ {
135
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
136
+ {
137
+ Assert . Throws < ArgumentException > ( ( ) => { var t = repo . Tags [ string . Empty ] ; } ) ;
138
+ }
139
+ }
140
+
141
+ [ Test ]
142
+ public void LookupNullTagNameThrows ( )
143
+ {
144
+ using ( var repo = new Repository ( Constants . TestRepoPath ) )
145
+ {
146
+ Assert . Throws < ArgumentNullException > ( ( ) => { var t = repo . Tags [ null ] ; } ) ;
147
+ }
148
+ }
149
+ }
150
+ }
0 commit comments