예제 #1
0
        public void JsonCodeGenerator_WithArrayOfObjectsGenerator()
        {
            var root = new WithArrayOfObjects()
            {
                Objects = new List <WithStrings>
                {
                    new WithStrings()
                    {
                        Title = "test", Category = "category"
                    },
                    new WithStrings()
                    {
                        Title = "test", Category = "category"
                    },
                }
            };

            var document = new JsonDocument()
            {
                DataAsJson = JsonExtensions.ToJObject(root)
            };

            var generator = new JsonCodeGenerator("csharp");
            var code      = generator.Execute(document);

            Assert.Contains("public class Class", code);
            Assert.Contains("public Objects[] Objects { get; set; }", code);


            Assert.Contains("public class Objects", code);
            Assert.Contains("public string Title { get; set; }", code);
            Assert.Contains("public string Category { get; set; }", code);
        }
예제 #2
0
        public void JsonCodeGenerator_WithArrayOfObjects()
        {
            var root = new WithArrayOfObjects()
            {
                Objects = new List <WithStrings>
                {
                    new WithStrings()
                    {
                        Title = "test", Category = "category"
                    },
                    new WithStrings()
                    {
                        Title = "test", Category = "category"
                    },
                }
            };

            var generator  = new JsonCodeGenerator("csharp");
            var classTypes = generator.GenerateClassesTypesFromObject("Root", JsonExtensions.ToJObject(root))
                             .ToLookup(x => x.Name);

            Assert.Equal(2, classTypes.Count());

            var clazz = classTypes["Root"].Single() as JsonCodeGenerator.ClassType;

            Assert.NotNull(clazz);

            var first = classTypes["Objects"].Single() as JsonCodeGenerator.ClassType;

            Assert.NotNull(first);

            Assert.Equal("Objects", clazz.Properties["Objects"].Name);
            Assert.True(clazz.Properties["Objects"].IsArray);
            Assert.False(clazz.Properties["Objects"].IsPrimitive);
        }
예제 #3
0
        public void JsonCodeGenerator_WithArrayOfObjectsGenerator()
        {
            var root = new WithArrayOfObjects()
            {
                Objects = new List<WithStrings>
                {
                     new WithStrings() { Title = "test", Category = "category" },
                     new WithStrings() { Title = "test", Category = "category" },
                }
            };

            var document = new JsonDocument()
            {
                DataAsJson = JsonExtensions.ToJObject(root)
            };

            var generator = new JsonCodeGenerator("csharp");
            var code = generator.Execute(document);

            Assert.Contains("public class Class", code);
            Assert.Contains("public Objects[] Objects { get; set; }", code);

            Assert.Contains("public class Objects", code);
            Assert.Contains("public string Title { get; set; }", code);
            Assert.Contains("public string Category { get; set; }", code);
        }
예제 #4
0
        public void JsonCodeGenerator_WithArrayOfObjects()
        {
            var root = new WithArrayOfObjects()
            {
                Objects = new List<WithStrings>
                {
                     new WithStrings() { Title = "test", Category = "category" },
                     new WithStrings() { Title = "test", Category = "category" },
                }
            };

            var generator = new JsonCodeGenerator("csharp");
            var classTypes = generator.GenerateClassesTypesFromObject("Root", JsonExtensions.ToJObject(root))
                                      .ToLookup(x => x.Name);

            Assert.Equal(2, classTypes.Count());

            var clazz = classTypes["Root"].Single() as JsonCodeGenerator.ClassType;
            Assert.NotNull(clazz);

            var first = classTypes["Objects"].Single() as JsonCodeGenerator.ClassType;
            Assert.NotNull(first);

            Assert.Equal("Objects", clazz.Properties["Objects"].Name);
            Assert.True(clazz.Properties["Objects"].IsArray);
            Assert.False(clazz.Properties["Objects"].IsPrimitive);
        }