Exemple #1
0
        public void HandleCommandLineOptions_ConfigFileDoesntExistWithForceParam_ShouldCreateFile()
        {
            // arrange
            var mockReporter = Substitute.For <IBaseReporter>();

            mockReporter.Report(Arg.Any <string>());

            var mockConfigFileGenerator = Substitute.For <IConfigFileGenerator>();

            mockConfigFileGenerator.WriteConfigFile(Arg.Any <string>());

            var mockCommandLineOptions = Substitute.For <ICommandLineOptions>();

            mockCommandLineOptions.Init  = true;
            mockCommandLineOptions.Force = true;

            var mockFileSystem = new MockFileSystem();
            var configFilePath = mockFileSystem.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @".tsqllintrc");

            var testCreateConfigFileStrategy = new CreateConfigFileStrategy(mockReporter, mockConfigFileGenerator, mockFileSystem);

            // act
            testCreateConfigFileStrategy.HandleCommandLineOptions(mockCommandLineOptions);

            // assert
            mockConfigFileGenerator.Received().WriteConfigFile(Arg.Is <string>(x => x == configFilePath));
        }
Exemple #2
0
        public void HandleCommandLineOptions_ConfigFileExistsNoForceParam_ShouldReportError()
        {
            // arrange
            var mockReporter = Substitute.For <IBaseReporter>();

            mockReporter.Report(Arg.Any <string>());

            var mockConfigFileGenerator = Substitute.For <IConfigFileGenerator>();

            var mockCommandLineOptions = Substitute.For <ICommandLineOptions>();

            mockCommandLineOptions.Init = true;

            var mockFileSystem = new MockFileSystem();
            var configFilePath = mockFileSystem.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @".tsqllintrc");

            mockFileSystem.AddFile(configFilePath, new MockFileData(string.Empty));

            var testCreateConfigFileStrategy = new CreateConfigFileStrategy(mockReporter, mockConfigFileGenerator, mockFileSystem);

            // act
            testCreateConfigFileStrategy.HandleCommandLineOptions(mockCommandLineOptions);

            // assert
            mockReporter.Received().Report(Arg.Is <string>(x => x.Contains("Default config file already exists at")));
        }
Exemple #3
0
        public void HandleCommandLineOptions_ConfigFileDoesntExistWithForceParam_ShouldCreateFile()
        {
            // arrange
            var mockReporter = Substitute.For <IBaseReporter>();

            mockReporter.Report(Arg.Any <string>());

            var mockConfigFileGenerator = Substitute.For <IConfigFileGenerator>();

            mockConfigFileGenerator.WriteConfigFile(Arg.Any <string>());

            var mockCommandLineOptions = Substitute.For <ICommandLineOptions>();

            mockCommandLineOptions.Init  = true;
            mockCommandLineOptions.Force = true;

            var          userprofilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            const string filename        = @".tsqllintrc";
            var          configFilePath  = Path.Combine(userprofilePath, filename);

            var fileSystemWrapper = Substitute.For <IFileSystemWrapper>();

            fileSystemWrapper.CombinePath(Arg.Is <string>(x => x == userprofilePath), Arg.Is <string>(x => x == filename)).Returns(configFilePath);
            fileSystemWrapper.FileExists(Arg.Is <string>(x => x == configFilePath)).Returns(false);

            var testCreateConfigFileStrategy = new CreateConfigFileStrategy(mockReporter, mockConfigFileGenerator, fileSystemWrapper);

            // act
            testCreateConfigFileStrategy.HandleCommandLineOptions(mockCommandLineOptions);

            // assert
            mockConfigFileGenerator.Received().WriteConfigFile(Arg.Is <string>(x => x == configFilePath));
        }
        public HandlerResponseMessage Handle(CommandLineRequestMessage request)
        {
            if (request.CommandLineOptions.Args.Length == 0)
            {
                var strategy = new PrintUsageStrategy(reporter);
                strategy.HandleCommandLineOptions(request.CommandLineOptions);
                return(new HandlerResponseMessage(false, false));
            }

            if (request.CommandLineOptions.Help)
            {
                var strategy = new PrintUsageStrategy(reporter);
                return(strategy.HandleCommandLineOptions(request.CommandLineOptions));
            }

            if (request.CommandLineOptions.Version)
            {
                var strategy = new PrintVersionStrategy(reporter);
                return(strategy.HandleCommandLineOptions());
            }

            if (request.CommandLineOptions.PrintConfig)
            {
                var strategy = new PrintConfigStrategy(reporter, configReader);
                return(strategy.HandleCommandLineOptions(request.CommandLineOptions));
            }

            if (!string.IsNullOrWhiteSpace(request.CommandLineOptions.ConfigFile))
            {
                var strategy = new LoadConfigFileStrategy(reporter, fileSystemWrapper);
                return(strategy.HandleCommandLineOptions(request.CommandLineOptions));
            }

            if (request.CommandLineOptions.Init)
            {
                var strategy = new CreateConfigFileStrategy(reporter, configFileGenerator, fileSystemWrapper);
                return(strategy.HandleCommandLineOptions(request.CommandLineOptions));
            }

            if (request.CommandLineOptions.ListPlugins)
            {
                var strategy = new PrintPluginsStrategy(reporter, configReader);
                return(strategy.HandleCommandLineOptions(request.CommandLineOptions));
            }

            if (request.CommandLineOptions.LintPath.Any())
            {
                var strategy = new ValidatePathStrategy(reporter, fileSystemWrapper);
                return(strategy.HandleCommandLineOptions(request.CommandLineOptions));
            }
            else
            {
                var strategy = new PrintUsageStrategy(reporter);
                return(strategy.HandleCommandLineOptions(request.CommandLineOptions));
            }
        }
Exemple #5
0
 public void HandleCommandLineOptions(CommandLineOptions commandLineOptions)
 {
     if (commandLineOptions.Args.Length == 0 || commandLineOptions.Help)
     {
         var strategy = new PrintUsageStrategy(reporter);
         strategy.HandleCommandLineOptions(commandLineOptions);
     }
     else if (commandLineOptions.Version)
     {
         var strategy = new PrintVersionStrategy(reporter);
         strategy.HandleCommandLineOptions();
     }
     else if (commandLineOptions.PrintConfig)
     {
         var strategy = new PrintConfigStrategy(reporter, configReader);
         strategy.HandleCommandLineOptions(commandLineOptions);
     }
     else if (!string.IsNullOrWhiteSpace(commandLineOptions.ConfigFile))
     {
         var strategy = new LoadConfigFileStrategy(reporter);
         strategy.HandleCommandLineOptions(commandLineOptions);
     }
     else if (commandLineOptions.Init)
     {
         var strategy = new CreateConfigFileStrategy(reporter, configFileGenerator);
         strategy.HandleCommandLineOptions(commandLineOptions);
     }
     else if (this.commandLineOptions.ListPlugins)
     {
         var strategy = new PrintPluginsStrategy(reporter, configReader);
         strategy.HandleCommandLineOptions(commandLineOptions);
     }
     else if (!this.commandLineOptions.LintPath.Any())
     {
         var strategy = new PrintUsageStrategy(reporter);
         strategy.HandleCommandLineOptions(commandLineOptions);
     }
 }