public void OnExecuteAsync_Should_NotThrow(
            IConsoleOutput console,
            IAutoRestOptions options,
            IProcessLauncher processLauncher,
            IProgressReporter progressReporter,
            IAutoRestCodeGeneratorFactory factory,
            ICodeGenerator generator,
            IOpenApiDocumentFactory documentFactory,
            string outputFile,
            string code)
        {
            var sut = new AutoRestCommand(
                console,
                options,
                processLauncher,
                progressReporter,
                factory,
                documentFactory)
            {
                OutputFile = outputFile
            };

            Mock.Get(generator).Setup(c => c.GenerateCode(progressReporter)).Returns(code);
            new Func <int>(sut.OnExecute).Should().NotThrow();
        }
 public async Task OnExecuteAsync_Should_Create_Generator(
     IConsoleOutput console,
     IAutoRestOptions options,
     IProcessLauncher processLauncher,
     IProgressReporter progressReporter,
     IAutoRestCodeGeneratorFactory factory,
     IOpenApiDocumentFactory documentFactory,
     string swaggerFile)
 => await new AutoRestCommand(
     console,
     options,
     processLauncher,
     progressReporter,
     factory,
     documentFactory)
 {
     SwaggerFile = swaggerFile
 }
 .OnExecuteAsync()
 .ContinueWith(
     t => Mock.Get(factory)
     .Verify(
         c => c.Create(
             swaggerFile,
             "GeneratedCode",
             options,
             processLauncher,
             documentFactory)));
        public void OnExecute_Should_Create_Generator(
            IConsoleOutput console,
            IAutoRestOptions options,
            IProcessLauncher processLauncher,
            IProgressReporter progressReporter,
            IAutoRestCodeGeneratorFactory factory,
            IOpenApiDocumentFactory documentFactory,
            string swaggerFile)
        {
            new AutoRestCommand(
                console,
                options,
                processLauncher,
                progressReporter,
                factory,
                documentFactory)
            {
                SwaggerFile = swaggerFile
            }
            .OnExecute();

            Mock.Get(factory)
            .Verify(
                c => c.Create(
                    swaggerFile,
                    "GeneratedCode",
                    options,
                    processLauncher,
                    documentFactory));
        }
        public void OnExecuteAsync_Should_NotThrow(
            IConsoleOutput console,
            IProgressReporter progressReporter,
            IOpenApiDocumentFactory openApiDocumentFactory,
            INSwagOptions options,
            INSwagCodeGeneratorFactory codeGeneratorFactory,
            ICodeGenerator generator,
            string outputFile,
            string code)
        {
            var sut = new NSwagCommand(
                console,
                progressReporter,
                openApiDocumentFactory,
                options,
                codeGeneratorFactory);

            sut.OutputFile = outputFile;

            Mock.Get(generator)
            .Setup(c => c.GenerateCode(progressReporter))
            .Returns(code);

            new Func <int>(sut.OnExecute).Should().NotThrow();
        }
Esempio n. 5
0
 public CodeGeneratorFactory(
     IOptionsFactory optionsFactory          = null,
     IProcessLauncher processLauncher        = null,
     IOpenApiDocumentFactory documentFactory = null)
 {
     this.optionsFactory  = optionsFactory ?? new OptionsFactory();
     this.processLauncher = processLauncher ?? new ProcessLauncher();
     this.documentFactory = documentFactory ?? new OpenApiDocumentFactory();
 }
Esempio n. 6
0
 public ICodeGenerator Create(
     string swaggerFile,
     string defaultNamespace,
     INSwagOptions options,
     IOpenApiDocumentFactory documentFactory)
 => new NSwagCSharpCodeGenerator(
     swaggerFile,
     documentFactory,
     new NSwagCodeGeneratorSettingsFactory(defaultNamespace, options));
 private void ArrangeOpenApiDocumentFactory(
     IOpenApiDocumentFactory factory,
     string swaggerFile = null)
 {
     Mock.Get(factory)
     .Setup(
         c => c.GetDocumentAsync(
             It.IsAny <string>()))
     .Returns(OpenApiDocument.FromFileAsync(swaggerFile ?? SwaggerJsonFilename));
 }
