Example #1
0
        public void ShouldReturnExpectedResult()
        {
            var templateContent = GetExpectedTemplateContent("Dao.dbtemplate");
            var databaseModel   = persistanceFacade.GetDatabaseModelByPersistenceName("OnlyEmployeePayHistorySqlServerDatabaseModel");

            IDatabaseTemplateHandlerInputModel input = new DatabaseTemplateHandlerInputModel()
            {
                DatabaseModel  = databaseModel,
                TemplateModels = new List <ITemplateModel>()
                {
                    new TemplateModel()
                    {
                        TemplatedFilePath    = $"{_tested.TableFilePathTemplateWord}Dao.cs",
                        TemplatedFileContent = templateContent,
                    },
                },
                typeMappings = new List <ITypeMapping>(),
            };

            var result = _tested.Process(input);

            Assert.IsNotNull(result);
            CollectionAssert.IsNotEmpty(result);
            Assert.AreEqual(1, result.Count);
            var expected = GetExpectedResultContent("EmployeePayHistoryDao.cs.expected");
            var actual   = result.First().Content;

            Assert.AreEqual(expected, actual);
        }
        public void ShouldReturnDatabaseNameAndTableName()
        {
            var templateHandlerNew = TemplateHandlerBuilder.Build(null);
            DatabaseNameDatabaseContextHandler databaseNameDatabaseContextHandler = new DatabaseNameDatabaseContextHandler(templateHandlerNew);
            TableNameTableContextHandler       tableNameTableContextHandler       = new TableNameTableContextHandler(templateHandlerNew);
            string databaseName = "DatabaseName";
            string tableName    = "TableName";
            DatabaseTemplateHandlerInputModel input = new DatabaseTemplateHandlerInputModel()
            {
                TemplateModels = new List <ITemplateModel>
                {
                    new TemplateModel()
                    {
                        TemplatedFilePath    = $"{_tested.DatabaseFilePathTemplateWord}-{_tested.TableFilePathTemplateWord}",
                        TemplatedFileContent = $"{databaseNameDatabaseContextHandler.Signature}-{tableNameTableContextHandler.Signature}",
                    }
                },
                DatabaseModel = new DatabaseModel()
                {
                    Name   = databaseName,
                    Tables = new List <ITableModel>()
                    {
                        new TableModel()
                        {
                            Name    = tableName,
                            Columns = new List <IColumnModel>(),
                        }
                    },
                }
            };

            var result = _tested.Process(input);

            Assert.IsNotNull(result);
            CollectionAssert.IsNotEmpty(result);
            Assert.AreEqual(1, result.Count);
            var resultItem = result.First();

            Assert.IsNotNull(resultItem);
            Assert.AreEqual($"{databaseName}-{tableName}", resultItem.Path);
            Assert.AreEqual($"{databaseName}-{tableName}", resultItem.Content);
        }
Example #3
0
        public void Test()
        {
            var templateContent = @"{:TDB:PREPROCESSOR:MAPPING:DECLARE(([->(C#)<-]<=>[[->(hierarchyid)<-]=>[->(Microsoft.SqlServer.Types.SqlHierarchyId)<-],
[->(smallint)<-]=>[->(short)<-],
[->(date)<-]=>[->(DateTime)<-],
[->(geography)<-]=>[->(Microsoft.SqlServer.Types.SqlGeography)<-],
[->(xml)<-]=>[->(System.Xml.XmlDocument)<-],
[->(varchar)<-]=>[->(string)<-],
[->(varbinary)<-]=>[->(byte[])<-],
[->(uniqueidentifier)<-]=>[->(Guid)<-],
[->(tinyint)<-]=>[->(byte)<-],
[->(timestamp)<-]=>[->(byte)<-],
[->(time)<-]=>[->(TimeSpan)<-],
[->(sql_variant)<-]=>[->(object)<-],
[->(smallmoney)<-]=>[->(decimal)<-],
[->(smalldatetime)<-]=>[->(DateTime)<-],
[->(rowversion)<-]=>[->(byte[])<-],
[->(nvarchar)<-]=>[->(string)<-],
[->(numeric)<-]=>[->(decimal)<-],
[->(ntext)<-]=>[->(string)<-],
[->(nchar)<-]=>[->(string)<-],
[->(money)<-]=>[->(decimal)<-],
[->(int)<-]=>[->(int)<-],
[->(image)<-]=>[->(byte[])<-],
[->(float)<-]=>[->(double)<-],
[->(varbinary)<-]=>[->(byte[])<-],
[->(decimal)<-]=>[->(decimal)<-],
[->(datetimeoffset)<-]=>[->(DateTimeOffset)<-],
[->(datetime)<-]=>[->(DateTime)<-],
[->(char)<-]=>[->(string)<-],
[->(bit)<-]=>[->(bool)<-],
[->(binary)<-]=>[->(byte[])<-],
[->(bigint)<-]=>[->(long)<-]
]):PREPROCESSOR:}        protected override {:TDB:TABLE:CURRENT:NAME::}Model ToModel(SqlDataReader dataReader)
        {
            var result = new {:TDB:TABLE:CURRENT:NAME::}Model();
{:TDB:TABLE:COLUMN:FOREACH[             result.{:TDB:FUNCTION:REPLACE({:TDB:TABLE:COLUMN:FOREACH:CURRENT:NAME::}<-:WITH:[ ]:BY:[])::} = ({:TDB:TABLE:COLUMN:FOREACH:CURRENT:CONVERT:TYPE(C#)::}{:TDB:TABLE:COLUMN:FOREACH:CURRENT:IS:NULL(?):::})(dataReader[""{:TDB:TABLE:COLUMN:FOREACH:CURRENT:NAME::}""]{:TDB:TABLE:COLUMN:FOREACH:CURRENT:IS:NULL( is DBNull ? null : dataReader[""{:TDB:TABLE:COLUMN:FOREACH:CURRENT:NAME::}""]):::});
]::}            return result;
        }";
            var databaseModel   = persistanceFacade.GetDatabaseModelByPersistenceName("OnlyEmployeePayHistorySqlServerDatabaseModel");

            IDatabaseTemplateHandlerInputModel input = new DatabaseTemplateHandlerInputModel()
            {
                DatabaseModel  = databaseModel,
                TemplateModels = new List <ITemplateModel>()
                {
                    new TemplateModel()
                    {
                        TemplatedFilePath    = $"{_tested.TableFilePathTemplateWord}Dao.cs",
                        TemplatedFileContent = templateContent,
                    },
                },
                typeMappings = new List <ITypeMapping>(),
            };

            var result = _tested.Process(input);

            Assert.IsNotNull(result);
            CollectionAssert.IsNotEmpty(result);
            Assert.AreEqual(1, result.Count);
            var expected = @"        protected override EmployeePayHistoryModel ToModel(SqlDataReader dataReader)
        {
            var result = new EmployeePayHistoryModel();
             result.BusinessEntityID = (int)(dataReader[""BusinessEntityID""]);
             result.RateChangeDate = (DateTime)(dataReader[""RateChangeDate""]);
             result.Rate = (decimal)(dataReader[""Rate""]);
             result.PayFrequency = (byte)(dataReader[""PayFrequency""]);
             result.ModifiedDate = (DateTime)(dataReader[""ModifiedDate""]);
            return result;
        }";
            var actual   = result.First().Content;

            Assert.AreEqual(expected, actual);
        }