<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="TestFu DatabasePopulator Template" %> <%@ Property Name="Namespace" Type="System.String" Default="Populators" Category="Output" Description="Namespace of the populator." %> <%@ Property Name="TestFixtureFormatName" Type="System.String" Default="{0}CrudTest" Category="Output" Description="Format string of the fixture" %> <%@ Property Name="DataSetNameFormat" Type="System.String" Default="{0}DataSet" Category="Output" Description="Format string to create the DatabaseSet class name." %> <%@ Property Name="DatabasePopulatorNameFormat" Type="System.String" Default="{0}DatabasePopulator" Category="Output" Description="Format string to create the DatabasePopulator class name." %> <%@ Property Name="CrudPopulatorNameFormat" Type="System.String" Default="{0}CrudPopulator" Category="Output" Description="Format string to create the CrudPopulator class name." %> <%@ Property Name="TableNamePrefix" Type="System.String" Default="" Category="Output" Optional="true" Description="Prefix to be removed." %> <%@ Property Name="RollBack" Type="System.Boolean" Default="false" Category="Output" Description="True if Rollback attribute is used." %> <%@ Property Name="TablePopulatorNameFormat" Type="System.String" Default="{0}TablePopulator" Category="Output" Description="Format string to create the TablePopulator class names." %> <%@ Property Name="ColumnDataGeneratorNameFormat" Type="System.String" Default="{0}DataGenerator" Category="Output" Description="Format string to create the ColumnGenenerator properties." %> <%@ Property Name="UniqueValidatorNameFormat" Type="System.String" Default="{0}Validator" Category="Output" Description="Format string to create the UniqueValidator properties." %> <%@ Property Name="ForeignKeyProviderNameFormat" Type="System.String" Default="{0}Provider" Category="Output" Description="Format string to create the ForeignKeyProviderNameFormat properties." %> <%@ Property Name="Database" Type="SchemaExplorer.DatabaseSchema" Category="Context" Description="Target database for the IDatabasePopulator." %> <%@ Assembly Name="SchemaExplorer" %> <%@ Import Namespace="SchemaExplorer" %> ////////////////////////////////////////////////////////////////// // // Strongly typed populator for the <%= DatabaseName %> // ////////////////////////////////////////////////////////////////// using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using MbUnit.Core.Framework; using MbUnit.Framework; using TestFu.Data; using TestFu.Data.Populators; using TestFu.Data.SqlClient; namespace <%= Namespace %> { [TestFixture] public class <%= String.Format(this.TestFixtureFormatName, Format(DatabaseName)) %> { private string connectionString; private <%= CrudPopulatorName %> populator; [TestFixtureSetUp] public void TestFixtureSetUp() { this.connectionString = ConfigurationSettings.AppSettings["connString"]; this.populator = new <%= CrudPopulatorName %>(connectionString); } <% foreach(TableSchema table in this.Database.Tables) {%> [Test<%= AddRollBack() %>] public void Create<%= Format(table.Name) %>() { this.populator.Create<%= Format(table.Name) %>(); } [Test<%= AddRollBack() %>] public void CreateAndDelete<%= Format(table.Name) %>() { DataRow row = this.populator.Create<%= Format(table.Name) %>(); this.populator.Delete<%= Format(table.Name) %>(row); } <% if (table.PrimaryKey.MemberColumns.Count != table.Columns.Count ) {%> [Test<%= AddRollBack() %>] public void CreateAndUpdate<%= Format(table.Name) %>() { DataRow row = this.populator.Create<%= Format(table.Name) %>(); this.populator.Update<%= Format(table.Name) %>(); } <% } %> <%} // foreach(TableSchema table in this.Database.Tables) %> } }