Esempio n. 8
0
 public NSwagSingleFileCustomTool(
     INSwagCodeGeneratorFactory factory,
     IOpenApiDocumentFactory openApiDocumentFactory,
     INSwagOptions options)
 {
     this.factory = factory ?? throw new ArgumentNullException(nameof(factory));
     this.openApiDocumentFactory = openApiDocumentFactory ??
                                   throw new ArgumentNullException(nameof(openApiDocumentFactory));
     this.options = options ?? throw new ArgumentNullException(nameof(options));
 }
 public NSwagCSharpCodeGenerator(
     string swaggerFile,
     IOpenApiDocumentFactory documentFactory,
     INSwagCodeGeneratorSettingsFactory generatorSettingsFactory)
 {
     this.swaggerFile              = swaggerFile ?? throw new ArgumentNullException(nameof(swaggerFile));
     this.documentFactory          = documentFactory ?? throw new ArgumentNullException(nameof(documentFactory));
     this.generatorSettingsFactory = generatorSettingsFactory ??
                                     throw new ArgumentNullException(nameof(generatorSettingsFactory));
 }
 public AutoRestSingleFileCustomTool(
     IAutoRestCodeGeneratorFactory factory,
     IAutoRestOptions options,
     IProcessLauncher processLauncher,
     IOpenApiDocumentFactory documentFactory)
 {
     this.factory         = factory ?? throw new ArgumentNullException(nameof(factory));
     this.options         = options ?? throw new ArgumentNullException(nameof(options));
     this.processLauncher = processLauncher ?? throw new ArgumentNullException(nameof(processLauncher));
     this.documentFactory = documentFactory ?? throw new ArgumentNullException(nameof(documentFactory));
 }
Esempio n. 11
0
 public CodeGeneratorFactory(
     IOptionsFactory optionsFactory          = null,
     IProcessLauncher processLauncher        = null,
     IOpenApiDocumentFactory documentFactory = null,
     IRemoteLogger remoteLogger = null)
 {
     this.optionsFactory  = optionsFactory ?? new OptionsFactory();
     this.processLauncher = processLauncher ?? new ProcessLauncher();
     this.documentFactory = documentFactory ?? new OpenApiDocumentFactory();
     this.remoteLogger    = remoteLogger ?? Logger.Instance;
 }
Esempio n. 12
0
 public AutoRestCSharpCodeGenerator(
     string swaggerFile,
     string defaultNamespace,
     IAutoRestOptions options,
     IProcessLauncher processLauncher,
     IOpenApiDocumentFactory documentFactory)
     : base(swaggerFile, defaultNamespace, processLauncher)
 {
     this.options         = options ?? throw new ArgumentNullException(nameof(options));
     this.documentFactory = documentFactory ?? throw new ArgumentNullException(nameof(documentFactory));
 }
 public NSwagCommand(
     IConsoleOutput console,
     IProgressReporter progressReporter,
     IOpenApiDocumentFactory openApiDocumentFactory,
     INSwagOptions options,
     INSwagCodeGeneratorFactory codeGeneratorFactory)
     : base(console, progressReporter)
 {
     this.openApiDocumentFactory = openApiDocumentFactory ?? throw new ArgumentNullException(nameof(openApiDocumentFactory));
     this.options = options ?? throw new ArgumentNullException(nameof(options));
     this.codeGeneratorFactory = codeGeneratorFactory ?? throw new ArgumentNullException(nameof(codeGeneratorFactory));
 }
Esempio n. 14
0
 public ICodeGenerator Create(
     string swaggerFile,
     string defaultNamespace,
     IAutoRestOptions options,
     IProcessLauncher processLauncher,
     IOpenApiDocumentFactory documentFactory)
 => new AutoRestCSharpCodeGenerator(
     swaggerFile,
     defaultNamespace,
     options,
     processLauncher,
     documentFactory);
Esempio n. 15
0
 public void Create_Should_Return_NotNull(
     NSwagCodeGeneratorFactory sut,
     string swaggerFile,
     string defaultNamespace,
     INSwagOptions options,
     IOpenApiDocumentFactory documentFactory)
 => sut.Create(
     swaggerFile,
     defaultNamespace,
     options,
     documentFactory)
 .Should()
 .NotBeNull();
 public AutoRestCommand(
     IConsoleOutput console,
     IAutoRestOptions options,
     IProcessLauncher processLauncher,
     IProgressReporter progressReporter,
     IAutoRestCodeGeneratorFactory factory,
     IOpenApiDocumentFactory documentFactory) : base(console, progressReporter)
 {
     this.options         = options ?? throw new ArgumentNullException(nameof(options));
     this.processLauncher = processLauncher ?? throw new ArgumentNullException(nameof(processLauncher));
     this.factory         = factory ?? throw new ArgumentNullException(nameof(factory));
     this.documentFactory = documentFactory ?? throw new ArgumentNullException(nameof(documentFactory));
 }
 public void Updates_Progress(
     [Frozen] IOpenApiDocumentFactory factory,
     AutoRestCSharpCodeGenerator sut,
     IProgressReporter progress)
 {
     ArrangeOpenApiDocumentFactory(factory);
     sut.GenerateCode(progress);
     Mock.Get(progress)
     .Verify(
         c => c.Progress(
             It.IsAny <uint>(),
             It.IsAny <uint>()),
         Times.Exactly(5));
 }
