1
-
2
- using SqlCi . ScriptRunner . Constants ;
1
+ using SqlCi . ScriptRunner . Constants ;
3
2
using SqlCi . ScriptRunner . Exceptions ;
4
3
using System . IO ;
5
4
@@ -8,81 +7,78 @@ namespace SqlCi.ScriptRunner
8
7
public class ScriptConfiguration
9
8
{
10
9
private string _connectionString ;
10
+ private string _environment ;
11
+ private string _releaseNumber ;
11
12
private string _resetConnectionString ;
12
- private string _scriptsFolder ;
13
+ private bool _resetDatabase ;
13
14
private string _resetFolder ;
14
- private string _releaseNumber ;
15
+ private string _scriptsFolder ;
15
16
private string _scriptTable ;
16
- private bool _resetDatabase ;
17
17
private bool _verified ;
18
- private string _environment ;
19
-
20
- public string ScriptsFolder
21
- {
22
- get { return _scriptsFolder ; }
23
- }
24
-
25
18
public string ConnectionString
26
19
{
27
20
get { return _connectionString ; }
28
21
}
29
-
30
- public string ScriptTable
22
+ public string Environment
31
23
{
32
- get { return _scriptTable ; }
24
+ get { return _environment ; }
25
+ }
26
+ public bool IsVerified
27
+ {
28
+ get { return _verified ; }
33
29
}
34
-
35
30
public string ReleaseNumber
36
31
{
37
32
get { return _releaseNumber ; }
38
33
}
39
-
40
- public bool IsVerified
34
+ public string ResetConnectionString
41
35
{
42
- get { return _verified ; }
36
+ get { return _resetConnectionString ; }
43
37
}
44
-
45
38
public bool ResetDatabase
46
39
{
47
40
get { return _resetDatabase ; }
48
41
}
49
-
50
42
public string ResetFolder
51
43
{
52
44
get { return _resetFolder ; }
53
45
}
54
-
55
- public string Environment
46
+ public string ScriptsFolder
56
47
{
57
- get { return _environment ; }
48
+ get { return _scriptsFolder ; }
58
49
}
59
-
60
- public string ResetConnectionString
50
+ public string ScriptTable
61
51
{
62
- get { return _resetConnectionString ; }
52
+ get { return _scriptTable ; }
63
53
}
64
54
65
- public ScriptConfiguration WithConnectionString ( string connectionString )
55
+ public ScriptConfiguration Verify ( )
66
56
{
67
- _connectionString = connectionString ;
68
- return this ;
69
- }
57
+ // do a sanity check on our variables and make sure we have everything we need to run
58
+ // the scripts
59
+ ValidateConnectionString ( ) ;
60
+ ValidateScriptsFolder ( ) ;
61
+ ValidateResetFolder ( ) ;
62
+ ValidateReleaseNumber ( ) ;
63
+ ValidateScriptTable ( ) ;
64
+ ValidateEnvironment ( ) ;
65
+ ValidateResetConnectionString ( ) ;
66
+
67
+ // if we got this far without errors then we are ready to run scripts
68
+ _verified = true ;
70
69
71
- public ScriptConfiguration WithScriptsFolder ( string scriptsFolder )
72
- {
73
- _scriptsFolder = scriptsFolder ;
74
70
return this ;
75
71
}
76
72
77
- public ScriptConfiguration WithResetDatabase ( bool resetDatabase )
73
+ public ScriptConfiguration WithConnectionString ( string connectionString )
78
74
{
79
- _resetDatabase = resetDatabase ;
75
+ _connectionString = connectionString ;
80
76
return this ;
81
77
}
82
78
83
- public ScriptConfiguration WithResetFolder ( string resetFolder )
79
+ public ScriptConfiguration WithEnvironment ( string environment )
84
80
{
85
- _resetFolder = resetFolder ;
81
+ _environment = environment ;
86
82
return this ;
87
83
}
88
84
@@ -92,68 +88,49 @@ public ScriptConfiguration WithReleaseNumber(string releaseNumber)
92
88
return this ;
93
89
}
94
90
95
- public ScriptConfiguration WithScriptTable ( string scriptVersionTable )
91
+ public ScriptConfiguration WithResetConnectionString ( string resetConnectionString )
96
92
{
97
- _scriptTable = scriptVersionTable ;
93
+ _resetConnectionString = resetConnectionString ;
98
94
return this ;
99
95
}
100
96
101
- public ScriptConfiguration WithEnvironment ( string environment )
97
+ public ScriptConfiguration WithResetDatabase ( bool resetDatabase )
102
98
{
103
- _environment = environment ;
99
+ _resetDatabase = resetDatabase ;
104
100
return this ;
105
101
}
106
102
107
- public ScriptConfiguration WithResetConnectionString ( string resetConnectionString )
103
+ public ScriptConfiguration WithResetFolder ( string resetFolder )
108
104
{
109
- _resetConnectionString = resetConnectionString ;
105
+ _resetFolder = resetFolder ;
110
106
return this ;
111
107
}
112
108
113
- public ScriptConfiguration Verify ( )
109
+ public ScriptConfiguration WithScriptsFolder ( string scriptsFolder )
114
110
{
115
- // do a sanity check on our variables and make sure we have
116
- // everything we need to run the scripts
117
- ValidateConnectionString ( ) ;
118
- ValidateScriptsFolder ( ) ;
119
- ValidateResetFolder ( ) ;
120
- ValidateReleaseNumber ( ) ;
121
- ValidateScriptTable ( ) ;
122
- ValidateEnvironment ( ) ;
123
- ValidateResetConnectionString ( ) ;
124
-
125
- // if we got this far without errors then we are ready to run scripts
126
- _verified = true ;
127
-
111
+ _scriptsFolder = scriptsFolder ;
128
112
return this ;
129
113
}
130
114
131
- private void ValidateEnvironment ( )
115
+ public ScriptConfiguration WithScriptTable ( string scriptVersionTable )
132
116
{
133
- if ( string . IsNullOrEmpty ( _environment ) )
134
- {
135
- throw new MissingEnvironmentException ( ExceptionMessages . MissingEnvironment ) ;
136
- }
117
+ _scriptTable = scriptVersionTable ;
118
+ return this ;
137
119
}
138
120
139
- private void ValidateScriptsFolder ( )
121
+ private void ValidateConnectionString ( )
140
122
{
141
- if ( string . IsNullOrEmpty ( _scriptsFolder ) )
142
- {
143
- throw new MissingScriptsFolderException ( ExceptionMessages . MissingScriptsFolder ) ;
144
- }
145
-
146
- if ( ! Directory . Exists ( _scriptsFolder ) )
123
+ if ( string . IsNullOrEmpty ( _connectionString ) )
147
124
{
148
- throw new ScriptsFolderDoesNotExistException ( ExceptionMessages . ScriptsFolderDoesNotExist ) ;
125
+ throw new MissingConnectionStringException ( ExceptionMessages . MissingConnectionString ) ;
149
126
}
150
127
}
151
128
152
- private void ValidateConnectionString ( )
129
+ private void ValidateEnvironment ( )
153
130
{
154
- if ( string . IsNullOrEmpty ( _connectionString ) )
131
+ if ( string . IsNullOrEmpty ( _environment ) )
155
132
{
156
- throw new MissingConnectionStringException ( ExceptionMessages . MissingConnectionString ) ;
133
+ throw new MissingEnvironmentException ( ExceptionMessages . MissingEnvironment ) ;
157
134
}
158
135
}
159
136
@@ -165,11 +142,11 @@ private void ValidateReleaseNumber()
165
142
}
166
143
}
167
144
168
- private void ValidateScriptTable ( )
145
+ private void ValidateResetConnectionString ( )
169
146
{
170
- if ( string . IsNullOrEmpty ( _scriptTable ) )
147
+ if ( _resetDatabase && string . IsNullOrEmpty ( _resetConnectionString ) )
171
148
{
172
- throw new MissingScriptTableException ( ExceptionMessages . MissingScriptTable ) ;
149
+ throw new MissingConnectionStringException ( ExceptionMessages . MissingResetConnectionString ) ;
173
150
}
174
151
}
175
152
@@ -186,12 +163,25 @@ private void ValidateResetFolder()
186
163
}
187
164
}
188
165
189
- private void ValidateResetConnectionString ( )
166
+ private void ValidateScriptsFolder ( )
190
167
{
191
- if ( _resetDatabase && string . IsNullOrEmpty ( _resetConnectionString ) )
168
+ if ( string . IsNullOrEmpty ( _scriptsFolder ) )
192
169
{
193
- throw new MissingConnectionStringException ( ExceptionMessages . MissingResetConnectionString ) ;
170
+ throw new MissingScriptsFolderException ( ExceptionMessages . MissingScriptsFolder ) ;
171
+ }
172
+
173
+ if ( ! Directory . Exists ( _scriptsFolder ) )
174
+ {
175
+ throw new ScriptsFolderDoesNotExistException ( ExceptionMessages . ScriptsFolderDoesNotExist ) ;
176
+ }
177
+ }
178
+
179
+ private void ValidateScriptTable ( )
180
+ {
181
+ if ( string . IsNullOrEmpty ( _scriptTable ) )
182
+ {
183
+ throw new MissingScriptTableException ( ExceptionMessages . MissingScriptTable ) ;
194
184
}
195
185
}
196
186
}
197
- }
187
+ }
0 commit comments