@@ -38,30 +38,31 @@ internal void TestIfSameRepoAfterPacking(Action<PackBuilder> buildingDelegate)
38
38
Directory . CreateDirectory ( mrrRepoPathPackDirPath ) ;
39
39
Directory . CreateDirectory ( mrrRepoPathPackDirPath + "/pack" ) ;
40
40
41
- PackBuilderOptions packBuilderOptions = new PackBuilderOptions ( ) ;
42
- packBuilderOptions . MaximumNumberOfThreads = 0 ;
43
- packBuilderOptions . PackFilePath = mrrRepoPathPackDirPath + "/pack" ;
41
+ PackBuilderOptions packBuilderOptions = new PackBuilderOptions ( mrrRepoPathPackDirPath + "/pack" ) ;
44
42
45
- Repository orgRepo = new Repository ( orgRepoPath ) ;
46
-
47
- PackBuilderResults results = orgRepo . ObjectDatabase . Pack ( packBuilderOptions , buildingDelegate ) ;
48
-
49
- // written objects count is the same as in objects database
50
- Assert . Equal ( orgRepo . ObjectDatabase . Count ( ) , results . WrittenObjectsCount ) ;
51
-
52
- // loading a repo from the written pack file.
53
- Repository mrrRepo = new Repository ( mrrRepoPath ) ;
43
+ using ( Repository orgRepo = new Repository ( orgRepoPath ) )
44
+ {
45
+ PackBuilderResults results ;
46
+ if ( buildingDelegate != null )
47
+ results = orgRepo . ObjectDatabase . Pack ( packBuilderOptions , buildingDelegate ) ;
48
+ else
49
+ results = orgRepo . ObjectDatabase . Pack ( packBuilderOptions ) ;
54
50
55
- // make sure the objects of the original repo are the same as the ones in the mirror repo
56
- // doing that by making sure the count is the same, and the set differnce is empty
57
- Assert . True ( mrrRepo . ObjectDatabase . Count ( ) == orgRepo . ObjectDatabase . Count ( ) && ! mrrRepo . ObjectDatabase . Except ( orgRepo . ObjectDatabase ) . Any ( ) ) ;
51
+ // written objects count is the same as in objects database
52
+ Assert . Equal ( orgRepo . ObjectDatabase . Count ( ) , results . WrittenObjectsCount ) ;
58
53
59
- Assert . Equal ( orgRepo . Commits . Count ( ) , mrrRepo . Commits . Count ( ) ) ;
60
- Assert . Equal ( orgRepo . Branches . Count ( ) , mrrRepo . Branches . Count ( ) ) ;
61
- Assert . Equal ( orgRepo . Refs . Count ( ) , mrrRepo . Refs . Count ( ) ) ;
54
+ // loading a repo from the written pack file.
55
+ using ( Repository mrrRepo = new Repository ( mrrRepoPath ) )
56
+ {
57
+ // make sure the objects of the original repo are the same as the ones in the mirror repo
58
+ // doing that by making sure the count is the same, and the set differnce is empty
59
+ Assert . True ( mrrRepo . ObjectDatabase . Count ( ) == orgRepo . ObjectDatabase . Count ( ) && ! mrrRepo . ObjectDatabase . Except ( orgRepo . ObjectDatabase ) . Any ( ) ) ;
62
60
63
- orgRepo . Dispose ( ) ;
64
- mrrRepo . Dispose ( ) ;
61
+ Assert . Equal ( orgRepo . Commits . Count ( ) , mrrRepo . Commits . Count ( ) ) ;
62
+ Assert . Equal ( orgRepo . Branches . Count ( ) , mrrRepo . Branches . Count ( ) ) ;
63
+ Assert . Equal ( orgRepo . Refs . Count ( ) , mrrRepo . Refs . Count ( ) ) ;
64
+ }
65
+ }
65
66
}
66
67
67
68
internal void TestBuildDelegate ( PackBuilder builder )
@@ -74,5 +75,104 @@ internal void TestBuildDelegate(PackBuilder builder)
74
75
}
75
76
}
76
77
}
78
+
79
+ [ Fact ]
80
+ public void ExceptionIfPathDoesNotExist ( )
81
+ {
82
+ PackBuilderOptions pbo ;
83
+
84
+ Assert . Throws < DirectoryNotFoundException > ( ( ) =>
85
+ {
86
+ pbo = new PackBuilderOptions ( "aaa" ) ;
87
+ } ) ;
88
+ }
89
+
90
+ [ Fact ]
91
+ public void ExceptionIfPathEqualsNull ( )
92
+ {
93
+ PackBuilderOptions pbo ;
94
+
95
+ Assert . Throws < ArgumentNullException > ( ( ) =>
96
+ {
97
+ pbo = new PackBuilderOptions ( null ) ;
98
+ } ) ;
99
+ }
100
+
101
+ [ Fact ]
102
+ public void ExceptionIfOptionsEqualsNull ( )
103
+ {
104
+ string orgRepoPath = SandboxPackBuilderTestRepo ( ) ;
105
+
106
+ using ( Repository orgRepo = new Repository ( orgRepoPath ) )
107
+ {
108
+ Assert . Throws < ArgumentNullException > ( ( ) =>
109
+ {
110
+ orgRepo . ObjectDatabase . Pack ( null ) ;
111
+ } ) ;
112
+ }
113
+ }
114
+
115
+ [ Fact ]
116
+ public void ExceptionIfBuildDelegateEqualsNull ( )
117
+ {
118
+ string orgRepoPath = SandboxPackBuilderTestRepo ( ) ;
119
+ PackBuilderOptions packBuilderOptions = new PackBuilderOptions ( orgRepoPath ) ;
120
+
121
+ using ( Repository orgRepo = new Repository ( orgRepoPath ) )
122
+ {
123
+ Assert . Throws < ArgumentNullException > ( ( ) =>
124
+ {
125
+ orgRepo . ObjectDatabase . Pack ( packBuilderOptions , null ) ;
126
+ } ) ;
127
+ }
128
+ }
129
+
130
+ [ Fact ]
131
+ public void ExceptionIfNegativeNumberOfThreads ( )
132
+ {
133
+ string orgRepoPath = SandboxPackBuilderTestRepo ( ) ;
134
+ PackBuilderOptions packBuilderOptions = new PackBuilderOptions ( orgRepoPath ) ;
135
+
136
+ Assert . Throws < ArgumentException > ( ( ) =>
137
+ {
138
+ packBuilderOptions . MaximumNumberOfThreads = - 1 ;
139
+ } ) ;
140
+ }
141
+
142
+ [ Fact ]
143
+ public void ExceptionIfAddNullObjectID ( )
144
+ {
145
+ string orgRepoPath = SandboxPackBuilderTestRepo ( ) ;
146
+ PackBuilderOptions packBuilderOptions = new PackBuilderOptions ( orgRepoPath ) ;
147
+
148
+ using ( Repository orgRepo = new Repository ( orgRepoPath ) )
149
+ {
150
+ Assert . Throws < ArgumentNullException > ( ( ) =>
151
+ {
152
+ orgRepo . ObjectDatabase . Pack ( packBuilderOptions , ( PackBuilder builder ) =>
153
+ {
154
+ builder . Add ( null ) ;
155
+ } ) ;
156
+ } ) ;
157
+ }
158
+ }
159
+
160
+ [ Fact ]
161
+ public void ExceptionIfAddRecursivelyNullObjectID ( )
162
+ {
163
+ string orgRepoPath = SandboxPackBuilderTestRepo ( ) ;
164
+ PackBuilderOptions packBuilderOptions = new PackBuilderOptions ( orgRepoPath ) ;
165
+
166
+ using ( Repository orgRepo = new Repository ( orgRepoPath ) )
167
+ {
168
+ Assert . Throws < ArgumentNullException > ( ( ) =>
169
+ {
170
+ orgRepo . ObjectDatabase . Pack ( packBuilderOptions , ( PackBuilder builder ) =>
171
+ {
172
+ builder . AddRecursively ( null ) ;
173
+ } ) ;
174
+ } ) ;
175
+ }
176
+ }
77
177
}
78
178
}
0 commit comments