public void AddJsonAttribute()
        {
            string             path               = Directory.GetCurrentDirectory().Replace("bin\\Debug", "") + @"Test_3_SETTINGS_INPUT.txt";
            string             resultPath         = Directory.GetCurrentDirectory().Replace("bin\\Debug", "") + @"Test_3_SETTINGS_OUTPUT.txt";
            string             input              = File.ReadAllText(path);
            string             errorMessage       = string.Empty;
            JavaCodeWriter     javaCodeWriter     = new JavaCodeWriter();
            JsonClassGenerator jsonClassGenerator = new JsonClassGenerator();

            jsonClassGenerator.CodeWriter = javaCodeWriter;
            string returnVal      = jsonClassGenerator.GenerateClasses(input, out errorMessage).ToString();
            string resultsCompare = File.ReadAllText(resultPath);

            Assert.AreEqual(resultsCompare.Replace(Environment.NewLine, "").Replace(" ", "").Replace("\t", ""), returnVal.Replace(Environment.NewLine, "").Replace(" ", "").Replace("\t", ""));
        }
Exemplo n.º 2
0
        public void Run()
        {
            string             path               = Directory.GetCurrentDirectory().Replace("bin\\Debug", "") + @"Test_0_BASIC_SCENARIO_INPUT.txt";
            string             resultPath         = Directory.GetCurrentDirectory().Replace("bin\\Debug", "") + @"Test_0_BASIC_SCENARIO_OUTPUT.txt";
            string             input              = File.ReadAllText(path);
            JavaCodeWriter     javaCodeWriter     = new JavaCodeWriter();
            JsonClassGenerator jsonClassGenerator = new JsonClassGenerator
            {
                CodeWriter = javaCodeWriter
            };

            string errorMessage;
            string returnVal      = jsonClassGenerator.GenerateClasses(input, out errorMessage).ToString();
            string resultsCompare = File.ReadAllText(resultPath);

            Assert.AreEqual(resultsCompare.Replace(Environment.NewLine, "").Replace(" ", "").Replace("\t", ""),
                            returnVal.Replace(Environment.NewLine, "").Replace(" ", "").Replace("\t", ""));
        }
        public void Run()
        {
            string path       = Directory.GetCurrentDirectory().Replace("bin\\Debug", "") + @"Test_4_JAVA_RESERVED_KEYWORDS_INPUT.txt";
            string resultPath = Directory.GetCurrentDirectory().Replace("bin\\Debug", "") + @"Test_4_JAVA_RESERVED_KEYWORDS_OUTPUT.txt";
            string input      = File.ReadAllText(path);

            JavaCodeWriter     javaCodeWriter     = new JavaCodeWriter();
            JsonClassGenerator jsonClassGenerator = new JsonClassGenerator();

            jsonClassGenerator.CodeWriter             = javaCodeWriter;
            jsonClassGenerator.MutableClasses.Members = OutputMembers.AsPublicFields;

            string returnVal      = jsonClassGenerator.GenerateClasses(input, out string errorMessage).ToString();
            string resultsCompare = File.ReadAllText(resultPath);

            Assert.AreEqual(expected: resultsCompare.NormalizeOutput(), actual: returnVal.NormalizeOutput());
            Assert.AreEqual(expected: String.Empty, actual: errorMessage);
        }
Exemplo n.º 4
0
        public void AddJsonAttribute()
        {
            Assert.Inconclusive(message: "This test is not yet implemented.");
            return;

            string path       = Directory.GetCurrentDirectory().Replace("bin\\Debug", "") + @"Test_3_SETTINGS_INPUT.txt";
            string resultPath = Directory.GetCurrentDirectory().Replace("bin\\Debug", "") + @"Test_3_SETTINGS_OUTPUT.txt";
            string input      = File.ReadAllText(path);

            JavaCodeWriter     javaCodeWriter     = new JavaCodeWriter();
            JsonClassGenerator jsonClassGenerator = new JsonClassGenerator();

            jsonClassGenerator.CodeWriter = javaCodeWriter;

            string returnVal      = jsonClassGenerator.GenerateClasses(input, out string errorMessage).ToString();
            string resultsCompare = File.ReadAllText(resultPath);

            Assert.AreEqual(resultsCompare.NormalizeOutput(), returnVal.NormalizeOutput());
        }
Exemplo n.º 5
0
        public void Run_camelCase()
        {
            string path       = Directory.GetCurrentDirectory().Replace("bin\\Debug", "") + @"Test_2_HANDLE_NUMBERS_INPUT.txt";
            string resultPath = Directory.GetCurrentDirectory().Replace("bin\\Debug", "") + @"Test_2_HANDLE_NUMBERS_OUTPUT.txt";
            string input      = File.ReadAllText(path);

            JavaCodeWriter     javaCodeWriter     = new JavaCodeWriter();
            JsonClassGenerator jsonClassGenerator = new JsonClassGenerator();

            jsonClassGenerator.CodeWriter             = javaCodeWriter;
            jsonClassGenerator.MutableClasses.Members = OutputMembers.AsPublicFields;

            string returnVal      = jsonClassGenerator.GenerateClasses(input, out string errorMessage).ToString();
            string resultsCompare = File.ReadAllText(resultPath);

            string expectedOutput = resultsCompare.NormalizeOutput();
            string actualOutput   = returnVal.NormalizeOutput();

            Assert.AreEqual(expected: expectedOutput, actual: actualOutput);
        }
