Ejemplo n.º 1
0
        public void GenerateSelectJoin()
        {
            // Arrange
            var objUser    = new User();
            var objAddress = new Address();

            IList <PropertyInfo> props  = new List <PropertyInfo>(objUser.GetType().GetProperties());
            IList <PropertyInfo> props2 = new List <PropertyInfo>(objAddress.GetType().GetProperties());

            var lstProperties = new List <IList <PropertyInfo> >
            {
                props,
                props2
            };

            List <string> models = new List <string>
            {
                "User",
                "Address"
            };

            // Act
            var ret = DapperGenerator.SelectJoin(models, lstProperties, false, false, false);

            // Assert
            Assert.Contains("SELECT Id, Name, Email FROM [User]", ret);
            Assert.Contains("ret = db.Query<User>(sql, commandType: CommandType.Text).ToList();", ret);
        }
Ejemplo n.º 2
0
        public void GenerateSelectAsync()
        {
            // Arrange
            var objUser = new User();
            IList <PropertyInfo> props = new List <PropertyInfo>(objUser.GetType().GetProperties());

            // Act
            var ret = DapperGenerator.Select("User", props, false, false, true, false);

            // Assert
            Assert.Contains("SELECT Id, Name, Email FROM [User]", ret);
            Assert.Contains("return await db.QueryAsync<User>(sql, commandType: CommandType.Text);", ret);
        }
Ejemplo n.º 3
0
        public void GenerateInsertNoIdAsync()
        {
            // Arrange
            var objUser = new User();
            IList <PropertyInfo> props = new List <PropertyInfo>(objUser.GetType().GetProperties());

            // Act
            var ret = DapperGenerator.Insert("User", props, false, false, true, true, false, false);

            // Assert
            Assert.Contains("INSERT INTO [User] (Name, Email) VALUES (@Name, @Email)", ret);
            Assert.Contains("await db.ExecuteAsync(sql, new { Name = user.Name, Email = user.Email }, commandType: CommandType.Text);", ret);
        }
Ejemplo n.º 4
0
        public void GenerateInsertReturnIdAsync()
        {
            // Arrange
            var objUser = new User();
            IList <PropertyInfo> props = new List <PropertyInfo>(objUser.GetType().GetProperties());

            // Act
            var ret = DapperGenerator.Insert("User", props, false, false, false, true, true, false);

            // Assert
            Assert.Contains("INSERT INTO [User] (Id, Name, Email) VALUES (@Id, @Name, @Email)", ret);
            Assert.Contains("return await db.QueryAsync<int>(sql, new { Id = user.Id, Name = user.Name, Email = user.Email }, commandType: CommandType.Text).Single();", ret);
        }
Ejemplo n.º 5
0
        public void GenerateSelectAsync()
        {
            // Arrange
            var objUser = new User();
            IList <PropertyInfo> props = new List <PropertyInfo>(objUser.GetType().GetProperties());
            var content = DapperGenerator.Select("User", props, false, false, true);

            // Act
            var ret = MethodGenerator.GenerateSelect(content, model, false, true);

            // Assert
            Assert.Contains("public async Task<IEnumerable<User>> SelectUser()", ret);
            Assert.Contains(content, ret);
        }
Ejemplo n.º 6
0
        public void GenerateReturnIdInsertAsync()
        {
            // Arrange
            var objUser = new User();
            IList <PropertyInfo> props = new List <PropertyInfo>(objUser.GetType().GetProperties());
            var content = DapperGenerator.Insert("User", props, false, false, false, true, true);

            // Act
            var ret = MethodGenerator.GenerateInsert(content, model, false, true, true);

            // Assert
            Assert.Contains("public async Task<int> InsertUser(User user)", ret);
            Assert.Contains(content, ret);
        }
