コード例 #1
0
ファイル: Program.cs プロジェクト: pingvinen/worm
        public static void Main(string[] args)
        {
            var parser = new Parser(new Worm.WormFactory());
            string workingDir = Directory.GetCurrentDirectory();

            DirectoryInfo libRoot = Directory.GetParent(workingDir).Parent.Parent.GetDirectories("fullflow-lib")[0];
            string modelProjectFile = String.Format("{0}/fullflow-lib.csproj", libRoot.FullName);

            PocoModel model = parser.Parse(modelProjectFile);

            foreach (PocoEntity entity in model.Entities)
            {
                Console.WriteLine("DbFactory: {0}", entity.DbFactory.GetType().Name);
                Console.WriteLine("PocoClassName: {0}", entity.PocoClassName);
                Console.WriteLine("PocoFilename: {0}", entity.PocoFilename);
                Console.WriteLine("PocoNamespace: {0}", entity.PocoNamespace);
                Console.WriteLine("TableName: {0}", entity.TableName);
                Console.WriteLine();

                foreach (PocoField field in entity.Fields)
                {
                    Console.WriteLine("AccessModifier: {0}", field.AccessModifier);
                    Console.WriteLine("AllowNull: {0}", field.AllowNull);
                    Console.WriteLine("ColumnName: {0}", field.ColumnName);
                    Console.WriteLine("HasGetter: {0}", field.HasGetter);
                    Console.WriteLine("HasSetter: {0}", field.HasSetter);
                    Console.WriteLine("IdGenerator: {0}", field.IdGenerator);
                    Console.WriteLine("IsEnum: {0}", field.IsEnum);
                    Console.WriteLine("IsPrimaryKey: {0}", field.IsPrimaryKey);
                    Console.WriteLine("Name: {0}", field.Name);
                    Console.WriteLine("StorageType: {0}", field.StorageType);
                    Console.WriteLine("Type: {0}", field.Type);
                    Console.WriteLine();
                }

                Console.WriteLine();
            }

            Engine eng = new Engine();
            Project proj = new Project(eng);
            proj.Load(modelProjectFile);
            BuildItemGroup compileBuildItemGroup = GetCompileIncludeBuildItemGroup(proj);

            var writer = new DbClassWriter(new WormFactory());
            foreach (PocoEntity entity in model.Entities)
            {
                CodeFile cf = writer.Generate(entity);
                //cf.Filename = cf.Filename.Replace("fullflowlib", "fullflow-lib");
                WriteCodeFile(libRoot, cf);
                AddFileToProject(compileBuildItemGroup, cf);
            }

            proj.Save(modelProjectFile);

            // compile the project again
            parser.Parse(modelProjectFile);
        }
コード例 #2
0
        public void Test()
        {
            var dbClassWriter = new DbClassWriter(new WormFactory());
            var entity = new PocoEntity() {
                DbFactory = new MySqlWormDbFactory(String.Empty),
                PocoClassName = "TestEntity",
                PocoFilename = "TestEntity.cs",
                PocoNamespace = "Test.Entities",
                TableName = "test_entities",
                WormClassName = "WormTestEntity",
                WormFilename = "WormTestEntity.cs",
                WormNamespace = "Test.Entities.Db"
            };

            entity.Fields.Add(new PocoField() {
                AccessModifier = AccessModifier.Public,
                ColumnName = "id",
                HasGetter = true,
                HasSetter = true,
                IdGenerator = WormIdGenerator.AutoIncrement,
                IsPrimaryKey = true,
                Name = "Id",
                StorageType = "int",
                Type = "int"
            });

            entity.Fields.Add(new PocoField() {
                AccessModifier = AccessModifier.Public,
                ColumnName = "my_string",
                HasGetter = true,
                HasSetter = true,
                Name = "MyString",
                StorageType = "varchar(255)",
                Type = "string"
            });

            entity.Fields.Add(new PocoField() {
                AccessModifier = AccessModifier.Public,
                ColumnName = "my_int",
                HasGetter = true,
                HasSetter = true,
                Name = "MyInt",
                StorageType = "int",
                Type = "int"
            });

            var result = dbClassWriter.Generate(entity);

            System.IO.File.WriteAllText("/tmp/mysql_" + result.Filename, result.Content);

            Assert.AreEqual("WormTestEntity.cs", result.Filename);
        }
コード例 #3
0
ファイル: DbClassWriterTests.cs プロジェクト: pingvinen/worm
        public void Setup()
        {
            this.poco = new Mock<PocoEntity>();
            this.factory = new Mock<WormFactory>();
            this.dbFactory = new Mock<IWormDbFactory>();
            this.templateProvider = new Mock<IWormTemplateProvider>();
            this.dbClassTemplate = new Mock<WormDbClassTemplate>();
            this.getByIdOrDefault = new Mock<DbGetByIdOrDefaultTemplateBase>();
            this.update = new Mock<DbUpdateTemplateBase>();
            this.insert = new Mock<DbInsertTemplateBase>();

            this.dbClassTemplate.SetupAllProperties();
            this.poco.SetupGet<IWormDbFactory>(xx => xx.DbFactory).Returns(this.dbFactory.Object);
            this.dbFactory.Setup(xx => xx.GetTemplateProvider()).Returns(this.templateProvider.Object);
            this.factory.Setup(xx => xx.GetWormDbClassTemplate()).Returns(this.dbClassTemplate.Object);
            this.templateProvider.Setup(xx => xx.GetDbGetByIdOrDefaultTemplate()).Returns(this.getByIdOrDefault.Object);
            this.templateProvider.Setup(xx => xx.GetDbUpdateTemplate()).Returns(this.update.Object);
            this.templateProvider.Setup(xx => xx.GetDbInsertTemplate()).Returns(this.insert.Object);

            this.writer = new DbClassWriter(this.factory.Object);
        }