コード例 #1
0
        public static void GenerateProject(YamlSpecification specification)
        {
            var project           = CsProjFile.LoadFrom(_testProjectFolder + @"Nest.Tests.Integration.Yaml.csproj");
            var existingYamlTests = project.All <CodeFile>().Where(c => c.Link != null && c.Link.EndsWith(".yaml.cs"));

            foreach (var c in existingYamlTests)
            {
                project.Remove(c);
            }

            var definitions = specification.Definitions;

            using (var pbar = new ProgressBar(definitions.Count, "Generating Code and project for yaml tests", ConsoleColor.Blue))
                foreach (var kv in specification.Definitions)
                {
                    var folder = kv.Key;
                    foreach (var d in kv.Value)
                    {
                        var path = folder + @"\" + d.FileName + ".cs";
                        if (!Directory.Exists(_testProjectFolder + folder))
                        {
                            Directory.CreateDirectory(_testProjectFolder + folder);
                        }

                        GenerateTestFileFromView(_testProjectFolder + path, d);
                        project.Add <CodeFile>(path);
                    }
                    pbar.Tick();
                }
            project.Save();
        }
コード例 #2
0
        private static void GenerateBaseJsonFormatter(YamlSpecification model)
        {
            var targetDir  = Path.GetFullPath(CodeConfiguration.ElasticCommonSchemaGeneratedFolder);
            var outputFile = Path.Combine(targetDir, "Serialization", @"BaseJsonFormatter.Generated.cs");
            var path       = Path.Combine(CodeConfiguration.ViewFolder, @"BaseJsonFormatter.Generated.cshtml");
            var template   = File.ReadAllText(path);
            var source     = DoRazor(nameof(GenerateBaseJsonFormatter), template, model);

            File.WriteAllText(outputFile, source);
        }
コード例 #3
0
        private static void GenerateTypeMappings(YamlSpecification model)
        {
            var targetDir  = Path.GetFullPath(CodeConfiguration.ElasticCommonSchemaNESTGeneratedFolder);
            var outputFile = Path.Combine(targetDir, @"TypeMappings.Generated.cs");
            var path       = Path.Combine(CodeConfiguration.ViewFolder, @"TypeMappings.Generated.cshtml");
            var template   = File.ReadAllText(path);
            var source     = DoRazor(nameof(GenerateTypeMappings), template, model);

            File.WriteAllText(outputFile, source);
        }
コード例 #4
0
 private static string DoRazor(string name, string template, YamlSpecification model) =>
 Razor.CompileRenderStringAsync(name, template, model).GetAwaiter().GetResult();