Esempio n. 18
0
 public ICodeGenerator Create(
     string swaggerFile,
     string defaultNamespace,
     IAutoRestOptions options,
     IProcessLauncher processLauncher,
     IOpenApiDocumentFactory factory,
     IDependencyInstaller dependencyInstaller)
 => new AutoRestCSharpCodeGenerator(
     swaggerFile,
     defaultNamespace,
     options,
     processLauncher,
     factory,
     dependencyInstaller);
 public void Parses_OpenApi_v3(
     [Frozen] IOpenApiDocumentFactory factory,
     AutoRestCSharpCodeGenerator sut,
     IProgressReporter progress)
 {
     ArrangeOpenApiDocumentFactory(factory, SwaggerV3JsonFilename);
     sut.GenerateCode(progress);
     Mock.Get(progress)
     .Verify(
         c => c.Progress(
             It.IsAny <uint>(),
             It.IsAny <uint>()),
         Times.Exactly(5));
 }
 public void Create_Should_Return_NotNull(
     AutoRestCodeGeneratorFactory sut,
     string swaggerFile,
     string defaultNamespace,
     IAutoRestOptions options,
     IProcessLauncher processLauncher,
     IOpenApiDocumentFactory documentFactory)
 => sut.Create(
     swaggerFile,
     defaultNamespace,
     options,
     processLauncher,
     documentFactory)
 .Should()
 .NotBeNull();
Esempio n. 21
0
 public AutoRestCSharpCodeGenerator(
     string swaggerFile,
     string defaultNamespace,
     IAutoRestOptions options,
     IProcessLauncher processLauncher,
     IOpenApiDocumentFactory documentFactory,
     IDependencyInstaller dependencyInstaller,
     IAutoRestArgumentProvider argumentProvider = null)
 {
     SwaggerFile              = swaggerFile;
     DefaultNamespace         = defaultNamespace;
     this.processLauncher     = processLauncher;
     this.documentFactory     = documentFactory ?? throw new ArgumentNullException(nameof(documentFactory));
     this.dependencyInstaller = dependencyInstaller ?? throw new ArgumentNullException(nameof(dependencyInstaller));
     this.argumentProvider    = argumentProvider ?? new AutoRestArgumentProvider(options);
 }
 public CodeGeneratorFactory(
     IOptionsFactory optionsFactory          = null,
     IProcessLauncher processLauncher        = null,
     IOpenApiDocumentFactory documentFactory = null,
     IRemoteLogger remoteLogger = null,
     IDependencyInstaller dependencyInstaller = null)
 {
     this.remoteLogger        = remoteLogger ?? Logger.Instance;
     this.optionsFactory      = optionsFactory ?? new OptionsFactory();
     this.processLauncher     = processLauncher ?? new ProcessLauncher();
     this.documentFactory     = documentFactory ?? new OpenApiDocumentFactory();
     this.dependencyInstaller = dependencyInstaller ??
                                new DependencyInstaller(
         new NpmInstaller(this.processLauncher),
         new FileDownloader(new WebDownloader()));
 }
 public void Constructor_Should_Throw_On_Null_IAutoRestCodeGeneratorFactory(
     IConsoleOutput console,
     IAutoRestOptions options,
     IProcessLauncher processLauncher,
     IProgressReporter progressReporter,
     IOpenApiDocumentFactory documentFactory)
 => new Action(
     () => new AutoRestCommand(
         console,
         options,
         processLauncher,
         progressReporter,
         null,
         documentFactory))
 .Should()
 .ThrowExactly <ArgumentNullException>();
        public void Tries_Again_Upon_ProcessLaunchException_For_OpenApi_v2(
            [Frozen] IOpenApiDocumentFactory factory,
            [Frozen] IProcessLauncher processLauncher,
            [Frozen] IAutoRestArgumentProvider argumentProvider,
            AutoRestCSharpCodeGenerator sut,
            IProgressReporter progress,
            ProcessLaunchException exception,
            string arguments)
        {
            arguments += "--version=[some version]";

            Mock.Get(processLauncher)
            .Setup(
                c => c.Start(
                    It.IsAny <string>(),
                    arguments,
                    It.IsAny <string>()))
            .Throws(exception);

            Mock.Get(argumentProvider)
            .Setup(
                c => c.GetLegacyArguments(
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>()))
            .Returns(arguments);

            ArrangeOpenApiDocumentFactory(factory);
            sut.GenerateCode(progress);

            Mock.Get(processLauncher)
            .Verify(
                c => c.Start(
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>()),
                Times.Exactly(2));
        }