Example #1
0
        public void OutputToSingleFile()
        {
            using (NewContext)
            {
                var settings = new Settings
                {
                    Modeler         = "Swagger",
                    CodeGenerator   = "CSharp",
                    Input           = "RedisResource.json",
                    FileSystem      = _fileSystem,
                    OutputDirectory = Path.GetTempPath(),
                    OutputFileName  = "test.file.cs"
                };

                string path             = Path.Combine(settings.OutputDirectory, "test.file.cs");
                string existingContents = "this is dummy";
                _fileSystem.VirtualStore[path] = new StringBuilder(existingContents);
                var codeGenerator = new SampleCodeGenerator();
                codeGenerator.Generate(New <CodeModel>()).GetAwaiter().GetResult();
                Assert.DoesNotContain(existingContents, _fileSystem.VirtualStore[path].ToString());
                Assert.Equal(4, _fileSystem.VirtualStore.Count);
                Assert.True(_fileSystem.VirtualStore.ContainsKey(path));
                Assert.True(_fileSystem.VirtualStore.ContainsKey("AutoRest.json"));
                Assert.True(_fileSystem.VirtualStore.ContainsKey("RedisResource.json"));
            }
        }
        public void CodeWriterCreatesDirectory()
        {
            var settings = new Settings
            {
                CodeGenerator   = "CSharp",
                FileSystem      = _fileSystem,
                OutputDirectory = Path.GetTempPath()
            };
            SampleCodeGenerator codeGenerator = new SampleCodeGenerator(settings);

            codeGenerator.Generate(new ServiceClient()).GetAwaiter().GetResult();
            Assert.Contains(Path.Combine(settings.OutputDirectory, settings.ModelsName), _fileSystem.VirtualStore.Keys);
        }
 public void CodeWriterCreatesDirectory()
 {
     using (NewContext)
     {
         var settings = new Settings
         {
             CodeGenerator   = "CSharp",
             FileSystemInput = _fileSystemInput,
             OutputDirectory = Path.GetTempPath()
         };
         SampleCodeGenerator codeGenerator = new SampleCodeGenerator();
         codeGenerator.Generate(New <CodeModel>()).GetAwaiter().GetResult();
         Assert.Contains(Path.Combine(settings.OutputDirectory, settings.ModelsName),
                         settings.FileSystemOutput.VirtualStore.Keys);
     }
 }
        public void CodeWriterOverwritesExistingFile()
        {
            var settings = new Settings
            {
                CodeGenerator   = "CSharp",
                FileSystem      = _fileSystem,
                OutputDirectory = Path.GetTempPath()
            };
            string existingContents = "this is dummy";
            string path             = Path.Combine(settings.OutputDirectory, settings.ModelsName, "Pet.cs");

            _fileSystem.VirtualStore[path] = new StringBuilder(existingContents);
            var codeGenerator = new SampleCodeGenerator(settings);

            codeGenerator.Generate(new ServiceClient()).GetAwaiter().GetResult();
            Assert.NotEqual(existingContents, _fileSystem.VirtualStore[path].ToString());
        }
        public void OutputToSingleFile()
        {
            var settings = new Settings
            {
                Modeler         = "Swagger",
                CodeGenerator   = "CSharp",
                Input           = "RedisResource.json",
                FileSystem      = _fileSystem,
                OutputDirectory = Path.GetTempPath(),
                OutputFileName  = "test.file.cs"
            };

            string path          = Path.Combine(settings.OutputDirectory, "test.file.cs");
            var    codeGenerator = new SampleCodeGenerator(settings);

            codeGenerator.Generate(new ServiceClient()).GetAwaiter().GetResult();
            Assert.Equal(4, _fileSystem.VirtualStore.Count);
            Assert.True(_fileSystem.VirtualStore.ContainsKey(path));
            Assert.True(_fileSystem.VirtualStore.ContainsKey("AutoRest.json"));
            Assert.True(_fileSystem.VirtualStore.ContainsKey("RedisResource.json"));
        }