Example #1
0
        public void Build_CreatesClassWithCompleteContentType()
        {
            var classDefinition = new ClassDefinition("Complete content type");

            classDefinition.AddProperty(Property.FromContentTypeElement("text", "text"));
            classDefinition.AddProperty(Property.FromContentTypeElement("rich_text", "rich_text"));
            classDefinition.AddProperty(Property.FromContentTypeElement("rich_text_structured", "rich_text(structured)"));
            classDefinition.AddProperty(Property.FromContentTypeElement("number", "number"));
            classDefinition.AddProperty(Property.FromContentTypeElement("multiple_choice", "multiple_choice"));
            classDefinition.AddProperty(Property.FromContentTypeElement("date_time", "date_time"));
            classDefinition.AddProperty(Property.FromContentTypeElement("asset", "asset"));
            classDefinition.AddProperty(Property.FromContentTypeElement("modular_content", "modular_content"));
            classDefinition.AddProperty(Property.FromContentTypeElement("taxonomy", "taxonomy"));
            classDefinition.AddProperty(Property.FromContentTypeElement("url_slug", "url_slug"));
            classDefinition.AddProperty(Property.FromContentTypeElement("custom", "custom"));

            classDefinition.AddSystemProperty();

            var classCodeGenerator = new DeliveryClassCodeGenerator(classDefinition, classDefinition.ClassName);

            var compiledCode = classCodeGenerator.GenerateCode();

            var executingPath = AppContext.BaseDirectory;
            var expectedCode  = File.ReadAllText(executingPath + "/Assets/CompleteContentType_CompiledCode.txt");

            Assert.Equal(expectedCode, compiledCode, ignoreWhiteSpaceDifferences: true, ignoreLineEndingDifferences: true);
        }
        public void Build_CreatesClassWithCompleteContentType()
        {
            var classDefinition = new ClassDefinition("Complete content type");

            classDefinition.AddProperty(Property.FromContentType("text", "text"));
            classDefinition.AddProperty(Property.FromContentType("rich_text", "rich_text"));
            classDefinition.AddProperty(Property.FromContentType("rich_text_structured", "rich_text(structured)"));
            classDefinition.AddProperty(Property.FromContentType("number", "number"));
            classDefinition.AddProperty(Property.FromContentType("multiple_choice", "multiple_choice"));
            classDefinition.AddProperty(Property.FromContentType("date_time", "date_time"));
            classDefinition.AddProperty(Property.FromContentType("asset", "asset"));
            classDefinition.AddProperty(Property.FromContentType("modular_content", "modular_content"));
            classDefinition.AddProperty(Property.FromContentType("taxonomy", "taxonomy"));
            classDefinition.AddProperty(Property.FromContentType("url_slug", "url_slug"));

            classDefinition.AddSystemProperty();

            var classCodeGenerator = new ClassCodeGenerator(classDefinition);

            string compiledCode = classCodeGenerator.GenerateCode();

            string executingPath = AppContext.BaseDirectory;
            string expectedCode  = File.ReadAllText(executingPath + "/Assets/CompleteContentType_CompiledCode.txt");

            // Ignore white space
            expectedCode = Regex.Replace(expectedCode, @"\s+", "");
            compiledCode = Regex.Replace(compiledCode, @"\s+", "");

            Assert.Equal(expectedCode, compiledCode);
        }
Example #3
0
        public void AddSystemProperty_SystemPropertyIsAdded()
        {
            var classDefinition = new ClassDefinition("Class name");

            classDefinition.AddSystemProperty();

            Assert.Single(classDefinition.Properties, property => property.Codename == "system");
        }
Example #4
0
 private static void TryAddSystemProperty(ClassDefinition classDefinition)
 {
     try
     {
         classDefinition.AddSystemProperty();
     }
     catch (InvalidOperationException)
     {
         Console.WriteLine(
             $"Warning: Can't add 'System' property. It's in collision with existing element in Content Type '{classDefinition.ClassName}'.");
     }
 }