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.
- data/docs/ASL - Apache Software Foundation License.txt +57 -0
- data/docs/MbUnit License.txt +14 -0
- data/docs/MbUnit.chm +0 -0
- data/docs/Release Notes.txt +7 -0
- data/docs/extras/CCNet/How to use MbUnit v2 with CruiseControl.Net.txt +88 -0
- data/docs/extras/CCNet/images/Category.png +0 -0
- data/docs/extras/CCNet/images/Fixture.png +0 -0
- data/docs/extras/CCNet/images/Populator.png +0 -0
- data/docs/extras/CCNet/images/Test.png +0 -0
- data/docs/extras/CCNet/xsl/MBUnitDetails.xsl +592 -0
- data/docs/extras/CCNet/xsl/MBUnitSummary.xsl +266 -0
- data/docs/extras/Snippets/AdjacencyGraph.cst +1703 -0
- data/docs/extras/Snippets/AssertWrapper.cst +181 -0
- data/docs/extras/Snippets/CrudPopulator.cst +377 -0
- data/docs/extras/Snippets/DatabasePopulator.cst +386 -0
- data/docs/extras/Snippets/DatabasePopulatorCrudTest.cst +177 -0
- data/docs/extras/Snippets/Exception.cst +94 -0
- data/docs/extras/Snippets/GrammarPopulator.cst +258 -0
- data/docs/extras/Snippets/MockObject.cst +296 -0
- data/docs/extras/Snippets/RapTierCrudPopulator.cst +444 -0
- data/docs/extras/Snippets/SimpleFixture.cst +91 -0
- data/docs/extras/Snippets/SqlppCrudPopulator.cst +443 -0
- data/docs/extras/Snippets/TestFixture.cst +469 -0
- data/docs/extras/Snippets/autorunner.snippet +45 -0
- data/docs/extras/Snippets/combinatorialtest.snippet +54 -0
- data/docs/extras/Snippets/datafixture.snippet +61 -0
- data/docs/extras/Snippets/model.snippet +95 -0
- data/docs/extras/Snippets/msbuild.snippet +40 -0
- data/docs/extras/Snippets/nant.snippet +34 -0
- data/docs/extras/Snippets/perfcounterassert.cst +173 -0
- data/docs/extras/Snippets/processtestfixture.snippet +75 -0
- data/docs/extras/Snippets/rowtest.snippet +113 -0
- data/docs/extras/Snippets/state.snippet +27 -0
- data/docs/extras/Snippets/submodel.snippet +32 -0
- data/docs/extras/Snippets/test.snippet +28 -0
- data/docs/extras/Snippets/testexpectedexception.snippet +32 -0
- data/docs/extras/Snippets/testfixture.snippet +68 -0
- data/docs/extras/Snippets/testsuitefixture.snippet +48 -0
- data/docs/extras/Snippets/typefixture.snippet +74 -0
- data/docs/extras/Snippets/typefixturewithproviderfactory.snippet +77 -0
- data/docs/extras/Snippets/usingmbunit.snippet +19 -0
- data/docs/extras/Templates/VS2005/ItemTemplates/CSharp/Test/MbUnit2.TestFixtureTemplate.CSharp.zip +0 -0
- data/docs/extras/Templates/VS2005/ItemTemplates/VisualBasic/Test/MbUnit2.TestFixtureTemplate.VisualBasic.zip +0 -0
- data/docs/extras/Templates/VS2005/ProjectTemplates/CSharp/Test/MbUnit2.TestProjectTemplate.CSharp.zip +0 -0
- data/docs/extras/Templates/VS2005/ProjectTemplates/VisualBasic/Test/MbUnit2.TestProjectTemplate.VisualBasic.zip +0 -0
- data/docs/extras/Templates/VS2008/ItemTemplates/CSharp/Test/MbUnit2.TestFixtureTemplate.CSharp.zip +0 -0
- data/docs/extras/Templates/VS2008/ItemTemplates/VisualBasic/Test/MbUnit2.TestFixtureTemplate.VisualBasic.zip +0 -0
- data/docs/extras/Templates/VS2008/ProjectTemplates/CSharp/Test/MbUnit2.MvcWebApplicationTestProjectTemplate.CSharp.zip +0 -0
- data/docs/extras/Templates/VS2008/ProjectTemplates/CSharp/Test/MbUnit2.TestProjectTemplate.CSharp.zip +0 -0
- data/docs/extras/Templates/VS2008/ProjectTemplates/VisualBasic/Test/MbUnit2.MvcWebApplicationTestProjectTemplate.VisualBasic.zip +0 -0
- data/docs/extras/Templates/VS2008/ProjectTemplates/VisualBasic/Test/MbUnit2.TestProjectTemplate.VisualBasic.zip +0 -0
- data/lib/MbUnit License.txt +14 -0
- data/lib/MbUnit.AddIn.dll +0 -0
- data/lib/MbUnit.Cons.exe +0 -0
- data/lib/MbUnit.Cons.exe.config +12 -0
- data/lib/MbUnit.Framework.2.0.dll +0 -0
- data/lib/MbUnit.Framework.2.0.pdb +0 -0
- data/lib/MbUnit.Framework.2.0.xml +278 -0
- data/lib/MbUnit.Framework.dll +0 -0
- data/lib/MbUnit.Framework.pdb +0 -0
- data/lib/MbUnit.Framework.xml +6929 -0
- data/lib/MbUnit.GUI.exe +0 -0
- data/lib/MbUnit.GUI.exe.config +14 -0
- data/lib/MbUnit.MSBuild.Tasks.dll +0 -0
- data/lib/MbUnit.Tasks.dll +0 -0
- data/lib/NGraphviz.Helpers.dll +0 -0
- data/lib/NGraphviz.Layout.dll +0 -0
- data/lib/NGraphviz.dll +0 -0
- data/lib/QuickGraph.Algorithms.Graphviz.dll +0 -0
- data/lib/QuickGraph.Algorithms.dll +0 -0
- data/lib/QuickGraph.Algorithms.pdb +0 -0
- data/lib/QuickGraph.Algorithms.xml +2818 -0
- data/lib/QuickGraph.dll +0 -0
- data/lib/QuickGraph.pdb +0 -0
- data/lib/QuickGraph.xml +3126 -0
- data/lib/Refly.dll +0 -0
- data/lib/Refly.pdb +0 -0
- data/lib/Refly.xml +1327 -0
- data/lib/TestFu.dll +0 -0
- data/lib/TestFu.pdb +0 -0
- data/lib/TestFu.xml +1932 -0
- data/lib/XsdTidy.exe +0 -0
- metadata +163 -0
@@ -0,0 +1,181 @@
|
|
1
|
+
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Assert Tester Wrapper" %>
|
2
|
+
<%@ Property Name="ClassName" Type="System.String" Category="Options" Description="Prefix of the class name, Assert will be appended." %>
|
3
|
+
<%@ Property Name="ClassNamespace" Type="System.String" Category="Options" Description="Namespace of the wrapped class" %>
|
4
|
+
<%@ Import Namespace="System.Reflection" %>
|
5
|
+
<%@ Import Namespace="System.Collections" %>
|
6
|
+
<%@ Assembly Name="AssemblyHelper"%>
|
7
|
+
<%@ Import Namespace="AssemblyHelper" %>
|
8
|
+
|
9
|
+
// MbUnit project.
|
10
|
+
// http://mbunit.tigris.org
|
11
|
+
|
12
|
+
using System;
|
13
|
+
using <%= ClassNamespace %>;
|
14
|
+
|
15
|
+
namespace MbUnit.Core.Framework
|
16
|
+
{
|
17
|
+
/// <summary>
|
18
|
+
/// Assertion helper for the <see cref="<%= ClassName %>"/> class.
|
19
|
+
/// </summary>
|
20
|
+
/// <remarks>
|
21
|
+
/// <para>
|
22
|
+
/// This class contains static helper methods to verify assertions on the
|
23
|
+
/// <see cref="<%= ClassName %>"/> class.
|
24
|
+
/// </para>
|
25
|
+
/// <para>
|
26
|
+
/// This class was automatically generated. Do not edit (or edit the template).
|
27
|
+
/// </para>
|
28
|
+
/// </remarks>
|
29
|
+
public sealed class <%= FullClassName %>
|
30
|
+
{
|
31
|
+
#region Private constructor
|
32
|
+
private <%= FullClassName %>()
|
33
|
+
{}
|
34
|
+
#endregion
|
35
|
+
|
36
|
+
<% foreach(PropertyInfo pi in this.ClassType.GetProperties())
|
37
|
+
{
|
38
|
+
if (pi.PropertyType == typeof(bool))
|
39
|
+
{%>
|
40
|
+
/// <summary>
|
41
|
+
/// Verifies that the property value <see cref="<%= FullPropertyName(pi) %>"/>
|
42
|
+
/// is true.
|
43
|
+
/// </summary>
|
44
|
+
/// <param name="actual"/>
|
45
|
+
/// Instance containing the expected value.
|
46
|
+
/// </param>
|
47
|
+
public static void <%= IsPropertyName(pi) %>(
|
48
|
+
<%= ClassName%> actual
|
49
|
+
)
|
50
|
+
{
|
51
|
+
<% CheckNonNull("actual");%>
|
52
|
+
Assert.IsTrue(actual.<%= pi.Name %>,
|
53
|
+
"Property <%= pi.Name %> is false");
|
54
|
+
}
|
55
|
+
|
56
|
+
/// <summary>
|
57
|
+
/// Verifies that the property value <see cref="<%= FullPropertyName(pi) %>"/>
|
58
|
+
/// is false.
|
59
|
+
/// </summary>
|
60
|
+
/// <param name="actual"/>
|
61
|
+
/// Instance containing the expected value.
|
62
|
+
/// </param>
|
63
|
+
public static void <%= IsNotPropertyName(pi) %>(
|
64
|
+
<%= ClassName%> actual
|
65
|
+
)
|
66
|
+
{
|
67
|
+
<% CheckNonNull("actual");%>
|
68
|
+
Assert.IsFalse(actual.<%= pi.Name %>,
|
69
|
+
"Property <%= pi.Name %> is true");
|
70
|
+
}
|
71
|
+
|
72
|
+
<%}
|
73
|
+
%>
|
74
|
+
|
75
|
+
/// <summary>
|
76
|
+
/// Verifies that the property value <see cref="<%= FullPropertyName(pi) %>"/>
|
77
|
+
/// of <paramref name="expected"/> and <paramref="actual"/> are equal.
|
78
|
+
/// </summary>
|
79
|
+
/// <param name="expected"/>
|
80
|
+
/// Instance containing the expected value.
|
81
|
+
/// </param>
|
82
|
+
/// <param name="actual"/>
|
83
|
+
/// Instance containing the tested value.
|
84
|
+
/// </param>
|
85
|
+
public static void <%= ArePropertyEqualName(pi) %>(
|
86
|
+
<%= ClassName%> expected,
|
87
|
+
<%= ClassName%> actual
|
88
|
+
)
|
89
|
+
{
|
90
|
+
<% CheckBothNull("expected","actual"); %>
|
91
|
+
<% CheckNonNull("expected");%>
|
92
|
+
<% CheckNonNull("actual");%>
|
93
|
+
<%= ArePropertyEqualName(pi)%>(expected.<%= pi.Name %>,actual);
|
94
|
+
}
|
95
|
+
|
96
|
+
/// <summary>
|
97
|
+
/// Verifies that the property value <see cref="<%= FullPropertyName(pi) %>"/>
|
98
|
+
/// of <paramref name="actual"/> is equal to <paramref="expected"/>.
|
99
|
+
/// </summary>
|
100
|
+
/// <param name="expected"/>
|
101
|
+
/// Expected value.
|
102
|
+
/// </param>
|
103
|
+
/// <param name="actual"/>
|
104
|
+
/// Instance containing the tested value.
|
105
|
+
/// </param>
|
106
|
+
public static void <%= ArePropertyEqualName(pi) %>(
|
107
|
+
<%= pi.PropertyType %> expected,
|
108
|
+
<%= ClassName%> actual
|
109
|
+
)
|
110
|
+
{
|
111
|
+
<% if (!pi.PropertyType.IsValueType)
|
112
|
+
CheckBothNull("expected","actual");
|
113
|
+
%>
|
114
|
+
<% CheckNonNull("actual");%>
|
115
|
+
Assert.AreEqual(expected,actual.<%= pi.Name %>,
|
116
|
+
"Property <%= pi.Name %> not equal");
|
117
|
+
}
|
118
|
+
<%}%>
|
119
|
+
}
|
120
|
+
}
|
121
|
+
<script runat="template">
|
122
|
+
private Assembly assembly;
|
123
|
+
|
124
|
+
[Editor(typeof(AssemblyHelper.AssemblyFilePicker), typeof(System.Drawing.Design.UITypeEditor))]
|
125
|
+
public Assembly AssemblyToLoad
|
126
|
+
{
|
127
|
+
get{return assembly;}
|
128
|
+
set{assembly = value;}
|
129
|
+
}
|
130
|
+
|
131
|
+
protected string FullClassName
|
132
|
+
{
|
133
|
+
get
|
134
|
+
{
|
135
|
+
return String.Format("{0}Assert",this.ClassName);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
protected string FullPropertyName(PropertyInfo pi)
|
139
|
+
{
|
140
|
+
return String.Format("{0}.{1}",this.ClassName,pi.Name);
|
141
|
+
}
|
142
|
+
protected string ArePropertyEqualName(PropertyInfo pi)
|
143
|
+
{
|
144
|
+
return String.Format("Are{0}Equal",pi.Name);
|
145
|
+
}
|
146
|
+
protected string IsPropertyName(PropertyInfo pi)
|
147
|
+
{
|
148
|
+
return pi.Name;
|
149
|
+
}
|
150
|
+
protected string IsNotPropertyName(PropertyInfo pi)
|
151
|
+
{
|
152
|
+
if (pi.Name.StartsWith("Is"))
|
153
|
+
{
|
154
|
+
return String.Format("IsNot{0}",
|
155
|
+
pi.Name.Substring(3,pi.Name.Length-3));
|
156
|
+
}
|
157
|
+
else
|
158
|
+
return String.Format("Not{0}",pi.Name);
|
159
|
+
}
|
160
|
+
|
161
|
+
protected Type ClassType
|
162
|
+
{
|
163
|
+
get
|
164
|
+
{
|
165
|
+
return this.AssemblyToLoad.GetType(String.Format("{0}.{1}",this.ClassNamespace, this.ClassName), true);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
protected void CheckNonNull(string name)
|
169
|
+
{
|
170
|
+
if (!this.ClassType.IsValueType)
|
171
|
+
Response.WriteLine(" Assert.IsNotNull({0});",name);
|
172
|
+
}
|
173
|
+
protected void CheckBothNull(string expected, string actual)
|
174
|
+
{
|
175
|
+
if (!this.ClassType.IsValueType)
|
176
|
+
{
|
177
|
+
Response.WriteLine(" if ({0}==null && {1}==null)",expected, actual);
|
178
|
+
Response.WriteLine(" return;");
|
179
|
+
}
|
180
|
+
}
|
181
|
+
</script>
|
@@ -0,0 +1,377 @@
|
|
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
|
+
Optional="true"
|
22
|
+
Description="Prefix to be removed." %>
|
23
|
+
<%@ Property Name="TablePopulatorNameFormat" Type="System.String"
|
24
|
+
Default="{0}TablePopulator"
|
25
|
+
Category="Output"
|
26
|
+
Description="Format string to create the TablePopulator class names." %>
|
27
|
+
<%@ Property Name="ColumnDataGeneratorNameFormat" Type="System.String"
|
28
|
+
Default="{0}DataGenerator"
|
29
|
+
Category="Output"
|
30
|
+
Description="Format string to create the ColumnGenenerator properties." %>
|
31
|
+
<%@ Property Name="UniqueValidatorNameFormat" Type="System.String"
|
32
|
+
Default="{0}Validator"
|
33
|
+
Category="Output"
|
34
|
+
Description="Format string to create the UniqueValidator properties." %>
|
35
|
+
<%@ Property Name="ForeignKeyProviderNameFormat" Type="System.String"
|
36
|
+
Default="{0}Provider"
|
37
|
+
Category="Output"
|
38
|
+
Description="Format string to create the ForeignKeyProviderNameFormat properties." %>
|
39
|
+
<%@ Property Name="Database" Type="SchemaExplorer.DatabaseSchema"
|
40
|
+
Category="Context"
|
41
|
+
Description="Target database for the IDatabasePopulator." %>
|
42
|
+
<%@ Assembly Name="SchemaExplorer" %>
|
43
|
+
<%@ Import Namespace="SchemaExplorer" %>
|
44
|
+
//////////////////////////////////////////////////////////////////
|
45
|
+
//
|
46
|
+
// Strongly typed CRUD populator for the <%= DatabaseName %>
|
47
|
+
//
|
48
|
+
// This file was generated by CodeSmith. Do not edit it! Modify
|
49
|
+
// the template if you need to tweak it for you.
|
50
|
+
//
|
51
|
+
//////////////////////////////////////////////////////////////////
|
52
|
+
|
53
|
+
using System;
|
54
|
+
using System.Data;
|
55
|
+
using System.Data.SqlClient;
|
56
|
+
using System.Data.SqlTypes;
|
57
|
+
|
58
|
+
using MbUnit.Core.Framework;
|
59
|
+
using MbUnit.Framework;
|
60
|
+
|
61
|
+
using TestFu.Data;
|
62
|
+
using TestFu.Data.SqlClient;
|
63
|
+
using TestFu.Data.Graph;
|
64
|
+
|
65
|
+
namespace <%= Namespace %>
|
66
|
+
{
|
67
|
+
/// <summary>
|
68
|
+
/// A CRUD harness for the <%= DatabaseName %> database.
|
69
|
+
/// </summary>
|
70
|
+
/// <remarks>
|
71
|
+
/// <para><b>Note to implementors:</b></para>
|
72
|
+
/// <para>
|
73
|
+
/// Implementors should modify the CodeSmith template that generated
|
74
|
+
/// this class to inject their Create,Update,Read and Delete methods.
|
75
|
+
/// Each generated method contains a <see cref="NotImplementedException"/>
|
76
|
+
/// that should be replaced with the proper DAL code.
|
77
|
+
/// </para>
|
78
|
+
/// <para>
|
79
|
+
/// The <c>Create*</c> methods create a new row and verify that it is
|
80
|
+
/// present in the database using the <c>Read*</c> methods.
|
81
|
+
/// The <c>Update*</c> methods apply an update between two rows and
|
82
|
+
/// verify that the update was succesful using <c>Read*</c> methods.
|
83
|
+
/// The <c>Delete*</c> remove a row from the tables and verify
|
84
|
+
/// that it has been removed using <c>Read*</c> methods.
|
85
|
+
/// </para>
|
86
|
+
/// <remarks>
|
87
|
+
public class <%= CrudPopulatorName %> : <%= DatabasePopulatorName %>
|
88
|
+
{
|
89
|
+
#region Constructors
|
90
|
+
/// <summary>
|
91
|
+
/// Initializes a new <see cref="<%= CrudPopulatorName %>"/> with the
|
92
|
+
/// connection string of the database.
|
93
|
+
/// </summary>
|
94
|
+
/// <param name="connectionString">
|
95
|
+
/// A valid conneciton string to the target database.
|
96
|
+
/// </param>
|
97
|
+
/// <exception type="ArgumentNullException">
|
98
|
+
/// The <paramref name="connectionString"/> is a
|
99
|
+
/// null reference (Nothing in Visual Basic).
|
100
|
+
/// </exception>
|
101
|
+
/// <exception type="ArgumentException">
|
102
|
+
/// The <paramref name="connectionString"/> is empty.
|
103
|
+
/// </exception>
|
104
|
+
public <%= CrudPopulatorName %>(string connectionString)
|
105
|
+
:this(new <%= DataSetName %>(), connectionString)
|
106
|
+
{}
|
107
|
+
|
108
|
+
/// <summary>
|
109
|
+
/// Initializes a new <see cref="<%= CrudPopulatorName %>"/> with the
|
110
|
+
/// connection string of the database.
|
111
|
+
/// </summary>
|
112
|
+
/// <param name="dataSet">
|
113
|
+
/// A <see cref="DataSet"/> representing the structure of the
|
114
|
+
/// <em><%= DatabaseName %></em> database.
|
115
|
+
/// </param>
|
116
|
+
/// <param name="connectionString">
|
117
|
+
/// A valid conneciton string to the target database.
|
118
|
+
/// </param>
|
119
|
+
/// <exception type="ArgumentNullException">
|
120
|
+
/// The <paramref name="dataSet"/> or the <paramref name="connectionString"/> is a
|
121
|
+
/// null reference (Nothing in Visual Basic).
|
122
|
+
/// </exception>
|
123
|
+
/// <exception type="ArgumentException">
|
124
|
+
/// The <paramref name="connectionString"/> is empty.
|
125
|
+
/// </exception>
|
126
|
+
public <%= CrudPopulatorName %>(
|
127
|
+
DataSet dataSet,
|
128
|
+
string connectionString
|
129
|
+
)
|
130
|
+
:base(dataSet,connectionString)
|
131
|
+
{}
|
132
|
+
#endregion
|
133
|
+
|
134
|
+
<% foreach(TableSchema table in this.Database.Tables) {%>
|
135
|
+
#region <%= table.Name %>
|
136
|
+
/// <summary>
|
137
|
+
/// Creates a new <see cref="DataRow"/> in the
|
138
|
+
/// <em><%= table.Name %> table.
|
139
|
+
/// </summary>
|
140
|
+
/// <returns>
|
141
|
+
/// The created <see cref="DataRow"/> instance
|
142
|
+
/// </returns>
|
143
|
+
public virtual DataRow Create<%= Format(table.Name) %>()
|
144
|
+
{
|
145
|
+
// generate row
|
146
|
+
DataRow row = this.<%=GetTablePopulatorPropertyName(table)%>.Generate();
|
147
|
+
// extract info
|
148
|
+
<% foreach(ColumnSchema column in table.Columns) {%>
|
149
|
+
Sql<%= column.SystemType.Name %> <%= FormatLower(column.Name) %> = (Sql<%= column.SystemType.Name %>)row["<%= column.Name%>"];
|
150
|
+
<% } // foreach(ColumnSchema column in table.Columns) %>
|
151
|
+
|
152
|
+
// TODO: add the row to the <%= table.Name %> table here
|
153
|
+
throw new NotImplementedException();
|
154
|
+
|
155
|
+
// check Create has been successfull
|
156
|
+
DataRow readRow = Read<%= Format(table.Name)%>(row);
|
157
|
+
if (readRow==null)
|
158
|
+
{
|
159
|
+
DisplayRow(row);
|
160
|
+
Assert.Fail("Row creation failed");
|
161
|
+
}
|
162
|
+
|
163
|
+
return row;
|
164
|
+
}
|
165
|
+
|
166
|
+
/// <summary>
|
167
|
+
/// Updates a row (chosen randomly) with a new generated row in the
|
168
|
+
/// <em><%= table.Name %> table.
|
169
|
+
/// </summary>
|
170
|
+
/// <returns>
|
171
|
+
/// The update <see cref="DataRow"/> instance
|
172
|
+
/// </returns>
|
173
|
+
public virtual DataRow Update<%= Format(table.Name) %>()
|
174
|
+
{
|
175
|
+
// generate row
|
176
|
+
DataRow row = this.<%=GetTablePopulatorPropertyName(table)%>.Generate();
|
177
|
+
// update random
|
178
|
+
return Update<%= Format(table.Name) %>(row);
|
179
|
+
}
|
180
|
+
|
181
|
+
/// <summary>
|
182
|
+
/// Updates a row (chosen randomly) with a <see cref="DataRow"/> in the
|
183
|
+
/// <em><%= table.Name %> table.
|
184
|
+
/// </summary>
|
185
|
+
/// <returns>
|
186
|
+
/// The update <see cref="DataRow"/> instance
|
187
|
+
/// </returns>
|
188
|
+
public virtual DataRow Update<%= Format(table.Name) %>(DataRow row)
|
189
|
+
{
|
190
|
+
if (row==null)
|
191
|
+
throw new ArgumentNullException("row");
|
192
|
+
// choose a row
|
193
|
+
DataRow rowToUpdate = this.<%=GetTablePopulatorPropertyName(table)%>.GetRandomRow();
|
194
|
+
return Update<%= Format(table.Name) %>(row, rowToUpdate);
|
195
|
+
}
|
196
|
+
|
197
|
+
/// <summary>
|
198
|
+
/// Updates <paramref name="row"/> with <paramref name="rowToUpdate"/> in the
|
199
|
+
/// <em><%= table.Name %> table.
|
200
|
+
/// </summary>
|
201
|
+
/// <returns>
|
202
|
+
/// The update <see cref="DataRow"/> instance
|
203
|
+
/// </returns>
|
204
|
+
public virtual DataRow Update<%= Format(table.Name) %>(DataRow row, DataRow rowToUpdate)
|
205
|
+
{
|
206
|
+
if (row==null)
|
207
|
+
throw new ArgumentNullException("row");
|
208
|
+
if (rowToUpdate==null)
|
209
|
+
throw new ArgumentNullException("rowToUpdate");
|
210
|
+
// extract info
|
211
|
+
<% foreach(ColumnSchema column in table.Columns) {%>
|
212
|
+
<%= column.SystemType %> <%= FormatLower(column.Name) %> = (<%= column.SystemType %>)row["<%= column.Name%>"];
|
213
|
+
<% } // foreach(ColumnSchema column in table.Columns) %>
|
214
|
+
|
215
|
+
// TODO: update the rowToUpdate with row in the <%= table.Name %> table
|
216
|
+
throw new NotImplementedException();
|
217
|
+
|
218
|
+
// check Update has been successfull
|
219
|
+
DataRow readRow = Read<%= Format(table.Name)%>(rowToUpdate);
|
220
|
+
if (readRow==null)
|
221
|
+
{
|
222
|
+
Console.WriteLine("New row:");
|
223
|
+
DisplayRow(row);
|
224
|
+
Console.WriteLine("Row to update:");
|
225
|
+
DisplayRow(rowToUpdate);
|
226
|
+
Assert.Fail("Row update failed");
|
227
|
+
}
|
228
|
+
|
229
|
+
return rowToUpdate;
|
230
|
+
}
|
231
|
+
|
232
|
+
/// <summary>
|
233
|
+
/// Deletes a random row
|
234
|
+
/// from the <em><%= table.Name %></em> table.
|
235
|
+
/// </summary>
|
236
|
+
public virtual void Delete<%= Format(table.Name) %>()
|
237
|
+
{
|
238
|
+
// choose a row
|
239
|
+
DataRow row = this.<%=GetTablePopulatorPropertyName(table)%>.GetRandomRow();
|
240
|
+
|
241
|
+
// delete
|
242
|
+
this.Delete<%= Format(table.Name) %>(row);
|
243
|
+
}
|
244
|
+
|
245
|
+
/// <summary>
|
246
|
+
/// Deletes the row
|
247
|
+
/// from the <em><%= table.Name %></em> table.
|
248
|
+
/// </summary>
|
249
|
+
public virtual void Delete<%= Format(table.Name) %>(DataRow row)
|
250
|
+
{
|
251
|
+
if (row==null)
|
252
|
+
throw new ArgumentNullException("row");
|
253
|
+
// extract info
|
254
|
+
<% foreach(ColumnSchema column in table.Columns) {%>
|
255
|
+
<%= column.SystemType %> <%= FormatLower(column.Name) %> = (<%= column.SystemType %>)row["<%= column.Name%>"];
|
256
|
+
<% } // foreach(ColumnSchema column in table.Columns) %>
|
257
|
+
|
258
|
+
// TODO: delete the row from the <%= table.Name %> table
|
259
|
+
throw new NotImplementedException();
|
260
|
+
|
261
|
+
// check it is not in the table
|
262
|
+
DataRow readRow = Read<%= Format(table.Name) %>(row);
|
263
|
+
if (readRow!=null)
|
264
|
+
{
|
265
|
+
Console.WriteLine("Row to delete");
|
266
|
+
DisplayRow(row);
|
267
|
+
Console.WriteLine("Not deleted row");
|
268
|
+
DisplayRow(readRow);
|
269
|
+
Assert.Fail("Row delete failed");
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
/// <summary>
|
274
|
+
/// Reads the <em><%= table.Name %></em> table for a row matching <paramref name="row"/>
|
275
|
+
/// and returns it.
|
276
|
+
/// </summary>
|
277
|
+
/// <returns>
|
278
|
+
/// Read <see cref="DataRow"/> row if foud; otherwize
|
279
|
+
/// a null reference.
|
280
|
+
/// </returns>
|
281
|
+
public virtual DataRow Read<%= Format(table.Name) %>(DataRow row)
|
282
|
+
{
|
283
|
+
if (row==null)
|
284
|
+
throw new ArgumentNullException("row");
|
285
|
+
|
286
|
+
// extract info
|
287
|
+
<% foreach(ColumnSchema column in table.Columns) {%>
|
288
|
+
<%= column.SystemType %> <%= FormatLower(column.Name) %> = (<%= column.SystemType %>)row["<%= column.Name%>"];
|
289
|
+
<% } // foreach(ColumnSchema column in table.Columns) %>
|
290
|
+
|
291
|
+
// TODO: read the data from the db and return the row,
|
292
|
+
// if not found, return null
|
293
|
+
throw new NotImplementedException();
|
294
|
+
}
|
295
|
+
#endregion
|
296
|
+
|
297
|
+
<%} // foreach(TableSchema table in this.Database.Tables) %>
|
298
|
+
|
299
|
+
|
300
|
+
protected virtual void DisplayRow(DataRow row)
|
301
|
+
{
|
302
|
+
if (row==null)
|
303
|
+
throw new ArgumentNullException("row");
|
304
|
+
foreach(DataColumn column in row.Table.Columns)
|
305
|
+
{
|
306
|
+
Console.WriteLine("\t{0}: {1}",
|
307
|
+
column.ColumnName,
|
308
|
+
row[column].ToString());
|
309
|
+
}
|
310
|
+
}
|
311
|
+
}
|
312
|
+
}
|
313
|
+
<script runat="template">
|
314
|
+
#region Properties
|
315
|
+
public string DatabaseName
|
316
|
+
{
|
317
|
+
get
|
318
|
+
{
|
319
|
+
return this.Database.Name;
|
320
|
+
}
|
321
|
+
}
|
322
|
+
public string ToSqlType(ColumnSchema column)
|
323
|
+
{
|
324
|
+
return String.Format("Sql{0}",column.SystemType.Name);
|
325
|
+
}
|
326
|
+
public string DataSetName
|
327
|
+
{
|
328
|
+
get{ return Format(this.DataSetNameFormat, this.DatabaseName);}
|
329
|
+
}
|
330
|
+
public string CrudPopulatorName
|
331
|
+
{
|
332
|
+
get{ return Format(this.CrudPopulatorNameFormat,this.DatabaseName);}
|
333
|
+
}
|
334
|
+
public string DatabasePopulatorName
|
335
|
+
{
|
336
|
+
get{ return Format(this.DatabasePopulatorNameFormat,this.DatabaseName);}
|
337
|
+
}
|
338
|
+
public string GetTablePopulatorName(TableSchema table)
|
339
|
+
{
|
340
|
+
return Format(this.TablePopulatorNameFormat, table.Name);
|
341
|
+
}
|
342
|
+
public string GetTablePopulatorPropertyName(TableSchema table)
|
343
|
+
{
|
344
|
+
return Format(table.Name);
|
345
|
+
}
|
346
|
+
public string GetColumnDataGeneratorName(ColumnSchema column)
|
347
|
+
{
|
348
|
+
return Format(ColumnDataGeneratorNameFormat, column.Name);
|
349
|
+
}
|
350
|
+
public string GetUniqueValidatorName(TableKeySchema unique)
|
351
|
+
{
|
352
|
+
return Format(UniqueValidatorNameFormat, unique.Name);
|
353
|
+
}
|
354
|
+
public string GetForeignKeyProviderName(TableKeySchema unique)
|
355
|
+
{
|
356
|
+
return Format(ForeignKeyProviderNameFormat, unique.Name);
|
357
|
+
}
|
358
|
+
protected string FormatLower(string format, params object[] args)
|
359
|
+
{
|
360
|
+
string s= Format(format,args);
|
361
|
+
return Char.ToLower(s[0]) + s.Substring(1);
|
362
|
+
}
|
363
|
+
protected string Format(string format, params Object[] args)
|
364
|
+
{
|
365
|
+
string result = string.Format(format,args);
|
366
|
+
if (this.TableNamePrefix!=null && this.TableNamePrefix.Length > 0)
|
367
|
+
{
|
368
|
+
if (result.StartsWith(this.TableNamePrefix))
|
369
|
+
result = result.Substring(this.TableNamePrefix.Length);
|
370
|
+
}
|
371
|
+
|
372
|
+
result = result.Replace(" ","").Replace("_","").Replace(".","");
|
373
|
+
return result;
|
374
|
+
}
|
375
|
+
|
376
|
+
#endregion
|
377
|
+
</script>
|