示例#1
0
        public void JsonCodeGenerator_WithArrayOfBasics()
        {
            var obj = new WithArrayOfBasics()
            {
                Ints    = new int[] { 0, 1, 2 },
                Strings = new string[] { "test", "category" }
            };

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

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

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

            Assert.NotNull(clazz);

            Assert.Equal("int", clazz.Properties["Ints"].Name);
            Assert.True(clazz.Properties["Ints"].IsArray);
            Assert.True(clazz.Properties["Ints"].IsPrimitive);

            Assert.Equal("string", clazz.Properties["Strings"].Name);
            Assert.True(clazz.Properties["Strings"].IsArray);
            Assert.True(clazz.Properties["Strings"].IsPrimitive);
        }
        public void JsonCodeGenerator_WithArrayOfBasics()
        {
            var obj = new WithArrayOfBasics()
            {
                Ints = new int[] { 0, 1, 2 },
                Strings = new string[] { "test", "category" }
            };

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

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

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

            Assert.Equal("int", clazz.Properties["Ints"].Name);
            Assert.True(clazz.Properties["Ints"].IsArray);
            Assert.True(clazz.Properties["Ints"].IsPrimitive);

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