コード例 #1
0
        public void TestInputMapping()
        {
            using (NewContext)
            {
                var settings = new Settings
                {
                    Namespace = "Test",
                    Input     = Path.Combine("Swagger", "swagger-payload-flatten.json"),
                    PayloadFlatteningThreshold = 3,
                    OutputDirectory            = Path.GetTempPath()
                };
                settings.FileSystem = new MemoryFileSystem();
                settings.FileSystem.WriteFile("AutoRest.json", File.ReadAllText("AutoRest.json"));
                settings.FileSystem.CreateDirectory(Path.GetDirectoryName(settings.Input));
                settings.FileSystem.WriteFile(settings.Input, File.ReadAllText(settings.Input));

                var             modeler     = new SwaggerModeler();
                var             clientModel = modeler.Build();
                CodeGeneratorCs generator   = new CodeGeneratorCs();

                generator.Generate(clientModel).GetAwaiter().GetResult();
                string body = settings.FileSystem.ReadFileAsText(Path.Combine(settings.OutputDirectory, "Payload.cs"));
                Assert.True(body.ContainsMultiline(@"
                MinProduct minProduct = new MinProduct();
                if (baseProductId != null || baseProductDescription != null || maxProductReference != null)
                {
                    minProduct.BaseProductId = baseProductId;
                    minProduct.BaseProductDescription = baseProductDescription;
                    minProduct.MaxProductReference = maxProductReference;
                }"));
            }
        }
コード例 #2
0
        public void TestInputMapping()
        {
            var input   = Path.Combine(Core.Utilities.Extensions.CodeBaseDirectory(typeof(MappingExtensionsTests)), "Resource", "swagger-payload-flatten.json");
            var modeler = new SwaggerModeler(new Settings {
                PayloadFlatteningThreshold = 3
            });
            var clientModel = modeler.Build(SwaggerParser.Parse(File.ReadAllText(input)));
            var plugin      = new PluginCs();

            using (plugin.Activate())
            {
                clientModel = plugin.Serializer.Load(clientModel);
                clientModel = plugin.Transformer.TransformCodeModel(clientModel);
                CodeGeneratorCs generator = new CodeGeneratorCs();

                generator.Generate(clientModel).GetAwaiter().GetResult();
                string body = Settings.Instance.FileSystemOutput.ReadAllText(Path.Combine("Payload.cs"));
                Assert.True(body.ContainsMultiline(@"
                    MinProduct minProduct = new MinProduct();
                    if (baseProductId != null || baseProductDescription != null || maxProductReference != null)
                    {
                        minProduct.BaseProductId = baseProductId;
                        minProduct.BaseProductDescription = baseProductDescription;
                        minProduct.MaxProductReference = maxProductReference;
                    }"));
            }
        }
コード例 #3
0
        public void TestInputMapping()
        {
            using (NewContext)
            {
                var settings = new Settings
                {
                    Namespace = "Test",
                    Input     = Path.Combine(Core.Utilities.Extensions.CodeBaseDirectory, "Resource", "swagger-payload-flatten.json"),
                    PayloadFlatteningThreshold = 3
                };
                settings.FileSystemInput = new MemoryFileSystem();
                settings.FileSystemInput.CreateDirectory(Path.GetDirectoryName(settings.Input));
                settings.FileSystemInput.WriteAllText(settings.Input, File.ReadAllText(settings.Input));

                var modeler     = new SwaggerModeler();
                var clientModel = modeler.Build();
                var plugin      = new PluginCs();
                using (plugin.Activate())
                {
                    clientModel = plugin.Serializer.Load(clientModel);
                    clientModel = plugin.Transformer.TransformCodeModel(clientModel);
                    CodeGeneratorCs generator = new CodeGeneratorCs();

                    generator.Generate(clientModel).GetAwaiter().GetResult();
                    string body = settings.FileSystemOutput.ReadAllText(Path.Combine("Payload.cs"));
                    Assert.True(body.ContainsMultiline(@"
                    MinProduct minProduct = new MinProduct();
                    if (baseProductId != null || baseProductDescription != null || maxProductReference != null)
                    {
                        minProduct.BaseProductId = baseProductId;
                        minProduct.BaseProductDescription = baseProductDescription;
                        minProduct.MaxProductReference = maxProductReference;
                    }"));
                }
            }
        }