예제 #1
0
        public void ScriptOnly_OnSuccess_Execute_WritesOnlyScriptContent_ToStandardOutput()
        {
            // Arrange
            const string scriptContent   = "script content only";
            var          serviceProvider = CreateServiceProvider(
                new TestProgrammingPlatform(scriptContent),
                scriptOnly: true);
            var scriptCommand = new BuildScriptCommand();
            var testConsole   = new TestConsole(newLineCharacter: string.Empty);

            // Act
            var exitCode = scriptCommand.Execute(serviceProvider, testConsole);

            // Assert
            Assert.Equal(0, exitCode);
            Assert.Contains(scriptContent, testConsole.StdOutput);
            Assert.Equal(string.Empty, testConsole.StdError);
        }
예제 #2
0
        public void OnExecute_ShowsHelp_AndExits_WhenSourceDirectoryDoesNotExist()
        {
            // Arrange
            var scriptCommand = new BuildScriptCommand
            {
                SourceDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())
            };
            var testConsole = new TestConsole();

            // Act
            var exitCode = scriptCommand.OnExecute(new CommandLineApplication(testConsole), testConsole);

            // Assert
            Assert.NotEqual(0, exitCode);
            var error = testConsole.StdError;

            Assert.DoesNotContain("Usage:", error);
            Assert.Contains("Could not find the source directory", error);
        }
예제 #3
0
        public void ScriptOnly_OnSuccess_GeneratesScript_ReplacingCRLF_WithLF()
        {
            // Arrange
            const string scriptContentWithCRLF = "#!/bin/bash\r\necho Hello\r\necho World\r\n";
            var          expected        = scriptContentWithCRLF.Replace("\r\n", "\n");
            var          serviceProvider = CreateServiceProvider(
                new TestProgrammingPlatform(scriptContentWithCRLF),
                scriptOnly: true);
            var scriptCommand = new BuildScriptCommand();
            var testConsole   = new TestConsole(newLineCharacter: string.Empty);

            // Act
            var exitCode = scriptCommand.Execute(serviceProvider, testConsole);

            // Assert
            Assert.Equal(0, exitCode);
            Assert.Contains(expected, testConsole.StdOutput);
            Assert.Equal(string.Empty, testConsole.StdError);
        }
예제 #4
0
        public void BuildScripts()
        {
            CommandModel config = new CommandModel();

            config.PluginType = "BuildScript";
            config.Settings   = new List <CommandSettingModel>()
            {
                new CommandSettingModel()
                {
                    Name  = "TempScriptDirectory",
                    Value = "src1/sql"
                },
                new CommandSettingModel()
                {
                    Name  = "ProviderName",
                    Value = ProviderName
                },
                new CommandSettingModel()
                {
                    Name  = "ConnectionString",
                    Value = ConnectionString
                },
                new CommandSettingModel()
                {
                    Name  = "TablePrefix",
                    Value = "TEST_BUILD"
                }
            };
            ISettingStore  settings = new SettingStore(config, null);
            IDataStore     data     = new DataStore();
            IPluginCommand cmd      = new BuildScriptCommand(settings, data);
            bool           res      = cmd.Execute();

            Assert.IsTrue(res);

            List <string> scripts = data.GetValue <List <string> >("ScriptsToApply");

            Assert.AreEqual(2, scripts.Count);

            Assert.IsTrue(scripts[0].EndsWith("script2.sql"));
            Assert.IsTrue(scripts[1].EndsWith("script3.sql"));
        }
예제 #5
0
        public void ScriptOnly_OnSuccess_Execute_WritesOnlyScriptContent_ToStandardOutput()
        {
            // Arrange
            const string scriptContent   = "script content only";
            var          serviceProvider = CreateServiceProvider(
                new TestProgrammingPlatform("test", new[] { "1.0.0" }, true, scriptContent,
                                            new TestLanguageDetectorUsingLangName(
                                                detectedLanguageName: "test",
                                                detectedLanguageVersion: "1.0.0")),
                scriptOnly: true);
            var scriptCommand = new BuildScriptCommand();
            var testConsole   = new TestConsole(newLineCharacter: string.Empty);

            // Act
            var exitCode = scriptCommand.Execute(serviceProvider, testConsole);

            // Assert
            Assert.Equal(0, exitCode);
            Assert.Contains(scriptContent, testConsole.StdOutput);
            Assert.Equal(string.Empty, testConsole.StdError);
        }
예제 #6
0
        public void ScriptOnly_OnSuccess_GeneratesScript_ReplacingCRLF_WithLF()
        {
            // Arrange
            const string scriptContentWithCRLF = "#!/bin/bash\r\necho Hello\r\necho World\r\n";
            var          serviceProvider       = CreateServiceProvider(
                new TestProgrammingPlatform("test", new[] { "1.0.0" }, true, scriptContentWithCRLF,
                                            new TestLanguageDetectorUsingLangName(
                                                detectedLanguageName: "test",
                                                detectedLanguageVersion: "1.0.0")),
                scriptOnly: true);
            var scriptCommand = new BuildScriptCommand();
            var testConsole   = new TestConsole(newLineCharacter: string.Empty);

            // Act
            var exitCode = scriptCommand.Execute(serviceProvider, testConsole);

            // Assert
            Assert.Equal(0, exitCode);
            Assert.Contains(scriptContentWithCRLF.Replace("\r\n", "\n"), testConsole.StdOutput);
            Assert.Equal(string.Empty, testConsole.StdError);
        }