Exemplo n.º 6
0
        private bool _containsKeyword(string Json, int language)
        {
            ICodeWriter writer;

            if (language == 1)
            {
                writer = new CSharpCodeWriter();
            }
            else if (language == 2)
            {
                writer = new VisualBasicCodeWriter();
            }
            else if (language == 7)
            {
                writer = new TypeScriptCodeWriter();
            }
            else if (language == 4)
            {
                writer = new SqlCodeWriter();
            }
            else if (language == 5)
            {
                writer = new JavaCodeWriter();
            }
            else
            {
                writer = new PhpCodeWriter();
            }

            var jtoken  = JToken.Parse(Json);
            var hashSet = jtoken.ToHashSet();

            if (writer.Keywords.Any(x => hashSet.Contains(x)))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        public static string Prepare(string JSON, string classname, Core.Language language, string aNamespace, bool pascal, string propertyAttribute, bool hasGetSet = false)
        {
            if (string.IsNullOrEmpty(JSON))
            {
                return(null);
            }

            ICodeWriter writer;

            switch (language)
            {
            case Language.CSharp:
                writer = new CSharpCodeWriter();
                break;

            case Language.VisualBasic:
                writer = new VisualBasicCodeWriter();
                break;

            case Language.TypeScript:
                writer = new TypeScriptCodeWriter();
                break;

            case Language.Sql:
                writer = new SqlCodeWriter();
                break;

            case Language.Java:
                writer = new JavaCodeWriter();
                break;

            case Language.PHP:
                writer = new PhpCodeWriter();
                break;

            default:
                throw new NotImplementedException("This language does not yet exists");
            }
            ;


            var gen = new JsonClassGenerator();

            gen.Example                 = JSON;
            gen.InternalVisibility      = false;
            gen.CodeWriter              = writer;
            gen.ExplicitDeserialization = false;
            if (!string.IsNullOrEmpty(aNamespace))
            {
                gen.Namespace = aNamespace;
            }
            else
            {
                gen.Namespace = null;
            }

            gen.NoHelperClass      = false;
            gen.SecondaryNamespace = null;
            gen.UseProperties      = ((int)language != 5 && (int)language != 6) || hasGetSet;
            gen.MainClass          = classname;
            gen.UsePascalCase      = pascal;
            gen.PropertyAttribute  = propertyAttribute;

            gen.UseNestedClasses           = !string.IsNullOrEmpty(aNamespace);
            gen.ApplyObfuscationAttributes = false;
            gen.SingleFile = true;
            gen.ExamplesInDocumentation = false;

            gen.TargetFolder = null;
            gen.SingleFile   = true;

            using (var sw = new StringWriter())
            {
                gen.OutputStream = sw;
                gen.GenerateClasses();
                sw.Flush();

                return(sw.ToString());
            }
        }
Exemplo n.º 8
0
        private string Prepare(string JSON, string classname, int language, bool nest, bool pascal, string propertyAttribute, bool hasGetSet = false)
        {
            if (string.IsNullOrEmpty(JSON))
            {
                return(null);
            }

            ICodeWriter writer;

            if (language == 1)
            {
                writer = new CSharpCodeWriter();
            }
            else if (language == 2)
            {
                writer = new VisualBasicCodeWriter();
            }
            else if (language == 7)
            {
                writer = new TypeScriptCodeWriter();
            }
            else if (language == 4)
            {
                writer = new SqlCodeWriter();
            }
            else if (language == 5)
            {
                writer = new JavaCodeWriter();
            }
            else
            {
                writer = new PhpCodeWriter();
            }

            var gen = new JsonClassGenerator();

            gen.Example                 = JSON;
            gen.InternalVisibility      = false;
            gen.CodeWriter              = writer;
            gen.ExplicitDeserialization = false;
            if (nest)
            {
                gen.Namespace = "JSONUtils";
            }
            else
            {
                gen.Namespace = null;
            }

            gen.NoHelperClass      = false;
            gen.SecondaryNamespace = null;
            gen.UseProperties      = (language != 5 && language != 6) || hasGetSet;
            gen.MainClass          = classname;
            gen.UsePascalCase      = pascal;
            gen.PropertyAttribute  = propertyAttribute;

            gen.UseNestedClasses           = nest;
            gen.ApplyObfuscationAttributes = false;
            gen.SingleFile = true;
            gen.ExamplesInDocumentation = false;

            gen.TargetFolder = null;
            gen.SingleFile   = true;

            using (var sw = new StringWriter())
            {
                gen.OutputStream = sw;
                gen.GenerateClasses();
                sw.Flush();

                return(sw.ToString());
            }
        }