public void ShouldGenerateMappingForSqlServerTable()
 {
     const string generatedXML = "<?xml version=\"1.0\"?><hibernate-mapping assembly=\"myAssemblyName\" xmlns=\"urn:nhibernate-mapping-2.2\"><class name=\"myNameSpace.Customer, myAssemblyName\" table=\"Customer\" lazy=\"true\" xmlns=\"\" /></hibernate-mapping>";
     var preferences = new ApplicationPreferences
                           {
                               FolderPath = "\\",
                               TableName = "Customer",
                               AssemblyName = "myAssemblyName",
                               NameSpace = "myNameSpace",
                               Sequence = "mySequenceNumber",
                           };
     var generator = new SqlMappingGenerator(preferences, new ColumnDetails());
     var document = generator.CreateMappingDocument();
     Assert.AreEqual(generatedXML, document.InnerXml);
 }
        public static ApplicationPreferences Default()
        {
            var preferences = new ApplicationPreferences
            {
                FieldGenerationConvention = FieldGenerationConvention.AutoProperty,
                FieldNamingConvention     = FieldNamingConvention.SameAsDatabase,
                Prefix     = string.Empty,
                IsNhFluent = true,
                Language   = Language.CSharp,
                ForeignEntityCollectionType = "IList",
                InheritenceAndInterfaces    = "",
                UseLazy = true
            };

            return(preferences);
        }
 public void ShouldGenerateMappingForOracleTable()
 {
     const string generatedXML = "<?xml version=\"1.0\"?><hibernate-mapping assembly=\"myAssemblyName\" namespace=\"myNameSpace\" xmlns=\"urn:nhibernate-mapping-2.2\"><class name=\"Customer\" table=\"Customer\" lazy=\"true\" xmlns=\"\"><id name=\"Id\" column=\"Id\" /></class></hibernate-mapping>";
     var preferences = new ApplicationPreferences
                           {
                               FolderPath = "\\",
                               TableName = "Customer",
                               AssemblyName = "myAssemblyName",
                               NameSpace = "myNameSpace",
                               Sequence = "mySequenceNumber",
                           };
     var pkColumn = new Column {Name = "Id", IsPrimaryKey = true, DataType = "Int"};
     var primaryKey = new PrimaryKey {Columns = new List<Column> {pkColumn}};
     var generator = new OracleMappingGenerator(preferences, new Table {PrimaryKey = primaryKey, Columns = new List<Column> {pkColumn}});
     var document = generator.CreateMappingDocument();
     Assert.AreEqual(generatedXML, document.InnerXml);
 }
Example #4
0
 public ApplicationController(ApplicationPreferences applicationPreferences, Table table)
 {
     this.applicationPreferences = applicationPreferences;
     codeGenerator = new CodeGenerator(applicationPreferences, table);
     fluentGenerator = new FluentGenerator(applicationPreferences, table);
     castleGenerator = new CastleGenerator(applicationPreferences, table);
     contractGenerator = new ContractGenerator(applicationPreferences, table);
     byCodeGenerator = new ByCodeGenerator(applicationPreferences, table);
     if (applicationPreferences.ServerType == ServerType.Oracle)
     {
         mappingGenerator = new OracleMappingGenerator(applicationPreferences, table);
     }
     else
     {
         mappingGenerator = new SqlMappingGenerator(applicationPreferences, table);
     }
 }
Example #5
0
 public void ShouldCreateCompleteCompileUnit()
 {
     var applicationPreferences = new ApplicationPreferences
                                      {
                                          NameSpace = "someNamespace",
                                          TableName = "someTableName"
                                      };
     var codeGenerator = new CodeGenerator(applicationPreferences, new ColumnDetails());
     CodeCompileUnit pkClass;
     var codeCompileUnit = codeGenerator.GetCompileUnit(out pkClass);
     var cSharpCodeProvider = new CSharpCodeProvider();
     var stringBuilder = new StringBuilder();
     cSharpCodeProvider.GenerateCodeFromCompileUnit(codeCompileUnit, new StringWriter(stringBuilder), new CodeGeneratorOptions());
     Assert.IsTrue(stringBuilder.ToString().Contains("namespace someNamespace"));
     Assert.IsTrue(stringBuilder.ToString().Contains("public class someTableName"));
     Assert.IsTrue(stringBuilder.ToString().Contains("public someTableName()"));
 }
Example #6
0
 public void ShouldCreateCompleteCompileUnit()
 {
     var applicationPreferences = new ApplicationPreferences
                                      {
                                          NameSpace = "someNamespace",
                                          TableName = "someTableName"
                                      };
     //var codeGenerator = new CodeGenerator(applicationPreferences, new ColumnDetails());
     //var codeCompileUnit = codeGenerator.GetCompileUnit();
     //var cSharpCodeProvider = new CSharpCodeProvider();
     //var stringBuilder = new StringBuilder();
     //cSharpCodeProvider.GenerateCodeFromCompileUnit(codeCompileUnit, new StringWriter(stringBuilder), new CodeGeneratorOptions());
     //// TODO: Put each assert in its own function. Since if one of the asserts fails, they all fail.
     //// Thus, harder to find what the bug is.
     //Assert.IsTrue(stringBuilder.ToString().Contains("namespace someNamespace"), "namespace failed" + stringBuilder.ToString());
     //Assert.IsTrue(stringBuilder.ToString().Contains("public class Sometablename"), "public class failed" + stringBuilder.ToString());
     //Assert.IsTrue(stringBuilder.ToString().Contains("public Sometablename()"), "public failed" + stringBuilder.ToString());
 }