Ejemplo n.º 7
0
        public void GenerateDelete()
        {
            // Arrange
            var objUser = new User();
            IList <PropertyInfo> props = new List <PropertyInfo>(objUser.GetType().GetProperties());
            var content = DapperGenerator.Delete("User", props, false, false, false);

            // Act
            var ret = MethodGenerator.GenerateDelete(content, model, false, false);

            // Assert
            Assert.Contains("public void DeleteUser(User user)", ret);
            Assert.Contains(content, ret);
        }
        public IActionResult GenerateCode([FromBody] vmGenerator data)
        {
            var spCollection = new List <string>();

            try
            {
                var webRootPath     = _hostingEnvironment.WebRootPath;     //From wwwroot
                var contentRootPath = _hostingEnvironment.ContentRootPath; //From Others

                var tblColumns     = data.Columns;
                var fullTblColumns = GetTableColumns(data.DatabaseName, data.TableName);

                var fileContentSet            = string.Empty;
                var fileContentGet            = string.Empty;
                var fileContentGetByID        = string.Empty;
                var fileContentPut            = string.Empty;
                var fileContentDelete         = string.Empty;
                var fileContentViewSp         = string.Empty;
                var fileContentIEntity        = string.Empty;
                var fileContentModifiedEntity = string.Empty;
                var fileContentEntities       = string.Empty;
                var fileContentDtos           = string.Empty;
                var fileContentCoreRepo       = string.Empty;
                var fileContentView           = string.Empty;
                var fileContentAPIGet         = string.Empty;
                var fileContentInterface      = string.Empty;
                var fileContentService        = string.Empty;
                var fileContentDbContext      = string.Empty;
                var fileContentUnitOfWork     = string.Empty;
                var fileContentCrud           = string.Empty;
                var fileModelDapper           = string.Empty;
                var fileIUnitDapper           = string.Empty;
                var fileRepoDapper            = string.Empty;

                //SP
                fileContentSet     = SpGenerator.GenerateInsertSP(tblColumns, webRootPath);
                fileContentGet     = SpGenerator.GenerateSelectSP(tblColumns, webRootPath);
                fileContentGetByID = SpGenerator.GenerateSelectByIDSP(tblColumns, webRootPath);
                fileContentPut     = SpGenerator.GenerateUpdateSP(tblColumns, webRootPath);
                fileContentDelete  = SpGenerator.GenerateDeleteSP(tblColumns, webRootPath);
                fileContentViewSp  = SpGenerator.GenerateViewSP(tblColumns, webRootPath);
                spCollection.Add(fileContentSet);
                spCollection.Add(fileContentGet);
                spCollection.Add(fileContentGetByID);
                spCollection.Add(fileContentPut);
                spCollection.Add(fileContentDelete);
                spCollection.Add(fileContentViewSp);

                //CORE
                fileContentIEntity        = VmGenerator.GenerateIEntity(webRootPath);
                fileContentModifiedEntity = VmGenerator.GenerateModifiedEntity(webRootPath);
                fileContentEntities       = VmGenerator.GenerateEntities(fullTblColumns, webRootPath);
                fileContentDtos           = VmGenerator.GenerateDtos(tblColumns, webRootPath);
                fileContentCoreRepo       = VmGenerator.GenerateIRepository(tblColumns, webRootPath);
                spCollection.Add(fileContentIEntity);
                spCollection.Add(fileContentModifiedEntity);
                spCollection.Add(fileContentEntities);
                spCollection.Add(fileContentDtos);
                spCollection.Add(fileContentCoreRepo);

                //VU
                fileContentView = ViewGenerator.GenerateForm(tblColumns, webRootPath);
                spCollection.Add(fileContentView);

                //API
                fileContentAPIGet = APIGenerator.GenerateAPIGet(tblColumns, webRootPath);
                spCollection.Add(fileContentAPIGet);

                //API SERVICE/INTERFACE
                fileContentInterface = SIGenerator.GenerateInterfaces(tblColumns, webRootPath);
                fileContentService   = SIGenerator.GenerateService(tblColumns, webRootPath);
                spCollection.Add(fileContentInterface);
                spCollection.Add(fileContentService);

                //EF REPO
                fileContentDbContext  = RepoEFGenerator.GenerateDbContext(tblColumns, webRootPath);
                fileContentUnitOfWork = RepoEFGenerator.GenerateUnitOfWork(webRootPath);
                fileContentCrud       = RepoEFGenerator.GenerateCrud(tblColumns, webRootPath);
                spCollection.Add(fileContentDbContext);
                spCollection.Add(fileContentUnitOfWork);
                spCollection.Add(fileContentCrud);

                //DAPPER REPO
                fileModelDapper = DapperGenerator.GenerateModel(tblColumns, webRootPath);
                fileIUnitDapper = DapperGenerator.GenerateUnitOfWork(tblColumns, webRootPath);
                fileRepoDapper  = DapperGenerator.GenerateRepository(tblColumns, webRootPath);
                spCollection.Add(fileModelDapper);
                spCollection.Add(fileIUnitDapper);
                spCollection.Add(fileRepoDapper);
            }
            catch (Exception ex)
            {
                ex.ToString();
            }

            return(Json(new
            {
                spCollection
            }));
        }