mbunit2 2.4.2.355.20100801

Sign up to get free protection for your applications and to get access to all the features.
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,443 @@
1
+ <%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="TestFu DatabasePopulator Crud Harness" %>
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="CrudPopulatorNameFormat" Type="System.String"
11
+ Default="{0}CrudPopulator"
12
+ Category="Output"
13
+ Description="Format string to create the CrudPopulator 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="TableNamePrefix" Type="System.String"
19
+ Default=""
20
+ Category="Output"
21
+ Description="Prefix to be removed." %>
22
+ <%@ Property Name="TablePopulatorNameFormat" Type="System.String"
23
+ Default="{0}TablePopulator"
24
+ Category="Output"
25
+ Description="Format string to create the TablePopulator class names." %>
26
+ <%@ Property Name="ColumnDataGeneratorNameFormat" Type="System.String"
27
+ Default="{0}DataGenerator"
28
+ Category="Output"
29
+ Description="Format string to create the ColumnGenenerator properties." %>
30
+ <%@ Property Name="UniqueValidatorNameFormat" Type="System.String"
31
+ Default="{0}Validator"
32
+ Category="Output"
33
+ Description="Format string to create the UniqueValidator properties." %>
34
+ <%@ Property Name="ForeignKeyProviderNameFormat" Type="System.String"
35
+ Default="{0}Provider"
36
+ Category="Output"
37
+ Description="Format string to create the ForeignKeyProviderNameFormat properties." %>
38
+ <%@ Property Name="Database" Type="SchemaExplorer.DatabaseSchema"
39
+ Category="Context"
40
+ Description="Target database for the IDatabasePopulator." %>
41
+ <%@ Assembly Name="SchemaExplorer" %>
42
+ <%@ Import Namespace="SchemaExplorer" %>
43
+ //////////////////////////////////////////////////////////////////
44
+ //
45
+ // Strongly typed CRUD populator for the <%= DatabaseName %>
46
+ //
47
+ // This file was generated by CodeSmith. Do not edit it! Modify
48
+ // the template if you need to tweak it for you.
49
+ //
50
+ //////////////////////////////////////////////////////////////////
51
+
52
+ using System;
53
+ using System.Data;
54
+ using System.Data.SqlClient;
55
+
56
+ using MbUnit.Core.Framework;
57
+ using MbUnit.Framework;
58
+
59
+ using TestFu.Data;
60
+ using TestFu.Data.SqlClient;
61
+ using TestFu.Data.Graph;
62
+
63
+ namespace <%= Namespace %>
64
+ {
65
+ /// <summary>
66
+ /// A CRUD harness for the <%= DatabaseName %> database.
67
+ /// </summary>
68
+ /// <remarks>
69
+ /// <para><b>Note to implementors:</b></para>
70
+ /// <para>
71
+ /// Implementors should modify the CodeSmith template that generated
72
+ /// this class to inject their Create,Update,Read and Delete methods.
73
+ /// Each generated method contains a <see cref="NotImplementedException"/>
74
+ /// that should be replaced with the proper DAL code.
75
+ /// </para>
76
+ /// <para>
77
+ /// The <c>Create*</c> methods create a new row and verify that it is
78
+ /// present in the database using the <c>Read*</c> methods.
79
+ /// The <c>Update*</c> methods apply an update between two rows and
80
+ /// verify that the update was succesful using <c>Read*</c> methods.
81
+ /// The <c>Delete*</c> remove a row from the tables and verify
82
+ /// that it has been removed using <c>Read*</c> methods.
83
+ /// </para>
84
+ /// <remarks>
85
+ public class <%= CrudPopulatorName %> : <%= DatabasePopulatorName %>
86
+ {
87
+ #region Constructors
88
+ /// <summary>
89
+ /// Initializes a new <see cref="<%= CrudPopulatorName %>"/> with the
90
+ /// connection string of the database.
91
+ /// </summary>
92
+ /// <param name="connectionString">
93
+ /// A valid conneciton string to the target database.
94
+ /// </param>
95
+ /// <exception type="ArgumentNullException">
96
+ /// The <paramref name="connectionString"/> is a
97
+ /// null reference (Nothing in Visual Basic).
98
+ /// </exception>
99
+ /// <exception type="ArgumentException">
100
+ /// The <paramref name="connectionString"/> is empty.
101
+ /// </exception>
102
+ public <%= DatabasePopulatorName %>(string connectionString)
103
+ :this(new <%= DataSetName %>(), connectionString)
104
+ {}
105
+
106
+ /// <summary>
107
+ /// Initializes a new <see cref="<%= CrudPopulatorName %>"/> with the
108
+ /// connection string of the database.
109
+ /// </summary>
110
+ /// <param name="dataSet">
111
+ /// A <see cref="DataSet"/> representing the structure of the
112
+ /// <em><%= DatabaseName %></em> database.
113
+ /// </param>
114
+ /// <param name="connectionString">
115
+ /// A valid conneciton string to the target database.
116
+ /// </param>
117
+ /// <exception type="ArgumentNullException">
118
+ /// The <paramref name="dataSet"/> or the <paramref name="connectionString"/> is a
119
+ /// null reference (Nothing in Visual Basic).
120
+ /// </exception>
121
+ /// <exception type="ArgumentException">
122
+ /// The <paramref name="connectionString"/> is empty.
123
+ /// </exception>
124
+ public <%= CrudPopulatorName %>(
125
+ DataSet dataSet,
126
+ string connectionString
127
+ )
128
+ :base(dataSet,connectionString)
129
+ {}
130
+ #endregion
131
+
132
+ <% foreach(TableSchema table in this.Database.Tables) {%>
133
+ #region <%= table.Name %>
134
+ /// <summary>
135
+ /// Creates a new <see cref="DataRow"/> in the
136
+ /// <em><%= table.Name %> table.
137
+ /// </summary>
138
+ /// <returns>
139
+ /// The created <see cref="DataRow"/> instance
140
+ /// </returns>
141
+ public virtual DataRow Create<%= Format(table.Name) %>()
142
+ {
143
+ // generate row
144
+ DataRow row = this.<%=GetTablePopulatorPropertyName(table)%>.Generate();
145
+ // extract info
146
+ <% foreach(ColumnSchema column in table.Columns) {%>
147
+ <%= FetchColumnValue(column) %>
148
+ <% } // foreach(ColumnSchema column in table.Columns) %>
149
+
150
+ // TODO: add the row to the <%= table.Name %> table here
151
+ <%= DalTableName(table) %>DB db = new <%= DalTableName(table) %>DB();
152
+ row["<%= table.PrimaryKey.MemberColumns[0].Name%>"] = db.Add<%= DalTableName(table) %>(
153
+ <% for(int i = 0;i<table.NonPrimaryKeyColumns.Count;++i) {
154
+ ColumnSchema column = table.NonPrimaryKeyColumns[i];
155
+ if (i==0) {%>
156
+ <%= FormatLower(column.Name) %>
157
+ <% } else { %>
158
+ ,<%= FormatLower(column.Name) %>
159
+ <% } %>
160
+ <% } // foreach(ColumnSchema column in table.Columns) %>
161
+ );
162
+
163
+ // check Create has been successfull
164
+ DataRow readRow = Read<%= Format(table.Name)%>(row);
165
+ if (readRow==null)
166
+ {
167
+ DisplayRow(row);
168
+ Assert.Fail("Row creation failed");
169
+ }
170
+ else
171
+ {
172
+ // verify that data are equal
173
+ DataAssert.AreEqual(row, readRow);
174
+ }
175
+
176
+ return row;
177
+ }
178
+
179
+ /// <summary>
180
+ /// Updates a row (chosen randomly) with a new generated row in the
181
+ /// <em><%= table.Name %> table.
182
+ /// </summary>
183
+ /// <returns>
184
+ /// The update <see cref="DataRow"/> instance
185
+ /// </returns>
186
+ public virtual DataRow Update<%= Format(table.Name) %>()
187
+ {
188
+ // generate row
189
+ DataRow row = this.<%=GetTablePopulatorPropertyName(table)%>.Generate();
190
+ // update random
191
+ return Update<%= Format(table.Name) %>(row);
192
+ }
193
+
194
+ /// <summary>
195
+ /// Updates a row (chosen randomly) with a <see cref="DataRow"/> in the
196
+ /// <em><%= table.Name %> table.
197
+ /// </summary>
198
+ /// <returns>
199
+ /// The update <see cref="DataRow"/> instance
200
+ /// </returns>
201
+ public virtual DataRow Update<%= Format(table.Name) %>(DataRow row)
202
+ {
203
+ if (row==null)
204
+ throw new ArgumentNullException("row");
205
+ // choose a row
206
+ DataRow rowToUpdate = this.<%=GetTablePopulatorPropertyName(table)%>.GetRandomRow();
207
+ return Update<%= Format(table.Name) %>(row, rowToUpdate);
208
+ }
209
+
210
+ /// <summary>
211
+ /// Updates <paramref name="row"/> with <paramref name="rowToUpdate"/> in the
212
+ /// <em><%= table.Name %> table.
213
+ /// </summary>
214
+ /// <returns>
215
+ /// The update <see cref="DataRow"/> instance
216
+ /// </returns>
217
+ public virtual DataRow Update<%= Format(table.Name) %>(DataRow row, DataRow rowToUpdate)
218
+ {
219
+ if (row==null)
220
+ throw new ArgumentNullException("row");
221
+ if (rowToUpdate==null)
222
+ throw new ArgumentNullException("rowToUpdate");
223
+ // extract info
224
+ <% foreach(ColumnSchema column in table.Columns) {%>
225
+ <%= FetchColumnValue(column) %>
226
+ <% } // foreach(ColumnSchema column in table.Columns) %>
227
+
228
+ // TODO: update the rowToUpdate with row in the <%= table.Name %> table
229
+ <%= DalTableName(table) %>DB db = new <%= DalTableName(table) %>DB();
230
+ db.Update<%= DalTableName(table) %>(
231
+ <% for(int i = 0;i<table.Columns.Count;++i) {
232
+ ColumnSchema column = table.Columns[i];
233
+ if (i==0) {%>
234
+ <%= FormatLower(column.Name) %>
235
+ <% } else { %>
236
+ ,<%= FormatLower(column.Name) %>
237
+ <% } %>
238
+ <% } // foreach(ColumnSchema column in table.Columns) %>
239
+ );
240
+
241
+ // check Update has been successfull
242
+ DataRow readRow = Read<%= Format(table.Name)%>(rowToUpdate);
243
+ if (readRow==null)
244
+ {
245
+ Console.WriteLine("New row:");
246
+ DisplayRow(row);
247
+ Console.WriteLine("Row to update:");
248
+ DisplayRow(rowToUpdate);
249
+ Assert.Fail("Row update failed");
250
+ }
251
+ else
252
+ {
253
+ // verify that data are equal
254
+ DataAssert.AreEqual(rowToUpdate, readRow);
255
+ }
256
+
257
+ return rowToUpdate;
258
+ }
259
+
260
+ /// <summary>
261
+ /// Deletes a random row
262
+ /// from the <em><%= table.Name %></em> table.
263
+ /// </summary>
264
+ public virtual void Delete<%= Format(table.Name) %>()
265
+ {
266
+ // choose a row
267
+ DataRow row = this.<%=GetTablePopulatorPropertyName(table)%>.GetRandomRow();
268
+
269
+ // delete
270
+ this.Delete<%= Format(table.Name) %>(row);
271
+ }
272
+
273
+ /// <summary>
274
+ /// Deletes the row
275
+ /// from the <em><%= table.Name %></em> table.
276
+ /// </summary>
277
+ public virtual void Delete<%= Format(table.Name) %>(DataRow row)
278
+ {
279
+ if (row==null)
280
+ throw new ArgumentNullException("row");
281
+ // extract info
282
+ <% foreach(ColumnSchema column in table.PrimaryKey.MemberColumns) {%>
283
+ <%= FetchColumnValue(column) %>
284
+ <% } // foreach(ColumnSchema column in table.Columns) %>
285
+
286
+ // TODO: delete the row from the <%= table.Name %> table
287
+ <%= DalTableName(table) %>DB db = new <%= DalTableName(table) %>DB();
288
+ db.Delete<%= DalTableName(table) %>(
289
+ <% for(int i = 0;i<table.PrimaryKey.MemberColumns.Count;++i) {
290
+ ColumnSchema column = table.PrimaryKey.MemberColumns[i];
291
+ if (i==0) {%>
292
+ <%= FormatLower(column.Name) %>
293
+ <% } else { %>
294
+ ,<%= FormatLower(column.Name) %>
295
+ <% } %>
296
+ <% } // foreach(ColumnSchema column in table.Columns) %>
297
+ );
298
+
299
+ // check it is not in the table
300
+ DataRow readRow = Read<%= Format(table.Name) %>(row);
301
+ if (readRow!=null)
302
+ {
303
+ Console.WriteLine("Row to delete");
304
+ DisplayRow(row);
305
+ Console.WriteLine("Not deleted row");
306
+ DisplayRow(readRow);
307
+ Assert.Fail("Row delete failed");
308
+ }
309
+ }
310
+
311
+ /// <summary>
312
+ /// Reads the <em><%= table.Name %></em> table for a row matching <paramref name="row"/>
313
+ /// and returns it.
314
+ /// </summary>
315
+ /// <returns>
316
+ /// Read <see cref="DataRow"/> row if foud; otherwize
317
+ /// a null reference.
318
+ /// </returns>
319
+ public virtual DataRow Read<%= Format(table.Name) %>(DataRow row)
320
+ {
321
+ if (row==null)
322
+ throw new ArgumentNullException("row");
323
+
324
+ // extract info
325
+ <% foreach(ColumnSchema column in table.Columns) {%>
326
+ <%= FetchColumnValue(column) %>
327
+ <% } // foreach(ColumnSchema column in table.Columns) %>
328
+
329
+ // TODO: read the data from the db and return the row,
330
+ // if not found, return null
331
+ <%= DalTableName(table) %>DB db = new <%= DalTableName(table) %>DB();
332
+ using(IDataReader dr = db.Get<%= DalTableName(table) %>DataReader(
333
+ <% for(int i = 0;i<table.PrimaryKey.MemberColumns.Count;++i) {
334
+ ColumnSchema column = table.PrimaryKey.MemberColumns[i];
335
+ if (i==0) {%>
336
+ <%= FormatLower(column.Name) %>
337
+ <% } else { %>
338
+ ,<%= FormatLower(column.Name) %>
339
+ <% } %>
340
+ <% } // foreach(ColumnSchema column in table.Columns) %>
341
+ ))
342
+ {
343
+ if (!dr.Read())
344
+ return null;
345
+
346
+ DataRow readRow = row.Table.NewRow();
347
+ for (int i = 0; i < dr.FieldCount; ++i)
348
+ readRow[i] = dr[i];
349
+ return readRow;
350
+ }
351
+ }
352
+ #endregion
353
+
354
+ <%} // foreach(TableSchema table in this.Database.Tables) %>
355
+
356
+
357
+ protected virtual void DisplayRow(DataRow row)
358
+ {
359
+ if (row==null)
360
+ throw new ArgumentNullException("row");
361
+ foreach(DataColumn column in row.Table.Columns)
362
+ {
363
+ Console.WriteLine("\t{0}: {1}",
364
+ column.ColumnName,
365
+ row[column].ToString());
366
+ }
367
+ }
368
+ }
369
+ }
370
+ <script runat="template">
371
+ #region Properties
372
+ public string DatabaseName
373
+ {
374
+ get
375
+ {
376
+ return this.Database.Name;
377
+ }
378
+ }
379
+ public string FetchColumnValue(ColumnSchema column)
380
+ {
381
+ if (column.AllowDBNull)
382
+ return String.Format("NullableTypes.{0} {1}= NullableTypes.HelperFunctions.DBNullConvert.To{0}(row[\"{2}\"]);",ToNullableTypes(column),FormatLower(column.Name),column.Name);
383
+ else
384
+ return String.Format("{0} {1} = ({0})row[\"{2}\"];",column.SystemType,FormatLower(column.Name),column.Name);
385
+ }
386
+ public string ToNullableTypes(ColumnSchema column)
387
+ {
388
+ string name = column.SystemType.Name;
389
+ return String.Format("Nullable{0}",name);
390
+ }
391
+ public string DalTableName(TableSchema table)
392
+ {
393
+ string name = Format(table.Name);
394
+ return name.TrimEnd('s');
395
+ }
396
+ public string DataSetName
397
+ {
398
+ get{ return Format(this.DataSetNameFormat, this.DatabaseName);}
399
+ }
400
+ public string CrudPopulatorName
401
+ {
402
+ get{ return Format(this.CrudPopulatorNameFormat,this.DatabaseName);}
403
+ }
404
+ public string DatabasePopulatorName
405
+ {
406
+ get{ return Format(this.DatabasePopulatorNameFormat,this.DatabaseName);}
407
+ }
408
+ public string GetTablePopulatorName(TableSchema table)
409
+ {
410
+ return Format(this.TablePopulatorNameFormat, table.Name);
411
+ }
412
+ public string GetTablePopulatorPropertyName(TableSchema table)
413
+ {
414
+ return Format(table.Name);
415
+ }
416
+ public string GetColumnDataGeneratorName(ColumnSchema column)
417
+ {
418
+ return Format(ColumnDataGeneratorNameFormat, column.Name);
419
+ }
420
+ public string GetUniqueValidatorName(TableKeySchema unique)
421
+ {
422
+ return Format(UniqueValidatorNameFormat, unique.Name);
423
+ }
424
+ public string GetForeignKeyProviderName(TableKeySchema unique)
425
+ {
426
+ return Format(ForeignKeyProviderNameFormat, unique.Name);
427
+ }
428
+ protected string FormatLower(string format, params object[] args)
429
+ {
430
+ string s= Format(format,args);
431
+ return Char.ToLower(s[0]) + s.Substring(1);
432
+ }
433
+ protected string Format(string format, params Object[] args)
434
+ {
435
+ string result = string.Format(format,args);
436
+ if (result.StartsWith(this.TableNamePrefix))
437
+ result = result.Substring(this.TableNamePrefix.Length);
438
+
439
+ result = result.Replace(" ","").Replace("_","").Replace(".","");
440
+ return result;
441
+ }
442
+ #endregion
443
+ </script>
@@ -0,0 +1,469 @@
1
+ <%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Assert Tester Wrapper" Debug="True"%>
2
+ <%@ Property Name="Class" Type="System.String" Category="Options" Description="Prefix of the class name, Assert will be appended." %>
3
+ <%@ Property Name="Namespace" Type="System.String" Category="Options" Description="Namespace of the wrapped class" %>
4
+ <%@ Property Name="TestNamespace" Type="System.String" Category="Options" Description="Namespace of the generated test" Optional="False" %>
5
+ <%@ Property Name="AsTypeFixture" Type="System.Boolean" Category="Options" Description="Generate as Type fixture" %>
6
+ <%@ Property Name="TestConstructors" Type="System.Boolean" Category="Options" Description="Generate tests for constructors" Default="True" %>
7
+ <%@ Property Name="TestAllProperties" Type="System.Boolean" Category="Options" Description="Generate tests for constructors" Default="True" %>
8
+ <%@ Property Name="TestAllMethods" Type="System.Boolean" Category="Options" Description="Generate tests for constructors" Default="True" %>
9
+ <%@ Property Name="TestMethodsDeep" Type="System.Boolean" Category="Options" Description="Generate tests for constructors" Default="True" %>
10
+ <%@ Assembly Name="AssemblyHelper"%>
11
+ <%@ Assembly Name="ILReader"%>
12
+ <%@ Assembly Name="QuickGraph.Applications"%>
13
+ <%@ Assembly Name="QuickGraph"%>
14
+ <%@ Assembly Name="QuickGraph.Concepts"%>
15
+ <%@ Assembly Name="QuickGraph.Collections"%>
16
+ <%@ Import Namespace="System.Reflection" %>
17
+ <%@ Import Namespace="System.Reflection.Emit" %>
18
+ <%@ Import Namespace="System.Collections" %>
19
+ <%@ Import Namespace="System.IO" %>
20
+ <%@ Import Namespace="System.Text.RegularExpressions" %>
21
+ <%@ Import Namespace="AssemblyHelper" %>
22
+ <%@ Import Namespace="Reflector.Disassembler"%>
23
+
24
+ using System;
25
+ using MbUnit.Core.Framework;
26
+ using MbUnit.Framework;
27
+
28
+ using <%= Namespace %>;
29
+
30
+ namespace <%= TestNamespace %>
31
+ {
32
+ /// <summary>
33
+ /// Unit test fixture for the <%=SeeClass %>
34
+ /// </summary>
35
+ /// <remarks>
36
+ /// <para>
37
+ /// This class was originially generated by a template.
38
+ /// When created, it contains Ignored empty test only. This is just a tool, don't expect intelligent
39
+ /// testing here.
40
+ /// </para>
41
+ /// </remarks>
42
+ <% if (AsTypeFixture){%>
43
+ [TypeFixture(typeof(<%= Class %>))]
44
+ <%}else{%>
45
+ [TestFixture]
46
+ <%}%>
47
+ public class <%= Fixture %>
48
+ {
49
+ <% if (!AsTypeFixture) { %>
50
+ #region private members
51
+ private <%= Class %> instance = null;
52
+ #endregion
53
+
54
+ #region Set up and tear down
55
+ /// <summary>
56
+ /// Sets the <see cref="instance"/> instance.
57
+ /// </summary>
58
+ /// <remarks>
59
+ /// <para>
60
+ /// Allocates an <%= SeeClass %> instance to be used in the tests.
61
+ /// </para>
62
+ /// <para>
63
+ /// Not implemented.
64
+ /// </para>
65
+ /// </remarks>
66
+ [SetUp]
67
+ public void SetUp()
68
+ {
69
+ throw new NotImplementedException();
70
+ }
71
+
72
+ /// <summary>
73
+ /// Releases the resources allocated for the fixture.
74
+ /// </summary>
75
+ /// <remarks>
76
+ /// <para>
77
+ /// Make this method release resource allocated for/during the test.
78
+ /// </para>
79
+ <%if (ClassType is IDisposable){%>
80
+ /// <para>
81
+ /// Disposes the instance method.
82
+ /// </para>
83
+ <%}%>
84
+ /// <para>
85
+ /// Not implemented.
86
+ /// </para>
87
+ /// </remarks>
88
+ [TearDown]
89
+ public void TearDown()
90
+ {
91
+ <%if (ClassType is IDisposable){%>
92
+ if (this.instance!=null)
93
+ {
94
+ this.instance.Dispose();
95
+ this.instance=null;
96
+ }
97
+ <%}%>
98
+ throw new NotImplementedException();
99
+ }
100
+ #endregion
101
+ <% if (TestConstructors) {%>
102
+ #region Constructors
103
+ <% foreach(ConstructorInfo ci in this.ClassType.GetConstructors()){%>
104
+ /// <summary>
105
+ /// Tests the constructor that takes following arguments:
106
+ /// <%= ParameterToComment(ci.GetParameters()) %>
107
+ /// </summary>
108
+ [Test]
109
+ [Ignore("Needs implementation")]
110
+ public void <%= ConstructorSignature(ci) %>()
111
+ {
112
+ throw new NotImplementedException();
113
+ }
114
+ <%}%>
115
+ #endregion
116
+ <%}%>
117
+
118
+ <%}%>
119
+ #region Testing properties
120
+ <% if (this.TestAllProperties){
121
+ foreach(PropertyInfo pi in this.ClassType.GetProperties())
122
+ {
123
+ if (pi.CanRead)
124
+ {%>
125
+ /// <summary>
126
+ /// Verifies that the <see cref="<%= pi.Name%>"/> property can be get.
127
+ /// </summary>
128
+ /// <remarks>
129
+ /// <para>
130
+ /// Tries to retreives the value of the property.
131
+ /// </para>
132
+ /// <para>
133
+ /// Not implemented.
134
+ /// </para>
135
+ /// </remarks>
136
+ <% AddArgsComment(); %>
137
+ [Test("Tests the <%= pi.Name %> can be read")]
138
+ [Ignore("Needs implementation")]
139
+ public void Get<%= pi.Name %>Test(<%= Args %>)
140
+ {
141
+ <%= pi.PropertyType %> value = <%= Instance%>.<%= pi.Name %>;
142
+ throw new NotImplementedException();
143
+ }
144
+
145
+ <%}
146
+ if (pi.CanWrite)
147
+ {%>
148
+ /// <summary>
149
+ /// Verifies that the <see cref="<%= pi.Name%>"/> property can be set.
150
+ /// </summary>
151
+ /// <remarks>
152
+ /// <para>
153
+ /// Not implemented.
154
+ /// </para>
155
+ /// </remarks>
156
+ <% AddArgsComment(); %>
157
+ [Test("Tests the <%= pi.Name %> can be written")]
158
+ [Ignore("Needs implementation")]
159
+ public void Set<%= pi.Name %>Test(<%= Args %>)
160
+ {
161
+ <%= pi.PropertyType %> value;
162
+ <%= Instance %>.<%= pi.Name %> = value;
163
+ throw new NotImplementedException();
164
+ }
165
+
166
+ <%}%>
167
+ <%}}%>
168
+ #endregion
169
+
170
+ #region Method tests
171
+ <% if(this.TestAllMethods){
172
+ foreach(MethodInfo mi in this.ClassType.GetMethods())
173
+ {
174
+ if (mi.Name.StartsWith("get_") || mi.Name.StartsWith("set_"))
175
+ continue;%>
176
+ /// <summary>
177
+ /// Tests the <see cref="<%= mi.Name %>"/> method
178
+ /// </summary>
179
+ /// <remarks>
180
+ /// <para>
181
+ /// Not implemented
182
+ /// </para>
183
+ /// </remarks>
184
+ <% AddArgsComment(); %>
185
+ [Test]
186
+ [Ignore("Needs implementation")]
187
+ public void <%= Beautify(mi.Name) %>(<%= Args%>)
188
+ {
189
+ throw new NotImplementedException();
190
+ }
191
+
192
+ <%}}%>
193
+ <%if (this.TestMethodsDeep){
194
+ ModuleReader reader = new ModuleReader(this.ClassType.Module, new AssemblyProvider());
195
+ foreach (MethodInfo mi in this.ClassType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly))
196
+ {
197
+ MethodBody methodBody = reader.GetMethodBody(mi);
198
+ int index = -1;
199
+
200
+ foreach(ICollection path in IlGrapher.IlGraphBuilder.GetAllEdgesPath(mi))
201
+ {
202
+ index++;
203
+ %>
204
+ /// <summary>
205
+ /// Tests that the <see cref="<%= mi.Name %>"/> method throws (see remarks)
206
+ /// </summary>
207
+ /// <remarks>
208
+ /// <para>
209
+ /// Not implemented
210
+ /// </para>
211
+ <% RenderPathToCode(methodBody, path); %>
212
+ /// </remarks>
213
+ <% AddArgsComment(); %>
214
+ [Test]
215
+ [Ignore("Needs implementation")]
216
+ public void <%= Beautify(mi.Name) %><%= index %>(<%= Args%>)
217
+ {
218
+ // don't forget to update the exception type.
219
+ throw new NotImplementedException();
220
+ }
221
+ <% }
222
+ }
223
+ }%>
224
+ #endregion
225
+ }
226
+ }
227
+
228
+ <script runat="template">
229
+ private Assembly assembly;
230
+
231
+ [Editor(typeof(AssemblyHelper.AssemblyFilePicker), typeof(System.Drawing.Design.UITypeEditor))]
232
+ public Assembly AssemblyToLoad
233
+ {
234
+ get{return assembly;}
235
+ set{assembly = value;}
236
+ }
237
+
238
+ protected string Args
239
+ {
240
+ get
241
+ {
242
+ if (this.AsTypeFixture)
243
+ return String.Format("{0} instance",this.Class);
244
+ else
245
+ return null;
246
+ }
247
+ }
248
+
249
+ protected string Instance
250
+ {
251
+ get
252
+ {
253
+ if (this.AsTypeFixture)
254
+ return "instance";
255
+ else
256
+ return "this.instance";
257
+ }
258
+ }
259
+
260
+ protected string SeeClass
261
+ {
262
+ get
263
+ {
264
+ return String.Format("<see cref=\"{0}\"/>",this.Class);
265
+ }
266
+ }
267
+
268
+ protected string Fixture
269
+ {
270
+ get
271
+ {
272
+ return String.Format("{0}Test",this.Class);
273
+ }
274
+ }
275
+ protected Type ClassType
276
+ {
277
+ get
278
+ {
279
+ return this.AssemblyToLoad.GetType(String.Format("{0}.{1}",this.Namespace, this.Class), true);
280
+ }
281
+ }
282
+ protected void AddArgsComment()
283
+ {
284
+ if (!AsTypeFixture)
285
+ return;
286
+ Response.WriteLine(" /// <param ref=\"instance\">");
287
+ Response.WriteLine(" /// Tested {0} instance.", this.SeeClass);
288
+ Response.WriteLine(" /// </param>");
289
+ }
290
+
291
+ protected string ParameterToComment(ParameterInfo[] pis)
292
+ {
293
+ StringWriter sw = new StringWriter();
294
+ sw.Write("<code>");
295
+ bool comma = false;
296
+ foreach(ParameterInfo pi in pis)
297
+ {
298
+ if (comma)
299
+ sw.Write(',');
300
+ comma=true;
301
+ sw.Write("{0} {1}",pi.ParameterType.Name, pi.Name);
302
+ }
303
+ sw.Write("</code>");
304
+ return sw.ToString();
305
+ }
306
+ protected string ParameterToCode(ParameterInfo[] pis)
307
+ {
308
+ StringWriter sw = new StringWriter();
309
+ foreach(ParameterInfo pi in pis)
310
+ {
311
+ sw.Write(TypeToString(pi.ParameterType.Name));
312
+ }
313
+ return sw.ToString();
314
+ }
315
+ protected string ConstructorSignature(ConstructorInfo ci)
316
+ {
317
+ return String.Format("Constructor{0}",ParameterToCode(ci.GetParameters()));
318
+ }
319
+ protected string TypeToString(string name)
320
+ {
321
+ name = name.Replace('*','P');
322
+ name = name.Replace('[','A');
323
+ name = name.Replace(']','r');
324
+ return name;
325
+ }
326
+ protected void RenderPathToCode(MethodBody body, ICollection path)
327
+ {
328
+ Hashtable ht = new Hashtable();
329
+ foreach(IlGrapher.InstructionVertex ii in path)
330
+ ht[ii.Instruction.Offset]=null;
331
+
332
+ Response.WriteLine(" /// <code>");
333
+ foreach(Instruction ii in body.GetInstructions())
334
+ {
335
+ if (ht.Contains(ii.Offset))
336
+ Response.WriteLine(" /// [[{0}]]",Render(ii));
337
+ else
338
+ Response.WriteLine(" /// {0}",Render(ii));
339
+ }
340
+ Response.WriteLine(" /// </code>");
341
+ }
342
+
343
+ public class AssemblyNotLoadedException : Exception
344
+ {}
345
+ public class TypeNotFoundException : Exception
346
+ {}
347
+ public class MethodNotFoundException : Exception
348
+ {}
349
+ protected string Beautify(string name)
350
+ {
351
+ if (name.StartsWith("get_"))
352
+ return "Get" + name.Substring(4, name.Length-4);
353
+ else if (name.StartsWith("set_"))
354
+ return "Set" + name.Substring(4, name.Length-4);
355
+ else
356
+ return name;
357
+ }
358
+
359
+ public string Render(Instruction ii)
360
+ {
361
+ StringWriter sw =new StringWriter();
362
+ OpCode code = ii.Code;
363
+ object operand = ii.Operand;
364
+ byte[] operandData = ii.GetOperandData();
365
+
366
+ sw.Write("L_" + ii.Offset.ToString("x4") + ": ");
367
+ sw.Write(code.Name);
368
+ sw.Write(" ");
369
+
370
+ if (operand != null)
371
+ {
372
+ switch (code.OperandType)
373
+ {
374
+ case OperandType.InlineNone:
375
+ break;
376
+
377
+ case OperandType.ShortInlineBrTarget:
378
+ case OperandType.InlineBrTarget:
379
+ int target = (int) operand;
380
+ sw.Write("L_" + target.ToString("x4"));
381
+ break;
382
+
383
+ case OperandType.ShortInlineI:
384
+ case OperandType.InlineI:
385
+ case OperandType.InlineI8:
386
+ case OperandType.ShortInlineR:
387
+ case OperandType.InlineR:
388
+ sw.Write(operand.ToString());
389
+ break;
390
+
391
+ case OperandType.InlineString:
392
+ sw.Write("'" + operand.ToString() + "'");
393
+ break;
394
+
395
+ case OperandType.ShortInlineVar:
396
+ case OperandType.InlineVar:
397
+ if (operand is int)
398
+ sw.Write("V_" + operand.ToString());
399
+ else if (operand is ParameterInfo)
400
+ {
401
+ ParameterInfo parameterInfo = (ParameterInfo) operand;
402
+ sw.Write((parameterInfo.Name != null) ? parameterInfo.Name : ("A_" + parameterInfo.Position));
403
+ }
404
+ break;
405
+
406
+ case OperandType.InlineSwitch:
407
+ sw.Write("(");
408
+ int[] targets = (int[]) operand;
409
+ for (int i = 0; i < targets.Length; i++)
410
+ {
411
+ if (i != 0) sw.Write(", ");
412
+ sw.Write("L_" + targets[i].ToString("x4"));
413
+ }
414
+ sw.Write(")");
415
+ break;
416
+
417
+ case OperandType.InlineSig:
418
+ case OperandType.InlineMethod:
419
+ case OperandType.InlineField:
420
+ case OperandType.InlineType:
421
+ case OperandType.InlineTok:
422
+ if (operand is Type)
423
+ {
424
+ sw.Write((Type) operand);
425
+ }
426
+ else if (operand is MemberInfo)
427
+ {
428
+ MemberInfo memberInfo = (MemberInfo) operand;
429
+ if (memberInfo.DeclaringType != null)
430
+ {
431
+ sw.Write(memberInfo.DeclaringType);
432
+ sw.Write("::");
433
+ }
434
+ sw.Write(memberInfo);
435
+ }
436
+ else
437
+ {
438
+ throw new Exception();
439
+ }
440
+ break;
441
+ }
442
+ }
443
+ else
444
+ {
445
+ if (operandData != null)
446
+ {
447
+ sw.Write("null");
448
+ sw.Write(" // " + code.OperandType + " ");
449
+ foreach (byte b in operandData)
450
+ sw.Write(b.ToString("X2") + " ");
451
+ }
452
+ }
453
+
454
+ return sw.ToString();
455
+ }
456
+
457
+ private sealed class AssemblyProvider : IAssemblyProvider
458
+ {
459
+ public Assembly Load(string assemblyName)
460
+ {
461
+ return Assembly.Load(assemblyName);
462
+ }
463
+
464
+ public Assembly[] GetAssemblies()
465
+ {
466
+ throw new NotImplementedException();
467
+ }
468
+ }
469
+ </script>