public void JsonCodeGenerator_WithDistinctInnerObject() { var obj = new WithInnerObject() { First = new WithIntsAndDateTimes() { Integer = 1, Long = (long)(int.MaxValue) + 1, Date = DateTime.Now }, Second = new WithStrings() { Title = "test", Category = "category" } }; var generator = new JsonCodeGenerator("csharp"); var classTypes = generator.GenerateClassesTypesFromObject("Root", JsonExtensions.ToJObject(obj)) .ToLookup(x => x.Name); Assert.Equal(3, classTypes.Count()); var clazz = classTypes["Root"].Single() as JsonCodeGenerator.ClassType; Assert.NotNull(clazz); var first = classTypes["FirstClass"].Single() as JsonCodeGenerator.ClassType; Assert.NotNull(first); Assert.Equal(3, first.Properties.Count); Assert.Equal("int", first.Properties["Integer"].Name); Assert.Equal("long", first.Properties["Long"].Name); Assert.Equal("DateTimeOffset", first.Properties["Date"].Name); Assert.True(first.Properties.All(x => !x.Value.IsArray && x.Value.IsPrimitive)); var second = classTypes["SecondClass"].Single() as JsonCodeGenerator.ClassType; Assert.NotNull(second); Assert.Equal(2, second.Properties.Count); Assert.Equal("string", second.Properties["Title"].Name); Assert.Equal("string", second.Properties["Category"].Name); Assert.True(second.Properties.All(x => !x.Value.IsArray && x.Value.IsPrimitive)); }
public void JsonCodeGenerator_WithDistinctInnerObject() { var obj = new WithInnerObject() { First = new WithIntsAndDateTimes() { Integer = 1, Long = (long)(int.MaxValue) + 1, Date = DateTime.Now }, Second = new WithStrings() { Title = "test", Category = "category" } }; var generator = new JsonCodeGenerator("csharp"); var classTypes = generator.GenerateClassesTypesFromObject("Root", JsonExtensions.ToJObject(obj)) .ToLookup(x => x.Name); Assert.Equal(3, classTypes.Count()); var clazz = classTypes["Root"].Single() as JsonCodeGenerator.ClassType; Assert.NotNull(clazz); var first = classTypes["FirstClass"].Single() as JsonCodeGenerator.ClassType; Assert.NotNull(first); Assert.Equal(3, first.Properties.Count); Assert.Equal("int", first.Properties["Integer"].Name); Assert.Equal("long", first.Properties["Long"].Name); Assert.Equal("DateTimeOffset", first.Properties["Date"].Name); Assert.True(first.Properties.All(x => !x.Value.IsArray && x.Value.IsPrimitive)); var second = classTypes["SecondClass"].Single() as JsonCodeGenerator.ClassType; Assert.NotNull(second); Assert.Equal(2, second.Properties.Count); Assert.Equal("string", second.Properties["Title"].Name); Assert.Equal("string", second.Properties["Category"].Name); Assert.True(second.Properties.All(x => !x.Value.IsArray && x.Value.IsPrimitive)); }