mbunit2 2.4.2.355.20100801

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. data/docs/ASL - Apache Software Foundation License.txt +57 -0
  2. data/docs/MbUnit License.txt +14 -0
  3. data/docs/MbUnit.chm +0 -0
  4. data/docs/Release Notes.txt +7 -0
  5. data/docs/extras/CCNet/How to use MbUnit v2 with CruiseControl.Net.txt +88 -0
  6. data/docs/extras/CCNet/images/Category.png +0 -0
  7. data/docs/extras/CCNet/images/Fixture.png +0 -0
  8. data/docs/extras/CCNet/images/Populator.png +0 -0
  9. data/docs/extras/CCNet/images/Test.png +0 -0
  10. data/docs/extras/CCNet/xsl/MBUnitDetails.xsl +592 -0
  11. data/docs/extras/CCNet/xsl/MBUnitSummary.xsl +266 -0
  12. data/docs/extras/Snippets/AdjacencyGraph.cst +1703 -0
  13. data/docs/extras/Snippets/AssertWrapper.cst +181 -0
  14. data/docs/extras/Snippets/CrudPopulator.cst +377 -0
  15. data/docs/extras/Snippets/DatabasePopulator.cst +386 -0
  16. data/docs/extras/Snippets/DatabasePopulatorCrudTest.cst +177 -0
  17. data/docs/extras/Snippets/Exception.cst +94 -0
  18. data/docs/extras/Snippets/GrammarPopulator.cst +258 -0
  19. data/docs/extras/Snippets/MockObject.cst +296 -0
  20. data/docs/extras/Snippets/RapTierCrudPopulator.cst +444 -0
  21. data/docs/extras/Snippets/SimpleFixture.cst +91 -0
  22. data/docs/extras/Snippets/SqlppCrudPopulator.cst +443 -0
  23. data/docs/extras/Snippets/TestFixture.cst +469 -0
  24. data/docs/extras/Snippets/autorunner.snippet +45 -0
  25. data/docs/extras/Snippets/combinatorialtest.snippet +54 -0
  26. data/docs/extras/Snippets/datafixture.snippet +61 -0
  27. data/docs/extras/Snippets/model.snippet +95 -0
  28. data/docs/extras/Snippets/msbuild.snippet +40 -0
  29. data/docs/extras/Snippets/nant.snippet +34 -0
  30. data/docs/extras/Snippets/perfcounterassert.cst +173 -0
  31. data/docs/extras/Snippets/processtestfixture.snippet +75 -0
  32. data/docs/extras/Snippets/rowtest.snippet +113 -0
  33. data/docs/extras/Snippets/state.snippet +27 -0
  34. data/docs/extras/Snippets/submodel.snippet +32 -0
  35. data/docs/extras/Snippets/test.snippet +28 -0
  36. data/docs/extras/Snippets/testexpectedexception.snippet +32 -0
  37. data/docs/extras/Snippets/testfixture.snippet +68 -0
  38. data/docs/extras/Snippets/testsuitefixture.snippet +48 -0
  39. data/docs/extras/Snippets/typefixture.snippet +74 -0
  40. data/docs/extras/Snippets/typefixturewithproviderfactory.snippet +77 -0
  41. data/docs/extras/Snippets/usingmbunit.snippet +19 -0
  42. data/docs/extras/Templates/VS2005/ItemTemplates/CSharp/Test/MbUnit2.TestFixtureTemplate.CSharp.zip +0 -0
  43. data/docs/extras/Templates/VS2005/ItemTemplates/VisualBasic/Test/MbUnit2.TestFixtureTemplate.VisualBasic.zip +0 -0
  44. data/docs/extras/Templates/VS2005/ProjectTemplates/CSharp/Test/MbUnit2.TestProjectTemplate.CSharp.zip +0 -0
  45. data/docs/extras/Templates/VS2005/ProjectTemplates/VisualBasic/Test/MbUnit2.TestProjectTemplate.VisualBasic.zip +0 -0
  46. data/docs/extras/Templates/VS2008/ItemTemplates/CSharp/Test/MbUnit2.TestFixtureTemplate.CSharp.zip +0 -0
  47. data/docs/extras/Templates/VS2008/ItemTemplates/VisualBasic/Test/MbUnit2.TestFixtureTemplate.VisualBasic.zip +0 -0
  48. data/docs/extras/Templates/VS2008/ProjectTemplates/CSharp/Test/MbUnit2.MvcWebApplicationTestProjectTemplate.CSharp.zip +0 -0
  49. data/docs/extras/Templates/VS2008/ProjectTemplates/CSharp/Test/MbUnit2.TestProjectTemplate.CSharp.zip +0 -0
  50. data/docs/extras/Templates/VS2008/ProjectTemplates/VisualBasic/Test/MbUnit2.MvcWebApplicationTestProjectTemplate.VisualBasic.zip +0 -0
  51. data/docs/extras/Templates/VS2008/ProjectTemplates/VisualBasic/Test/MbUnit2.TestProjectTemplate.VisualBasic.zip +0 -0
  52. data/lib/MbUnit License.txt +14 -0
  53. data/lib/MbUnit.AddIn.dll +0 -0
  54. data/lib/MbUnit.Cons.exe +0 -0
  55. data/lib/MbUnit.Cons.exe.config +12 -0
  56. data/lib/MbUnit.Framework.2.0.dll +0 -0
  57. data/lib/MbUnit.Framework.2.0.pdb +0 -0
  58. data/lib/MbUnit.Framework.2.0.xml +278 -0
  59. data/lib/MbUnit.Framework.dll +0 -0
  60. data/lib/MbUnit.Framework.pdb +0 -0
  61. data/lib/MbUnit.Framework.xml +6929 -0
  62. data/lib/MbUnit.GUI.exe +0 -0
  63. data/lib/MbUnit.GUI.exe.config +14 -0
  64. data/lib/MbUnit.MSBuild.Tasks.dll +0 -0
  65. data/lib/MbUnit.Tasks.dll +0 -0
  66. data/lib/NGraphviz.Helpers.dll +0 -0
  67. data/lib/NGraphviz.Layout.dll +0 -0
  68. data/lib/NGraphviz.dll +0 -0
  69. data/lib/QuickGraph.Algorithms.Graphviz.dll +0 -0
  70. data/lib/QuickGraph.Algorithms.dll +0 -0
  71. data/lib/QuickGraph.Algorithms.pdb +0 -0
  72. data/lib/QuickGraph.Algorithms.xml +2818 -0
  73. data/lib/QuickGraph.dll +0 -0
  74. data/lib/QuickGraph.pdb +0 -0
  75. data/lib/QuickGraph.xml +3126 -0
  76. data/lib/Refly.dll +0 -0
  77. data/lib/Refly.pdb +0 -0
  78. data/lib/Refly.xml +1327 -0
  79. data/lib/TestFu.dll +0 -0
  80. data/lib/TestFu.pdb +0 -0
  81. data/lib/TestFu.xml +1932 -0
  82. data/lib/XsdTidy.exe +0 -0
  83. metadata +163 -0
