protected void TestBuildCode(string classFileName, DocumentType contentType, string contentTypeName)
        {
            string expectedOutput;

            using (var goldReader = File.OpenText(@"..\..\TestFiles\" + classFileName + ".cs"))
            {
                expectedOutput = goldReader.ReadToEnd();
            }

            var configuration = CodeGeneratorConfiguration.Create();
            var typeConfig    = configuration.Get(contentTypeName);

            typeConfig.BaseClass = "Umbraco.Core.Models.TypedModelBase";
            typeConfig.Namespace = "Umbraco.CodeGen.Models";

            configuration.TypeMappings.Add(new TypeMapping("Umbraco.Integer", "Int32"));

            OnConfiguring(configuration, contentTypeName);

            var sb     = new StringBuilder();
            var writer = new StringWriter(sb);

            var dataTypeProvider = new TestDataTypeProvider();
            var generator        = new CodeGenerator(typeConfig, dataTypeProvider, CreateGeneratorFactory());

            generator.Generate(contentType, writer);

            writer.Flush();
            Console.WriteLine(sb.ToString());

            Assert.AreEqual(expectedOutput, sb.ToString());
        }
示例#2
0
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     Parser        = new CommonInfoParser(Configuration);
     ContentType   = new MediaType();
     Info          = ContentType.Info;
 }
示例#3
0
 public void SetUp()
 {
     Generator     = new StructureGenerator(Configuration);
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     Candidate     = Type = new CodeTypeDeclaration();
     ContentType   = new MediaType();
 }
示例#4
0
        private static void TestParse <T>(string fileName, string contentTypeName, T expectedContentType, ParserFactory factory)
            where T : ContentType
        {
            string code;

            using (var inputReader = File.OpenText(@"..\..\TestFiles\" + fileName + ".cs"))
            {
                code = inputReader.ReadToEnd();
            }

            var config = CodeGeneratorConfiguration.Create().Get(contentTypeName);

            config.BaseClass = "DocumentTypeBase";

            var parser = new CodeParser(
                config,
                TestDataTypeProvider.All,
                factory
                );

            var contentType = parser.Parse(new StringReader(code)).SingleOrDefault();

            var expectedXml = SerializationHelper.BclSerialize(expectedContentType);
            var actualXml   = SerializationHelper.BclSerialize((T)contentType);

            Assert.AreEqual(expectedXml, actualXml);
        }
示例#5
0
        public void SetUp()
        {
            Configuration         = CodeGeneratorConfiguration.Create().MediaTypes;
            DataTypeConfiguration = TestDataTypeProvider.All;

            Parser = CreateParser();
        }
 public void SetUp()
 {
     Generator     = new StructureGenerator(Configuration);
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     attribute     = new CodeAttributeDeclaration("MediaType");
     contentType   = new MediaType();
 }
        private static void TestGeneratedXml(string classFileName, string xmlFileName, string contentTypeName, ParserFactory factory)
        {
            ContentType contentType;
            string      expectedOutput;

            using (var goldReader = File.OpenText(@"..\..\TestFiles\" + xmlFileName + ".xml"))
            {
                expectedOutput = goldReader.ReadToEnd();
            }

            var contentTypeConfig = CodeGeneratorConfiguration.Create().Get(contentTypeName);

            contentTypeConfig.BaseClass = "Umbraco.Core.Models.TypedModelBase";

            using (var inputReader = File.OpenText(@"..\..\TestFiles\" + classFileName + ".cs"))
            {
                var codeParser = new CodeParser(contentTypeConfig, TestDataTypeProvider.All, factory);
                contentType = codeParser.Parse(inputReader).Single();
            }

            var serializer = new ContentTypeSerializer();
            var xml        = serializer.Serialize(contentType);

            Console.WriteLine(xml);

            Assert.AreEqual(expectedOutput, xml);
        }
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     Parser        = new DocumentTypeInfoParser(Configuration);
     ContentType   = new DocumentType();
     Info          = ContentType.Info;
     typedInfo     = (DocumentTypeInfo)Info;
 }
示例#9
0
 public void SetUp()
 {
     Configuration           = CodeGeneratorConfiguration.Create().MediaTypes;
     Configuration.Namespace = "MyWeb.Models";
     ContentType             = new MediaType();
     Generator   = new NamespaceGenerator(Configuration);
     compileUnit = new CodeCompileUnit();
 }
        public void Create_DelegatesConfiguration()
        {
            var factory             = new DefaultParserFactory();
            var configuration       = new ContentTypeConfiguration(CodeGeneratorConfiguration.Create(), "DocumentType");
            var dataTypeDefinitions = new List <DataTypeDefinition>();
            var parser = factory.Create(configuration, dataTypeDefinitions);

            Assert.IsInstanceOf <DocumentTypeCodeParser>(parser);
        }
        public void Parse_Definition_WhenMissingOrUnknown_AndDefaultIsMissing_Throws()
        {
            CodeGenConfig = CodeGeneratorConfiguration.Create();
            CodeGenConfig.TypeMappings.DefaultDefinitionId = "";
            Configuration = CodeGenConfig.MediaTypes;
            Parser        = new PropertyParser(Configuration, DataTypeConfiguration);

            ParseProperty(PureProperty);
        }
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     attribute     = new CodeAttributeDeclaration();
     Generator     = new EntityDescriptionGenerator(Configuration);
     documentType  = new DocumentType {
         Info = { Alias = "anEntity" }
     };
     EntityDescription = documentType.Info;
 }
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     Generator     = new CommonInfoGenerator(Configuration);
     ContentType   = new MediaType {
         Info = { Alias = "anEntity" }
     };
     Candidate = Type = new CodeTypeDeclaration();
     info      = ContentType.Info;
 }
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     Candidate     = Type = new CodeTypeDeclaration();
     generator     = new DocumentTypeInfoGenerator(Configuration);
     documentType  = new DocumentType {
         Info = { Alias = "aClass" }
     };
     info = (DocumentTypeInfo)documentType.Info;
 }
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().DocumentTypes;
     Candidate     = Type = new CodeTypeDeclaration();
     Generator     = new InterfaceNameGenerator(Configuration);
     documentType  = new DocumentType {
         Info = { Alias = "aMixin" }
     };
     EntityDescription = documentType.Info;
 }
示例#16
0
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().DocumentTypes;
     Generator     = new InterfaceGenerator(
         Configuration
         );
     ContentType = new DocumentType {
         Info = { Alias = "Mixin" }
     };
     ns = new CodeNamespace("ANamespace");
 }
示例#17
0
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     attribute     = new CodeAttributeDeclaration("DocumentType");
     generator     = new DocumentTypeInfoGenerator(Configuration);
     documentType  = new DocumentType
     {
         Info = info = new DocumentTypeInfo {
             Alias = "aClass"
         }
     };
 }
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     Generator     = new ClassGenerator(
         Configuration,
         new EntityDescriptionGenerator(Configuration)
         );
     ContentType = new MediaType {
         Info = { Alias = "anEntity" }
     };
     info = ContentType.Info;
     ns   = new CodeNamespace("ANamespace");
 }
