Ejemplo n.º 1
0
        public void JsonCodeGenerator_ContentResolutionForNumerics()
        {
            // Result will be Int,Int,DateTime
            var root = new WithIntsAndDateTimes()
            {
                Integer = 1,
                Long    = 2,
                Date    = DateTime.Now
            };

            var generator  = new JsonCodeGenerator("csharp");
            var classTypes = generator.GenerateClassesTypesFromObject("Root", JsonExtensions.ToJObject(root))
                             .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["Integer"].Name);
            Assert.False(clazz.Properties["Integer"].IsArray);
            Assert.True(clazz.Properties["Integer"].IsPrimitive);

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

            Assert.Equal("DateTimeOffset", clazz.Properties["Date"].Name);
            Assert.False(clazz.Properties["Date"].IsArray);
            Assert.True(clazz.Properties["Date"].IsPrimitive);
        }
Ejemplo n.º 2
0
        public void JsonCodeGenerator_SimpleObjectWithNumericsAndDateTimeGenerator()
        {
            var root = new WithIntsAndDateTimes()
            {
                Integer = int.MaxValue,
                Long    = long.MaxValue,
                Date    = DateTime.Now
            };
            var document = new JsonDocument()
            {
                DataAsJson = JsonExtensions.ToJObject(root)
            };

            // "Raven-Clr-Type": "Namespace.ClassName, AssemblyName"
            document.Metadata["Raven-Clr-Type"] = new RavenJValue("NamespaceName.ClassName, AssemblyName");

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

            Assert.Contains("namespace NamespaceName", code);
            Assert.Contains("public class ClassName", code);
            Assert.Contains("public DateTimeOffset Date { get; set; }", code);
            Assert.Contains("public long Long { get; set; }", code);
            Assert.Contains("public int Integer { get; set; }", code);
        }
Ejemplo n.º 3
0
        public void JsonCodeGenerator_SimpleObjectWithNumericsAndDateTime()
        {
            var root = new WithIntsAndDateTimes()
            {
                Integer = int.MaxValue,
                Long    = long.MaxValue,
                Date    = DateTime.Now
            };

            var generator  = new JsonCodeGenerator("csharp");
            var classTypes = generator.GenerateClassesTypesFromObject("Root", JsonExtensions.ToJObject(root))
                             .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["Integer"].Name);
            Assert.False(clazz.Properties["Integer"].IsArray);
            Assert.True(clazz.Properties["Integer"].IsPrimitive);

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

            Assert.Equal("DateTimeOffset", clazz.Properties["Date"].Name);
            Assert.False(clazz.Properties["Date"].IsArray);
            Assert.True(clazz.Properties["Date"].IsPrimitive);
        }
Ejemplo n.º 4
0
        public void JsonCodeGenerator_ContentResolutionForNumerics()
        {
            // Result will be Int,Int,DateTime
            var root = new WithIntsAndDateTimes()
            {
                Integer = 1,
                Long = 2,
                Date = DateTime.Now
            };

            var generator = new JsonCodeGenerator("csharp");
            var classTypes = generator.GenerateClassesTypesFromObject("Root", JsonExtensions.ToJObject(root))
                                      .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["Integer"].Name);
            Assert.False(clazz.Properties["Integer"].IsArray);
            Assert.True(clazz.Properties["Integer"].IsPrimitive);

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

            Assert.Equal("DateTimeOffset", clazz.Properties["Date"].Name);
            Assert.False(clazz.Properties["Date"].IsArray);
            Assert.True(clazz.Properties["Date"].IsPrimitive);
        }
Ejemplo n.º 5
0
        public void JsonCodeGenerator_SimpleObjectWithNumericsAndDateTimeGenerator()
        {
            var root = new WithIntsAndDateTimes()
            {
                Integer = int.MaxValue,
                Long = long.MaxValue,
                Date = DateTime.Now
            };
            var document = new JsonDocument()
            {
                DataAsJson = JsonExtensions.ToJObject(root)
            };

            // "Raven-Clr-Type": "Namespace.ClassName, AssemblyName"
            document.Metadata["Raven-Clr-Type"] = new RavenJValue("NamespaceName.ClassName, AssemblyName");

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

            Assert.Contains("namespace NamespaceName", code);
            Assert.Contains("public class ClassName", code);
            Assert.Contains("public DateTimeOffset Date { get; set; }", code);
            Assert.Contains("public long Long { get; set; }", code);
            Assert.Contains("public int Integer { get; set; }", code);
        }
Ejemplo n.º 6
0
        public void JsonCodeGenerator_SimpleObjectWithNumericsAndDateTime()
        {
            var root = new WithIntsAndDateTimes()
            {
                Integer = int.MaxValue,
                Long = long.MaxValue,
                Date = DateTime.Now
            };

            var generator = new JsonCodeGenerator("csharp");
            var classTypes = generator.GenerateClassesTypesFromObject("Root", JsonExtensions.ToJObject(root))
                                      .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["Integer"].Name);
            Assert.False(clazz.Properties["Integer"].IsArray);
            Assert.True(clazz.Properties["Integer"].IsPrimitive);

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

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