@@ -0,0 +1,386 @@
1
+ <%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="TestFu DatabasePopulator Template" %>
2
+ <%@ Property Name="Namespace" Type="System.String"
3
+ Default="Populators"
4
+ Category="Output"
5
+ Description="Namespace of the populator." %>
6
+ <%@ Property Name="DataSetNameFormat" Type="System.String"
7
+ Default="{0}DataSet"
8
+ Category="Output"
9
+ Description="Format string to create the DatabaseSet class name." %>
10
+ <%@ Property Name="DatabasePopulatorNameFormat" Type="System.String"
11
+ Default="{0}DatabasePopulator"
12
+ Category="Output"
13
+ Description="Format string to create the DatabasePopulator class name." %>
14
+ <%@ Property Name="TableNamePrefix" Type="System.String"
15
+ Default=""
16
+ Category="Output"
17
+ Optional="true"
18
+ Description="Prefix to be removed." %>
19
+ <%@ Property Name="TablePopulatorNameFormat" Type="System.String"
20
+ Default="{0}TablePopulator"
21
+ Category="Output"
22
+ Description="Format string to create the TablePopulator class names." %>
23
+ <%@ Property Name="ColumnDataGeneratorNameFormat" Type="System.String"
24
+ Default="{0}DataGenerator"
25
+ Category="Output"
26
+ Description="Format string to create the ColumnGenenerator properties." %>
27
+ <%@ Property Name="UniqueValidatorNameFormat" Type="System.String"
28
+ Default="{0}Validator"
29
+ Category="Output"
30
+ Description="Format string to create the UniqueValidator properties." %>
31
+ <%@ Property Name="ForeignKeyProviderNameFormat" Type="System.String"
32
+ Default="{0}Provider"
33
+ Category="Output"
34
+ Description="Format string to create the ForeignKeyProviderNameFormat properties." %>
35
+ <%@ Property Name="Database" Type="SchemaExplorer.DatabaseSchema"
36
+ Category="Context"
37
+ Description="Target database for the IDatabasePopulator." %>
38
+ <%@ Assembly Name="SchemaExplorer" %>
39
+ <%@ Import Namespace="SchemaExplorer" %>
40
+ //////////////////////////////////////////////////////////////////
41
+ //
42
+ // Strongly typed populator for the <%= DatabaseName %>
43
+ //
44
+ //////////////////////////////////////////////////////////////////
45
+
46
+ using System;
47
+ using System.Data;
48
+ using System.Data.SqlClient;
49
+
50
+ using TestFu.Data;
51
+ using TestFu.Data.Populators;
52
+ using TestFu.Data.SqlClient;
53
+ using TestFu.Data.Generators;
54
+
55
+ namespace <%= Namespace %>
56
+ {
57
+ /// <summary>
58
+ /// A strongly typed <see cref="IDatabasePopulator"/> implementation for the
59
+ /// <%= DatabaseName %> database.
60
+ /// </summary>
61
+ /// <remarks>
62
+ /// <para>
63
+ /// This class can be used to generate <see cref="DataRow" /> instances that are compatible with
64
+ /// the constraint of the tables.
65
+ /// </para>
66
+ /// </remarks>
67
+ public class <%= DatabasePopulatorName %> : SqlDatabasePopulator
68
+ {
69
+ #region Constructors
70
+ /// <summary>
71
+ /// Initializes a new <see cref="<%= DatabasePopulatorName %>"/> with the
72
+ /// connection string of the database.
73
+ /// </summary>
74
+ /// <param name="connectionString">
75
+ /// A valid conneciton string to the target database.
76
+ /// </param>
77
+ /// <exception type="ArgumentNullException">
78
+ /// The <paramref name="connectionString"/> is a
79
+ /// null reference (Nothing in Visual Basic).
80
+ /// </exception>
81
+ /// <exception type="ArgumentException">
82
+ /// The <paramref name="connectionString"/> is empty.
83
+ /// </exception>
84
+ public <%= DatabasePopulatorName %>(string connectionString)
85
+ :this(new <%= DataSetName %>(), connectionString)
86
+ {}
87
+
88
+ /// <summary>
89
+ /// Initializes a new <see cref="<%= DatabasePopulatorName %>"/> with the
90
+ /// connection string of the database.
91
+ /// </summary>
92
+ /// <param name="dataSet">
93
+ /// A <see cref="DataSet"/> representing the structure of the
94
+ /// <em><%= DatabaseName %></em> database.
95
+ /// </param>
96
+ /// <param name="connectionString">
97
+ /// A valid conneciton string to the target database.
98
+ /// </param>
99
+ /// <exception type="ArgumentNullException">
100
+ /// The <paramref name="dataSet"/> or the <paramref name="connectionString"/> is a
101
+ /// null reference (Nothing in Visual Basic).
102
+ /// </exception>
103
+ /// <exception type="ArgumentException">
104
+ /// The <paramref name="connectionString"/> is empty.
105
+ /// </exception>
106
+ public <%= DatabasePopulatorName %>(
107
+ DataSet dataSet,
108
+ string connectionString
109
+ )
110
+ :base(connectionString)
111
+ {
112
+ // populate
113
+ this.Populate(dataSet);
114
+ }
115
+
116
+ protected override void PopulateTables()
117
+ {
118
+ // replace each ITablePopulator by a strongly-typed version
119
+ <% foreach(TableSchema table in this.Database.Tables) {%>
120
+ this.Tables.Add(new <%= GetTablePopulatorName(table)%>(this));
121
+ <%} // foreach(TableSchema table in this.Database.Tables) %>
122
+ }
123
+ #endregion
124
+
125
+ #region Tables
126
+ <% foreach(TableSchema table in this.Database.Tables) {%>
127
+ /// <summary>
128
+ /// Gets the <see cref="GetTablePopulatorName(table)"/> that populates the
129
+ /// <em><%= table.Name %></em> table.
130
+ /// </summary>
131
+ /// <value>
132
+ /// A strongly typed implementation of <see cref="ITablePopulator"/> that targets
133
+ /// the <em><%= table.Name %></em> table.
134
+ /// </value>
135
+ public <%= GetTablePopulatorName(table) %> <%= GetTablePopulatorPropertyName(table) %>
136
+ {
137
+ get
138
+ {
139
+ DataTable table = this.DataSet.Tables["<%= table.Name %>"];
140
+ if (table==null)
141
+ throw new InvalidOperationException("The table <%= table.Name %> was not found in the DataSet");
142
+ <%= GetTablePopulatorName(table) %> tablePopulator = this.Tables[table] as <%= GetTablePopulatorName(table) %>;
143
+ if (tablePopulator==null)
144
+ throw new InvalidOperationException("The table populator for the <%= table.FullName %> was not found");
145
+ return tablePopulator;
146
+ }
147
+ }
148
+ <%} // foreach(TableSchema table in this.Database.Tables) %>
149
+ #endregion
150
+ #region Table Classes
151
+ <% foreach(TableSchema table in this.Database.Tables) {%>
152
+
153
+ #region <%= GetTablePopulatorName(table) %>
154
+ /// <summary>
155
+ /// A strongly typed implementation of <see cref="ITablePopulator"/> that targets
156
+ /// the <%= table.Name %> table.
157
+ /// </summary>
158
+ public class <%= GetTablePopulatorName(table) %> : TablePopulator
159
+ {
160
+ public <%= GetTablePopulatorName(table) %>(<%= DatabasePopulatorName %> databasePopulator)
161
+ :base(databasePopulator,databasePopulator.DataSet.Tables["<%= table.Name %>"])
162
+ {}
163
+
164
+ public new <%= DatabasePopulatorName %> Database
165
+ {
166
+ get
167
+ {
168
+ return base.Database as <%= DatabasePopulatorName %>;
169
+ }
170
+ }
171
+
172
+ public DataRow GetRandomRow()
173
+ {
174
+ return this.Database.GetRandomRow(this.Table);
175
+ }
176
+
177
+ protected override void PopulateDataGenerators()
178
+ {
179
+ base.PopulateDataGenerators();
180
+
181
+ // Fix fields length
182
+ <% foreach(ColumnSchema column in table.Columns){
183
+ if (column.SystemType.IsValueType)
184
+ continue;
185
+ if (column.NativeType.ToLower() == "ntext" || column.NativeType.ToLower() == "text")
186
+ continue;
187
+ %>
188
+ this.FixLength(this.Columns["<%= column.Name %>"],<%= column.Size %>, <%= (table.PrimaryKey.MemberColumns.Contains(column)) ? "false" : "true" %>);
189
+ <%}%>
190
+ }
191
+
192
+ private void FixLength(IDataGenerator gen, int size, bool updateMaxLengthOnly)
193
+ {
194
+ StringGeneratorBase stringGenerator = gen as StringGeneratorBase;
195
+ if(stringGenerator!=null)
196
+ {
197
+ if (!updateMaxLengthOnly)
198
+ stringGenerator.MinLength = size;
199
+ stringGenerator.MaxLength = size;
200
+ return;
201
+ }
202
+
203
+ BinaryGenerator binaryGenerator = gen as BinaryGenerator;
204
+ if (binaryGenerator!=null)
205
+ {
206
+ if (!updateMaxLengthOnly)
207
+ binaryGenerator.MinLength = size;
208
+ binaryGenerator.MaxLength = 16;
209
+ return;
210
+ }
211
+ }
212
+
213
+ #region Columns Data Generators
214
+ <% foreach(ColumnSchema column in table.Columns){ %>
215
+ /// <summary>
216
+ /// Gets or sets the <see cref="IDataGenerator"/> that generates data for
217
+ /// the <em><%= GetColumnDataGeneratorName(column) %></em> column.
218
+ /// </summary>
219
+ /// <value>
220
+ /// A <see cref="IDataGenerator"/> instance that generates the data
221
+ /// for the <em><%= GetColumnDataGeneratorName(column) %></em> column.
222
+ /// </value>
223
+ /// <exception type="ArgumentNullException">
224
+ /// set property, the value is a null reference.
225
+ /// </exception>
226
+ public IDataGenerator <%= GetColumnDataGeneratorName(column) %>
227
+ {
228
+ get
229
+ {
230
+ DataColumn column = this.Table.Columns["<%= column.Name %>"];
231
+ if (column==null)
232
+ throw new InvalidOperationException("Column <%= column.Name %> not found");
233
+ IDataGenerator dataGenerator = this.Columns[column];
234
+ if (dataGenerator==null)
235
+ throw new InvalidOperationException("IDataGenerator not found for <%= column.Name %>");
236
+ return dataGenerator;
237
+ }
238
+ set
239
+ {
240
+ if (value==null)
241
+ throw new ArgumentNullException("IDataGenerator cannot be null");
242
+ this.Columns.Remove("<%= column.Name %>");
243
+ this.Columns.Add(value);
244
+ }
245
+ }
246
+ <%} // foreach(ColumnSchema column in table.Columns) %>
247
+ #endregion
248
+
249
+ #region UniqueValidators
250
+ <% foreach(TableKeySchema unique in table.PrimaryKeys){ %>
251
+ /// <summary>
252
+ /// Gets or sets the <see cref="IUniqueValidator"/> that validates data
253
+ /// the <em><%= GetUniqueValidatorName(unique) %></em> unique constraint.
254
+ /// </summary>
255
+ /// <value>
256
+ /// A <see cref="IUniqueValidator"/> instance that validates data
257
+ /// the <em><%= GetUniqueValidatorName(unique) %></em> unique constraint.
258
+ /// </value>
259
+ /// <exception type="ArgumentNullException">
260
+ /// set property, the value is a null reference.
261
+ /// </exception>
262
+ public IUniqueValidator <%= GetUniqueValidatorName(unique)%>
263
+ {
264
+ get
265
+ {
266
+ UniqueConstraint unique = this.Table.Constraints["<%= unique.Name %>"] as UniqueConstraint;
267
+ if (unique==null)
268
+ throw new InvalidOperationException("Could not find UniqueConstraint <%= unique.Name %>");
269
+ IUniqueValidator validator = this.Uniques[unique];
270
+ if (validator==null)
271
+ throw new InvalidOperationException("Could not find validator for UniqueConstraint <%= unique.Name %>");
272
+ return validator;
273
+ }
274
+ set
275
+ {
276
+ if (value==null)
277
+ throw new ArgumentNullException("IUniqueValidator cannot be null");
278
+ UniqueConstraint unique = this.Table.Constraints["<%= unique.Name %>"] as UniqueConstraint;
279
+ if (unique==null)
280
+ throw new InvalidOperationException("Could not find UniqueConstraint <%= unique.Name %>");
281
+ this.Uniques[unique] = value;
282
+ }
283
+ }
284
+ <%} // foreach(TableKeySchema unique in table.TableKeySchemas) %>
285
+ #endregion
286
+
287
+ #region ForeignKeyProviders
288
+ <% foreach(TableKeySchema foreignKey in table.ForeignKeys){ %>
289
+ /// <summary>
290
+ /// Gets or sets the <see cref="IForeignKeyProvider"/> that fetches valid
291
+ /// foreign key columns values for
292
+ /// the <em><%= GetForeignKeyProviderName(foreignKey) %></em> foreign key constraint.
293
+ /// </summary>
294
+ /// <value>
295
+ /// A <see cref="IForeignKeyProvider"/> that fetches valid
296
+ /// foreign key columns values for
297
+ /// the <em><%= GetForeignKeyProviderName(foreignKey) %></em> foreign key constraint.
298
+ /// </value>
299
+ /// <exception type="ArgumentNullException">
300
+ /// set property, the value is a null reference.
301
+ /// </exception>
302
+ public IForeignKeyProvider <%= GetForeignKeyProviderName(foreignKey)%>
303
+ {
304
+ get
305
+ {
306
+ ForeignKeyConstraint foreignKey = this.Table.Constraints["<%= foreignKey.Name %>"] as ForeignKeyConstraint;
307
+ if (foreignKey==null)
308
+ throw new InvalidOperationException("Could not find ForeignKeyConstraint <%= foreignKey.Name %>");
309
+ IForeignKeyProvider provider = this.ForeignKeys[foreignKey];
310
+ if (provider==null)
311
+ throw new InvalidOperationException("Could not find provider for UniqueConstraint <%= foreignKey.Name %>");
312
+ return provider;
313
+ }
314
+ set
315
+ {
316
+ if (value==null)
317
+ throw new ArgumentNullException("IForeignKeyProvider cannot be null");
318
+ ForeignKeyConstraint foreignKey = this.Table.Constraints["<%= foreignKey.Name %>"] as ForeignKeyConstraint;
319
+ if (foreignKey==null)
320
+ throw new InvalidOperationException("Could not find ForeignKeyConstraint <%= foreignKey.Name %>");
321
+ this.ForeignKeys[foreignKey] = value;
322
+ }
323
+ }
324
+ <%} // foreach(TableKeySchema foreignKey in table.ForeignKeys) %>
325
+ #endregion
326
+ }
327
+ #endregion
328
+ <%} // foreach(TableSchema table in this.Database.Tables) %>
329
+ #endregion
330
+
331
+ }
332
+ }
333
+ <script runat="template">
334
+ #region Properties
335
+ public string DatabaseName
336
+ {
337
+ get
338
+ {
339
+ return this.Database.Name;
340
+ }
341
+ }
342
+
343
+ public string DataSetName
344
+ {
345
+ get{ return Format(this.DataSetNameFormat, this.DatabaseName);}
346
+ }
347
+
348
+ public string DatabasePopulatorName
349
+ {
350
+ get{ return Format(this.DatabasePopulatorNameFormat,this.DatabaseName);}
351
+ }
352
+ public string GetTablePopulatorName(TableSchema table)
353
+ {
354
+ return Format(this.TablePopulatorNameFormat, table.Name);
355
+ }
356
+ public string GetTablePopulatorPropertyName(TableSchema table)
357
+ {
358
+ return Format(table.Name);
359
+ }
360
+ public string GetColumnDataGeneratorName(ColumnSchema column)
361
+ {
362
+ return Format(ColumnDataGeneratorNameFormat, column.Name);
363
+ }
364
+ public string GetUniqueValidatorName(TableKeySchema unique)
365
+ {
366
+ return Format(UniqueValidatorNameFormat, unique.Name);
367
+ }
368
+ public string GetForeignKeyProviderName(TableKeySchema unique)
369
+ {
370
+ return Format(ForeignKeyProviderNameFormat, unique.Name);
371
+ }
372
+
373
+ protected string Format(string format, params Object[] args)
374
+ {
375
+ string result = string.Format(format,args);
376
+ if (this.TableNamePrefix!=null && this.TableNamePrefix.Length > 0)
377
+ {
378
+ if (result.StartsWith(this.TableNamePrefix))
379
+ result = result.Substring(this.TableNamePrefix.Length);
380
+ }
381
+
382
+ result = result.Replace(" ","").Replace("_","").Replace(".","");
383
+ return result;
384
+ }
385
+ #endregion
386
+ </script>
@@ -0,0 +1,177 @@
1
+ <%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="TestFu DatabasePopulator Template" %>
2
+ <%@ Property Name="Namespace" Type="System.String"
3
+ Default="Populators"
4
+ Category="Output"
5
+ Description="Namespace of the populator." %>
6
+ <%@ Property Name="TestFixtureFormatName" Type="System.String"
7
+ Default="{0}CrudTest"
8
+ Category="Output"
9
+ Description="Format string of the fixture" %>
10
+ <%@ Property Name="DataSetNameFormat" Type="System.String"
11
+ Default="{0}DataSet"
12
+ Category="Output"
13
+ Description="Format string to create the DatabaseSet class name." %>
14
+ <%@ Property Name="DatabasePopulatorNameFormat" Type="System.String"
15
+ Default="{0}DatabasePopulator"
16
+ Category="Output"
17
+ Description="Format string to create the DatabasePopulator class name." %>
18
+ <%@ Property Name="CrudPopulatorNameFormat" Type="System.String"
19
+ Default="{0}CrudPopulator"
20
+ Category="Output"
21
+ Description="Format string to create the CrudPopulator class name." %>
22
+ <%@ Property Name="TableNamePrefix" Type="System.String"
23
+ Default=""
24
+ Category="Output"
25
+ Optional="true"
26
+ Description="Prefix to be removed." %>
27
+ <%@ Property Name="RollBack" Type="System.Boolean"
28
+ Default="false"
29
+ Category="Output"
30
+ Description="True if Rollback attribute is used." %>
31
+ <%@ Property Name="TablePopulatorNameFormat" Type="System.String"
32
+ Default="{0}TablePopulator"
33
+ Category="Output"
34
+ Description="Format string to create the TablePopulator class names." %>
35
+ <%@ Property Name="ColumnDataGeneratorNameFormat" Type="System.String"
36
+ Default="{0}DataGenerator"
37
+ Category="Output"
38
+ Description="Format string to create the ColumnGenenerator properties." %>
39
+ <%@ Property Name="UniqueValidatorNameFormat" Type="System.String"
40
+ Default="{0}Validator"
41
+ Category="Output"
42
+ Description="Format string to create the UniqueValidator properties." %>
43
+ <%@ Property Name="ForeignKeyProviderNameFormat" Type="System.String"
44
+ Default="{0}Provider"
45
+ Category="Output"
46
+ Description="Format string to create the ForeignKeyProviderNameFormat properties." %>
47
+ <%@ Property Name="Database" Type="SchemaExplorer.DatabaseSchema"
48
+ Category="Context"
49
+ Description="Target database for the IDatabasePopulator." %>
50
+ <%@ Assembly Name="SchemaExplorer" %>
51
+ <%@ Import Namespace="SchemaExplorer" %>
52
+ //////////////////////////////////////////////////////////////////
53
+ //
54
+ // Strongly typed populator for the <%= DatabaseName %>
55
+ //
56
+ //////////////////////////////////////////////////////////////////
57
+
58
+ using System;
59
+ using System.Data;
60
+ using System.Data.SqlClient;
61
+ using System.Configuration;
62
+
63
+ using MbUnit.Core.Framework;
64
+ using MbUnit.Framework;
65
+
66
+ using TestFu.Data;
67
+ using TestFu.Data.Populators;
68
+ using TestFu.Data.SqlClient;
69
+
70
+ namespace <%= Namespace %>
71
+ {
72
+ [TestFixture]
73
+ public class <%= String.Format(this.TestFixtureFormatName, Format(DatabaseName)) %>
74
+ {
75
+ private string connectionString;
76
+ private <%= CrudPopulatorName %> populator;
77
+
78
+ [TestFixtureSetUp]
79
+ public void TestFixtureSetUp()
80
+ {
81
+ this.connectionString = ConfigurationSettings.AppSettings["connString"];
82
+ this.populator = new <%= CrudPopulatorName %>(connectionString);
83
+ }
84
+
85
+ <% foreach(TableSchema table in this.Database.Tables) {%>
86
+ [Test<%= AddRollBack() %>]
87
+ public void Create<%= Format(table.Name) %>()
88
+ {
89
+ this.populator.Create<%= Format(table.Name) %>();
90
+ }
91
+ [Test<%= AddRollBack() %>]
92
+ public void CreateAndDelete<%= Format(table.Name) %>()
93
+ {
94
+ DataRow row = this.populator.Create<%= Format(table.Name) %>();
95
+ this.populator.Delete<%= Format(table.Name) %>(row);
96
+ }
97
+ <% if (table.PrimaryKey.MemberColumns.Count != table.Columns.Count ) {%>
98
+ [Test<%= AddRollBack() %>]
99
+ public void CreateAndUpdate<%= Format(table.Name) %>()
100
+ {
101
+ DataRow row = this.populator.Create<%= Format(table.Name) %>();
102
+ this.populator.Update<%= Format(table.Name) %>();
103
+ }
104
+ <% } %>
105
+ <%} // foreach(TableSchema table in this.Database.Tables) %>
106
+ }
107
+ }
108
+ <script runat="template">
109
+ #region Properties
110
+ public string CrudPopulatorName
111
+ {
112
+ get{ return Format(this.CrudPopulatorNameFormat,this.DatabaseName);}
113
+ }
114
+ public string DatabaseName
115
+ {
116
+ get
117
+ {
118
+ return this.Database.Name;
119
+ }
120
+ }
121
+
122
+ public string DataSetName
123
+ {
124
+ get{ return Format(this.DataSetNameFormat, this.DatabaseName);}
125
+ }
126
+ public string AddRollBack()
127
+ {
128
+ if (this.RollBack)
129
+ return ",RollBack";
130
+ else
131
+ return "";
132
+ }
133
+
134
+ public string DatabasePopulatorName
135
+ {
136
+ get{ return Format(this.DatabasePopulatorNameFormat,this.DatabaseName);}
137
+ }
138
+ public string GetTablePopulatorName(TableSchema table)
139
+ {
140
+ return Format(this.TablePopulatorNameFormat, table.Name);
141
+ }
142
+ public string GetTablePopulatorPropertyName(TableSchema table)
143
+ {
144
+ return Format(table.Name);
145
+ }
146
+ public string GetColumnDataGeneratorName(ColumnSchema column)
147
+ {
148
+ return Format(ColumnDataGeneratorNameFormat, column.Name);
149
+ }
150
+ public string GetUniqueValidatorName(TableKeySchema unique)
151
+ {
152
+ return Format(UniqueValidatorNameFormat, unique.Name);
153
+ }
154
+ public string GetForeignKeyProviderName(TableKeySchema unique)
155
+ {
156
+ return Format(ForeignKeyProviderNameFormat, unique.Name);
157
+ }
158
+ protected string FormatLower(string format, params object[] args)
159
+ {
160
+ string s= Format(format,args);
161
+ return Char.ToLower(s[0]) + s.Substring(1);
162
+ }
163
+ protected string Format(string format, params Object[] args)
164
+ {
165
+ string result = string.Format(format,args);
166
+ if (this.TableNamePrefix!=null && this.TableNamePrefix.Length > 0)
167
+ {
168
+ if (result.StartsWith(this.TableNamePrefix))
169
+ result = result.Substring(this.TableNamePrefix.Length);
170
+ }
171
+
172
+ result = result.Replace(" ","").Replace("_","").Replace(".","");
173
+ return result;
174
+ }
175
+
176
+ #endregion
177
+ </script>