예제 #1
0
        public void ScriptOnly_OnSuccess_Execute_WritesOnlyScriptContent_ToFile()
        {
            // 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);

            var outputDirectory = _testDir.CreateChildDir();
            var scriptPath      = Path.Join(outputDirectory, "build.sh");

            scriptCommand.OutputPath = scriptPath;

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

            // Assert
            Assert.Equal(0, exitCode);
            Assert.Contains("Script written to", testConsole.StdOutput);
            Assert.Equal(string.Empty, testConsole.StdError);

            var outputFileContent = File.ReadAllText(scriptPath);

            Assert.Contains(scriptContent, outputFileContent);
        }
예제 #2
0
        public void ScriptOnly_OnSuccess_Execute_WritesOnlyScriptContent_ToStandardOutput()
        {
            // Arrange
            const string scriptContent   = "script content only";
            var          serviceProvider = CreateServiceProvider(
                new TestProgrammingPlatform(
                    platformName: "test",
                    platformVersions: new[] { "1.0.0" },
                    canGenerateScript: true,
                    scriptContent: scriptContent,
                    detector: new TestPlatformDetectorUsingPlatformName(
                        detectedPlatformName: "test",
                        detectedPlatformVersion: "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);
        }
예제 #3
0
        public void ScriptOnly_OnSuccess_GenerateScript_ReplacingCRLF_WithLF_ToFile()
        {
            // 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);

            var outputDirectory = _testDir.CreateChildDir();
            var scriptPath      = Path.Join(outputDirectory, "build.sh");

            scriptCommand.OutputPath = scriptPath;

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

            // Assert
            Assert.Equal(0, exitCode);
            Assert.Contains("Script written to", testConsole.StdOutput);
            Assert.Equal(string.Empty, testConsole.StdError);

            var outputFileContent = File.ReadAllText(scriptPath);

            Assert.Contains(scriptContentWithCRLF.Replace("\r\n", "\n"), outputFileContent);
        }
예제 #4
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(
                    platformName: "test",
                    platformVersions: new[] { "1.0.0" },
                    canGenerateScript: true,
                    scriptContent: scriptContentWithCRLF,
                    detector: new TestPlatformDetectorUsingPlatformName(
                        detectedPlatformName: "test",
                        detectedPlatformVersion: "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);
        }
예제 #5
0
        public void BuildActualScripts()
        {
            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"
                },
                new CommandSettingModel()
                {
                    Name  = "ActualScriptFileName",
                    Value = "log/NotAppliedScripts.txt"
                }
            };
            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"));

            string actScriptPath = "src1/sql/log/NotAppliedScripts.txt";

            Assert.IsTrue(File.Exists(actScriptPath));

            //string expectedScript = GetExpectedScript();
            //string actScript = File.ReadAllText(actScriptPath);
            //Assert.AreEqual(expectedScript, actScript);
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
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"));
        }