Beispiel #1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Need a C# code file path.");
                Environment.Exit(1);
            }

            var path        = args[0];
            var csharpCodes = System.IO.File.ReadAllText(path);
            var result      = CSharpValidation.CompileThenSave(csharpCodes, null);

            if (result.Success)
            {
                Console.WriteLine("Generated codes pass compilation.");
            }
            else
            {
                Console.WriteLine("Compile generated codes and found the following errors:");
                foreach (var ms in result.Diagnostics)
                {
                    Console.WriteLine(ms.ToString());
                }

                Console.WriteLine($"Total Errors: {result.Diagnostics.Length}");
                Environment.Exit(2);
            }
        }
Beispiel #2
0
        public void GenerateFromOpenApiAndBuild(string openapiDir, Settings mySettings = null)
        {
            string s = TranslateDefToCode(openapiDir, mySettings);
            var    r = CSharpValidation.CompileThenSave(s, null, mySettings != null ? mySettings.UseSystemTextJson : false);

            if (!r.Success)
            {
                output.WriteLine("CSharp Compilation Errors:");
                foreach (var ms in r.Diagnostics)
                {
                    output.WriteLine(ms.ToString());
                }
            }

            Assert.True(r.Success);
        }
Beispiel #3
0
        public string GenerateFromOpenApiAndBuildWithError(string openapiDir, Settings mySettings = null)
        {
            string s = TranslateDefToCode(openapiDir, mySettings);
            var    r = CSharpValidation.CompileThenSave(s, null, mySettings != null ? mySettings.UseSystemTextJson : false);

            if (!r.Success)
            {
                StringBuilder sb = new StringBuilder();
                output.WriteLine("CSharp Compilation Errors:");
                foreach (var ms in r.Diagnostics)
                {
                    sb.AppendLine(ms.ToString());
                }

                return(sb.ToString());
            }

            return(null);
        }
        public void GenerateAndAssertAndBuild(string filePath, string expectedFile, Settings mySettings = null)
        {
            string s = TranslateDefToCode(filePath, mySettings);
            //File.WriteAllText(expectedFile, s); //To update Results after some feature changes. Copy what in the bin folder back to the source content.
            string expected = ReadFromResults(expectedFile);

            Assert.Equal(expected, s);
            var r = CSharpValidation.CompileThenSave(s, null);

            if (!r.Success)
            {
                output.WriteLine("CSharp Compilation Errors:");
                foreach (var ms in r.Diagnostics)
                {
                    output.WriteLine(ms.ToString());
                }
            }

            Assert.True(r.Success);
        }