<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="TestFu Grammar" %> <%@ Property Name="Namespace" Type="System.String" Default="Populators" Category="Output" Description="Namespace of the populator." %> <%@ Property Name="DataSetNameFormat" Type="System.String" Default="{0}DataSet" Category="Output" Description="Format string to create the DatabaseSet class name." %> <%@ Property Name="CrudPopulatorNameFormat" Type="System.String" Default="{0}CrudPopulator" Category="Output" Description="Format string to create the CrudPopulator class name." %> <%@ Property Name="DatabasePopulatorNameFormat" Type="System.String" Default="{0}DatabasePopulator" Category="Output" Description="Format string to create the DatabasePopulator class name." %> <%@ Property Name="GrammarNameFormat" Type="System.String" Default="{0}Grammar" Category="Output" Description="Format string to create the Grammar class name." %> <%@ Property Name="TableNamePrefix" Type="System.String" Default="" Category="Output" Optional="true" Description="Prefix to be removed." %> <%@ 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 CRUD populator for the <%= DatabaseName %> // // This file was generated by CodeSmith. Do not edit it! Modify // the template if you need to tweak it for you. // ////////////////////////////////////////////////////////////////// using System; using System.Data; using System.Data.SqlClient; using MbUnit.Core.Framework; using MbUnit.Framework; using TestFu.Data; using TestFu.Data.SqlClient; using TestFu.Data.Graph; using TestFu.Grammars; namespace <%= Namespace %> { /// /// A strongly-typed for the /// <%= DatabaseName %> database. /// public class <%= DatabaseGrammarName %> : Grammar { #region Fields private <%= CrudPopulatorName%> populator; <% foreach(TableSchema table in this.Database.Tables) { %> private <%= TableGrammarName(table) %> <%= FormatLower(TableGrammarPropertyName(table)) %>; <%}// foreach(TableSchema table in this.Database.Tables) %> #endregion #region Constructors /// /// Initializes a new instance /// with a instance. /// public <%= DatabaseGrammarName %>(<%= CrudPopulatorName%> populator) { if (populator==null) throw new ArgumentNullException("populator"); this.populator = populator; AlternativeRule alt = new AlternativeRule(); <% foreach(TableSchema table in this.Database.Tables) { %> <%= FormatLower(TableGrammarPropertyName(table))%> = new <%= TableGrammarName(table) %>(populator); alt.Rules.Add(<%= FormatLower(TableGrammarPropertyName(table))%>); <%}// foreach(TableSchema table in this.Database.Tables) %> this.StartRule = Rules.Kleene(alt); } #endregion #region Grammars <% foreach(TableSchema table in this.Database.Tables) { %> <%= TableGrammarName(table) %> <%= TableGrammarPropertyName(table) %> { get { return <%= FormatLower(TableGrammarPropertyName(table)) %>;} } <% } // %> #endregion #region Grammars Classes <% foreach(TableSchema table in this.Database.Tables) { %> #region <%= table.Name %> public class <%= TableGrammarName(table) %> : Grammar { private <%= CrudPopulatorName%> populator; private IRule createRule; private IRule updateRule; private IRule deleteRule; public <%= TableGrammarName(table) %>(<%= CrudPopulatorName%> populator) { if (populator==null) throw new ArgumentNullException("populator"); this.populator = populator; this.CreateRules(); } public <%= CrudPopulatorName%> Populator { get { return this.populator;} } public IRule CreateRule { get { return this.createRule;} } public IRule UpdateRule { get { return this.updateRule;} } public IRule DeleteRule { get { return this.deleteRule;} } protected void CreateRules() { this.createRule = Rules.Method(new MethodInvoker(this.Create)); this.updateRule = Rules.Method(new MethodInvoker(this.Update)); this.deleteRule = Rules.Method(new MethodInvoker(this.Delete)); this.StartRule = Rules.Alt( this.createRule ,this.updateRule // ,this.deleteRule ); } private void Create() { DataRow row = this.populator.Create<%= Format(table.Name) %>(); Console.WriteLine("Created <%= Format(table.Name) %>"); } private void Delete() { this.populator.Delete<%= Format(table.Name) %>(); Console.WriteLine("Deleted <%= Format(table.Name) %>"); } private void Update() { this.populator.Update<%= Format(table.Name) %>(); Console.WriteLine("Updated <%= Format(table.Name) %>"); } } #endregion <%}// foreach(TableSchema table in this.Database.Tables) %> #endregion } }