示例#19
0
 public void SetUp()
 {
     codeGenConfig = CodeGeneratorConfiguration.Create();
     Configuration = codeGenConfig.MediaTypes;
     Generator     = new PropertyInfoGenerator(
         Configuration,
         TestDataTypeProvider.All
         );
     attribute = new CodeAttributeDeclaration();
     property  = new GenericProperty {
         Alias = "anEntity"
     };
 }
示例#20
0
 public void SetUp()
 {
     codeGenConfig = CodeGeneratorConfiguration.Create();
     Configuration = codeGenConfig.MediaTypes;
     Generator     = new PropertyInfoGenerator(
         Configuration,
         TestDataTypeProvider.All,
         new EntityDescriptionGenerator(Configuration)
         );
     Candidate = codeProperty = new CodeMemberProperty();
     property  = new GenericProperty {
         Alias = "anEntity"
     };
 }
示例#21
0
 public void SetUp()
 {
     codeGenConfig = CodeGeneratorConfiguration.Create();
     Configuration = codeGenConfig.DocumentTypes;
     Generator     = new InterfacePropertyDeclarationGenerator(
         Configuration,
         TestDataTypeProvider.All,
         new EntityDescriptionGenerator(Configuration)
         );
     Candidate = codeProperty = new CodeMemberProperty();
     property  = new GenericProperty {
         Alias = "aProperty"
     };
 }
        public void Generate_Adds_Getter()
        {
            var property = new GenericProperty {
                Alias = "aProperty"
            };
            var propNode = new CodeMemberProperty {
                Type = new CodeTypeReference("String")
            };

            var generator = new InterfacePropertyBodyGenerator(CodeGeneratorConfiguration.Create().DocumentTypes);

            generator.Generate(propNode, property);

            Assert.IsTrue(propNode.HasGet);
            Assert.AreEqual(0, propNode.GetStatements.Count);
        }
示例#23
0
        public void SetUp()
        {
            Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
            Candidate     = type = new CodeTypeDeclaration();
            contentType   = new MediaType
            {
                Info = info = new Info {
                    Alias = "anEntity"
                }
            };

            attribute = new CodeAttributeDeclaration("MediaType");
            type.CustomAttributes.Add(attribute);

            Generator = new CommonInfoGenerator(Configuration);
        }
示例#24
0
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     Parser        = new StructureParser(Configuration);
     ContentType   = new MediaType();
 }
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().DocumentTypes;
     spy1          = new SpyGenerator();
     spy2          = new SpyGenerator();
 }
 protected override CodeGeneratorBase CreateGenerator()
 {
     return(new PropertyBodyGenerator(CodeGeneratorConfiguration.Create().MediaTypes));
 }