Пример #1
0
 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, "Models"), _fileSystem.VirtualStore.Keys);
 }
Пример #2
0
 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, "Models", "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());
 }
Пример #3
0
 public void MissingParameterThrowsException()
 {
     var settings = Settings.Create(new[] {"-Modeler", "foo"});
     try
     {
         var codeGenerator = new SampleCodeGenerator(settings);
         settings.Validate();
         Assert.True(false);
     }
     catch (CodeGenerationException e)
     {
         Assert.NotNull(e.InnerExceptions);
         Assert.Equal(1, e.InnerExceptions.Count);
         Assert.True(e.InnerExceptions.Any(i =>
             i.Message.Equals(string.Format("Parameter '{0}' is required.", "Input"))));
     }
 }
Пример #4
0
        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"));
        }