private static async Task TestGenerate(string apiVersion, string[] methodUrls, string expectedJsonString)
        {
            MemoryFileSystem fileSystem = new MemoryFileSystem();

            Settings settings = new Settings();
            settings.FileSystem = fileSystem;

            ServiceClient serviceClient = new ServiceClient();
            serviceClient.ApiVersion = apiVersion;
            foreach(string methodUrl in methodUrls)
            {
                serviceClient.Methods.Add(new Method()
                {
                    Url = methodUrl,
                    HttpMethod = HttpMethod.Put,
                });
            }
            await CreateGenerator(settings).Generate(serviceClient);

            Assert.Equal(2, fileSystem.VirtualStore.Count);

            string folderPath = fileSystem.VirtualStore.Keys.First();
            Assert.Equal("Folder", fileSystem.VirtualStore[folderPath].ToString());

            JObject expectedJSON = JObject.Parse(expectedJsonString);

            string fileContents = fileSystem.VirtualStore[fileSystem.VirtualStore.Keys.Skip(1).First()].ToString();
            JObject actualJson = JObject.Parse(fileContents);

            Assert.Equal(expectedJSON, actualJson);
        }
Exemplo n.º 2
0
        internal static MemoryFileSystem GenerateCodeInto(this string inputFile, MemoryFileSystem fileSystem )
        {
            fileSystem.Copy(Path.Combine("Resource", inputFile));

            var settings = new Settings
            {
                Modeler = "Swagger",
                CodeGenerator = "CSharp",
                FileSystem = fileSystem,
                OutputDirectory = "GeneratedCode",
                Input = inputFile,
            };

            var codeGenerator = new CSharpCodeGenerator(settings);
            Modeler modeler = ExtensionsLoader.GetModeler(settings);
            var sc = modeler.Build();
            codeGenerator.NormalizeClientModel(sc);
            codeGenerator.Generate(sc).GetAwaiter().GetResult();

            return fileSystem;
        }
Exemplo n.º 3
0
 protected MemoryFileSystem CreateMockFilesystem()
 {
     var fs = new MemoryFileSystem();
     fs.Copy(Path.Combine("Resource", "AutoRest.json"));
     return fs;
 }