コード例 #1
0
        public void Test_generated_entity_classes()
        {
            using (var tempFolder = new TempFolder())
            {
                const string projectConfigurationFile = "solution/DesignProject/ProjectConfiguration.xml";

                tempFolder.CreateWriteTextFile(projectConfigurationFile,
                                               @"
<ProjectConfiguration xmlns='uri:polygen/1.0/project-configuration'>
    <Solution path='..'>
        <Project name='DesignProject' path='DesignProject' type='Design' />
        <Project name='DataProject' path='DataProject' type='Data' />
    </Solution>
</ProjectConfiguration>
");

                const string designModelsFile = "solution/DesignProject/DesignModels/DesignModels.xml";

                tempFolder.CreateWriteTextFile(designModelsFile,
                                               @"
<DesignModels xmlns='uri:polygen/1.0/designmodel'>
    <Namespace name='TestApp.MyClasses'>
        <Entity name='MyEntity'>
            <Attribute name='Name' type='string' />
        </Entity>
    </Namespace>
</DesignModels>
");

                var outputFolder = tempFolder.CreateFolder("output");
                var runner       = TestRunner.Create(new Core.AutofacModule(), new Base.AutofacModule(), new Templates.HandlebarsNet.AutofacModule(), new AutofacModule());

                runner.Execute(new Core.RunnerConfiguration
                {
                    ProjectConfigurationFile = tempFolder.GetPath(projectConfigurationFile),
                    TempFolder = outputFolder
                });

                var generatedEntityClassFile = tempFolder.GetPath("output/DataProject/Entity/TestApp/MyClasses/MyEntity.gen.cs");
                var customEntityClassFile    = tempFolder.GetPath("output/DataProject/Entity/TestApp/MyClasses/MyEntity.cs");

                File.Exists(generatedEntityClassFile).Should().BeTrue();

                var generatedEntityClass = File.ReadAllText(generatedEntityClassFile).Trim();

                generatedEntityClass.Should().Contain("public partial class MyEntity");
                generatedEntityClass.Should().Contain("namespace TestApp.MyClasses");
                generatedEntityClass.Should().Contain("public string Name { get; set; }");
                generatedEntityClass.Should().Contain("using System;");

                File.Exists(customEntityClassFile).Should().BeTrue();

                var customEntityClass = File.ReadAllText(customEntityClassFile).Trim();

                customEntityClass.Should().Contain("public partial class MyEntity");
                customEntityClass.Should().Contain("namespace TestApp.MyClasses");
                customEntityClass.Should().NotContain("public string Name { get; set; }");
                customEntityClass.Should().Contain("using System;");
            }
        }
コード例 #2
0
ファイル: BasePluginTests.cs プロジェクト: mpoyhonen/polygen
        public void Test_project_configuration_file_parsing()
        {
            using (var tempFolder = new TempFolder())
            {
                const string designModelPath = "ProjectConfiguration.xml";

                tempFolder.CreateWriteTextFile(designModelPath,
                                               @"
<ProjectConfiguration xmlns='uri:polygen/1.0/project-configuration'>
    <Solution path='solution'>
        <Project name='DesignProject' path='DesignProject' type='Design' />
        <Project name='WebProject' path='WebProject' type='Web' />
    </Solution>
</ProjectConfiguration>
");

                var runner = TestRunner.Create(new Core.AutofacModule(), new AutofacModule());

                runner.Initialize();
                runner.RegisterSchemas();
                runner.ParseProjectConfiguration(tempFolder.GetPath(designModelPath));

                var projectConfiguration = runner.Context.DesignModels.GetByType(Core.CoreConstants.DesignModelType_ProjectConfiguration).FirstOrDefault() as IProjectConfiguration;

                projectConfiguration.Should().NotBeNull();
                projectConfiguration.Projects.Projects.Count().Should().Be(2);

                var projects = projectConfiguration.Projects.Projects.Select(x => (name: x.Name, path: x.SourceFolder, type: x.Type));

                projects.Should().BeEquivalentTo(new[] {
コード例 #3
0
        public void Test_template_loading_with_override()
        {
            using (var tempFolder = new TempFolder())
            {
                var collection = new TemplateCollection();

                tempFolder.CreateWriteTextFile("folder1/template-a.hbs", "Contents A");
                tempFolder.CreateWriteTextFile("folder2/template-a.hbs", "Contents B");

                collection.LoadTemplates(new[] { tempFolder.GetPath("folder1"), tempFolder.GetPath("folder2") });

                var templateA = collection.GetTemplate("template-a");

                templateA.Should().NotBeNull();
                templateA.Name.Should().Be("template-a");
                templateA.RenderIntoString(new object()).Should().Be("Contents B");
            }
        }
コード例 #4
0
        public void Test_generated_schemas()
        {
            using (var tempFolder = new TempFolder())
            {
                const string projectConfigurationFile = "ProjectConfiguration.xml";

                tempFolder.CreateWriteTextFile(projectConfigurationFile,
                                               @"
<ProjectConfiguration xmlns='uri:polygen/1.0/project-configuration'>
    <Solution path='solution'>
        <Project name='DesignProject' path='DesignProject' type='Design' />
    </Solution>
</ProjectConfiguration>
");

                var outputFolder = tempFolder.CreateFolder("output");
                var runner       = TestRunner.Create(new Core.AutofacModule(), new AutofacModule());

                runner.Execute(new Core.RunnerConfiguration
                {
                    ProjectConfigurationFile = tempFolder.GetPath(projectConfigurationFile),
                    TempFolder = outputFolder
                });

                var projectConfigurationSchemaFile = tempFolder.GetPath("output/DesignProject/Schemas/XSD/ProjectConfiguration.xsd");

                File.Exists(projectConfigurationSchemaFile).Should().BeTrue();

                var projectConfigurationSchema = File.ReadAllText(projectConfigurationSchemaFile).Trim();

                projectConfigurationSchema.Should().Contain("<xs:element name=\"Solution\"");

                var designModelSchemaFile = tempFolder.GetPath("output/DesignProject/Schemas/XSD/DesignModels.xsd");

                File.Exists(designModelSchemaFile).Should().BeTrue();

                var designModelSchema = File.ReadAllText(designModelSchemaFile).Trim();

                designModelSchema.Should().Contain("<xs:element name=\"Namespace\"");
            }
        }