예제 #1
0
        public void SetUp()
        {
            _dbReadingServiceMock = new Mock <IDbReadingService>(MockBehavior.Strict);
            _dbSysUtilsMock       = new Mock <IDbSysUtils>(MockBehavior.Strict);

            _target = new CodeGeneratorController(_dbReadingServiceMock.Object, _dbSysUtilsMock.Object);

            _testModelProperties = new List <ModelProperty>
            {
                new ModelProperty
                {
                    PropertyDataType = "int",
                    PropertyName     = "RATE_GROUP_CODE",
                    IsNullable       = false
                },
                new ModelProperty
                {
                    PropertyDataType = "int",
                    PropertyName     = "SERVICE_LEVEL_NO",
                    IsNullable       = false
                },
                new ModelProperty
                {
                    PropertyDataType = "string",
                    PropertyName     = "RATE_GROUP_DESCRIPTION",
                    IsNullable       = false
                },
                new ModelProperty
                {
                    PropertyDataType = "string",
                    PropertyName     = "USER_ID",
                    IsNullable       = false
                },
                new ModelProperty
                {
                    PropertyDataType = "DateTimeOffset",
                    PropertyName     = "RECORD_INSERT_TIMESTAMP",
                    IsNullable       = false
                }
            };

            _testTables = new List <string>(
                new[]
            {
                "RATE_GROUP_DEF"
            }
                );
            _connectionString =
                "Data Source=ky1-vrt-msqld1.ky.cafepress.com;Initial Catalog=transit;User ID=cpdba;Password=ithinkgreen; ";

            _dbObjectName    = "GET_RATE_GROUP_BY_GROUP_CODE";
            _codeServiceType = CodeServiceType.TableModel;
        }
예제 #2
0
        public ActionResult GenerateModel(string connectionString, string dbObjectName, CodeServiceType codeServiceType)
        {
            if (string.IsNullOrEmpty(connectionString) ||
                string.IsNullOrEmpty(dbObjectName) ||
                codeServiceType == 0)
            {
                return(View("Index", new GeneratedModelCodeViewModel()));
            }

            _spReadingService.ConnectionString = connectionString;
            _spReadingService.DbObjectName     = dbObjectName;
            var modelProperties = _spReadingService.ReadColumnsFromDbObject().ToList();

            switch (codeServiceType)
            {
            case CodeServiceType.TableModel:
                _generatorService = new TableModelGenerator();
                break;

            case CodeServiceType.Repo:
                _generatorService = new RepoGenerator();
                break;

            case CodeServiceType.RepoTest:
                _generatorService = new RepoTestGenerator();
                break;

            default:
                throw new ArgumentException("That generator does not exists");
            }

            var generatedModelCodeViewModel = new GeneratedModelCodeViewModel
            {
                ModelName       = _dbSysUtils.GetTablesFromSP(connectionString, dbObjectName).ToList().FirstOrDefault(),
                ModelCode       = _generatorService.GenerateCode(modelProperties, connectionString, dbObjectName),
                CodeServiceType = codeServiceType
            };

            return(View("Index", generatedModelCodeViewModel));
        }