Example #7
0
        private ApplicationPreferences GetApplicationPreferences(Table tableName, bool all, ApplicationSettings appSettings)
        {
            string sequence = string.Empty;
            object sequenceName = null;
            if (sequencesComboBox.InvokeRequired)
            {
                sequencesComboBox.Invoke(new MethodInvoker(delegate {
                    sequenceName = sequencesComboBox.SelectedItem; }));
            }
            else
            {
                sequenceName = sequencesComboBox.SelectedItem;
            }
            if (sequenceName != null && !all)
            {
                sequence = sequenceName.ToString();
            }

            var folderPath = AddSlashToFolderPath(folderTextBox.Text);
            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }
            var domainFolderPath = AddSlashToFolderPath(domainFolderTextBox.Text);
            if (appSettings.GenerateInFolders)
            {
                Directory.CreateDirectory(folderPath + "Contract");
                Directory.CreateDirectory(folderPath + "Domain");
                Directory.CreateDirectory(folderPath + "Mapping");
                domainFolderPath = folderPath;
            }
            else
            {
                // Domain folder is specified by user
                if (!Directory.Exists(domainFolderPath))
                {
                    Directory.CreateDirectory(domainFolderPath);
                }
            }

            var applicationPreferences = new ApplicationPreferences
                                             {
                                                 ServerType = _currentConnection.Type,
                                                 FolderPath = folderPath,
                                                 DomainFolderPath = domainFolderPath,
                                                 TableName = tableName.Name,
                                                 NameSpaceMap = namespaceMapTextBox.Text,
                                                 NameSpace = nameSpaceTextBox.Text,
                                                 AssemblyName = assemblyNameTextBox.Text,
                                                 Sequence = sequence,
                                                 Language = LanguageSelected,
                                                 FieldNamingConvention = GetFieldNamingConvention(),
                                                 FieldGenerationConvention = GetFieldGenerationConvention(),
                                                 Prefix = prefixTextBox.Text,
                                                 IsFluent = IsFluent,
                                                 IsEntityFramework = IsEntityFramework,
                                                 IsCastle = IsCastle,
                                                 GeneratePartialClasses = appSettings.GeneratePartialClasses,
                                                 GenerateWcfDataContract = appSettings.GenerateWcfContracts,
                                                 ConnectionString = _currentConnection.ConnectionString,
                                                 ForeignEntityCollectionType = appSettings.ForeignEntityCollectionType,
                                                 InheritenceAndInterfaces = appSettings.InheritenceAndInterfaces,
                                                 GenerateInFolders = appSettings.GenerateInFolders,
                                                 ClassNamePrefix = appSettings.ClassNamePrefix,
                                                 EnableInflections = appSettings.EnableInflections,
                                                 IsByCode = appSettings.IsByCode,
                                                 UseLazy = appSettings.UseLazy,
                                                 FieldPrefixRemovalList = appSettings.FieldPrefixRemovalList,
                                                 IncludeForeignKeys = appSettings.IncludeForeignKeys,
                                                 NameFkAsForeignTable = appSettings.NameFkAsForeignTable,
                                                 IncludeHasMany = appSettings.IncludeHasMany,
                                                 IncludeLengthAndScale = appSettings.IncludeLengthAndScale,
                                                 ValidatorStyle = appSettings.ValidationStyle
                                             };

            return applicationPreferences;
        }
Example #8
0
 public static ApplicationPreferences Default()
 {
     var preferences = new ApplicationPreferences
                           {
                               FieldGenerationConvention = FieldGenerationConvention.AutoProperty,
                               FieldNamingConvention = FieldNamingConvention.SameAsDatabase,
                               Prefix = string.Empty,
                               IsNhFluent = true,
                               Language = Language.CSharp,
                               ForeignEntityCollectionType = "IList",
                               InheritenceAndInterfaces = "",
                               UseLazy = true
                           };
     return preferences;
 }
Example #9
0
        private ApplicationPreferences GetApplicationPreferences(string tableName)
        {
            var sequence = string.Empty;
            if (sequencesComboBox.SelectedItem != null)
            {
                sequence = sequencesComboBox.SelectedItem.ToString();
            }

            var applicationPreferences = new ApplicationPreferences
                                             {
                                                 ServerType = (ServerType)serverTypeComboBox.SelectedItem,
                                                 FolderPath = folderTextBox.Text,
                                                 TableName = tableName,
                                                 NameSpace = nameSpaceTextBox.Text,
                                                 AssemblyName = assemblyNameTextBox.Text,
                                                 Sequence = sequence,
                                                 Language = LanguageSelected,
                                                 FieldNamingConvention = GetFieldNamingConvention(),
                                                 FieldGenerationConvention = GetFieldGenerationConvention(),
                                                 Prefix = prefixTextBox.Text
                                             };

            if(sequenceRadio.Checked)
            {
                applicationPreferences.PrimaryKeyType = PrimaryKeyType.Sequence;
            }
            else
            {
                applicationPreferences.PrimaryKeyType = PrimaryKeyType.Assigned;
            }

            return applicationPreferences;
        }