Exemple #1
0
        public void BuildTaskRunAsync()
        {
            var task   = new BuildTask("ping.exe localhost -n 1");
            var writer = new Mock.MockBuildOutputWriter();
            var env    = new BuildEnvironment("c:\\temp", writer);

            var result = task.RunAsync(env).Result;
            var output = writer.StringWriter.ToString();

            Assert.IsTrue(result.Success);
            Assert.AreEqual(0, result.ExitCode);
            Assert.IsTrue(output.Contains("Ping statistics"));
        }
Exemple #2
0
        public void BuildTaskRunAsyncWithCustomExitCode()
        {
            var task   = new BuildTask("ping.exe -foobar");
            var writer = new Mock.MockBuildOutputWriter();
            var env    = new BuildEnvironment("c:\\temp", writer);

            task.SuccessfulExitCodes = new int[] { 0, 1 };

            var result = task.RunAsync(env).Result;
            var output = writer.StringWriter.ToString();

            Assert.IsTrue(result.Success);
            Assert.AreEqual(1, result.ExitCode);
        }
Exemple #3
0
        public void BuildEnvironmentStartProcessCapturesStandardOutput()
        {
            var    writer    = new Mock.MockBuildOutputWriter();
            string testToken = "Reply from";

            using (var te = new BuildEnvironment("C:\\Build", writer))
            {
                var processResult = te.StartProcessAsync("cmd.exe", $"/c ping localhost -n 2");

                var resultCode = processResult.Result;
                Assert.IsTrue(processResult.IsCompleted);
                Assert.AreEqual(0, resultCode);
            }

            Assert.IsTrue(writer.StringWriter.ToString().Contains(testToken));
        }
Exemple #4
0
        public void BuildEnvironmentStartProcessCapturesStandardError()
        {
            var    writer    = new Mock.MockBuildOutputWriter();
            string testToken = "SuperDuperTokenTest";

            using (var te = new BuildEnvironment("C:\\Build", writer))
            {
                var processResult = te.StartProcessAsync("cmd.exe", $"/c echo {testToken} 1>&2");
                var resultCode    = processResult.Result;

                Assert.IsTrue(processResult.IsCompleted);
                Assert.AreEqual(0, resultCode);
            }

            Assert.IsTrue(writer.StringWriter.ToString().Contains(testToken));
        }
        public void RunsAllTasksExtension()
        {
            var writer = new Mock.MockBuildOutputWriter();
            var env    = new BuildEnvironment("C:\\BUILD", writer);
            var tasks  = new List <Mock.MockBuildTask>();

            tasks.Add(new Mock.MockBuildTask());
            tasks.Add(new Mock.MockBuildTask());
            tasks.Add(new Mock.MockBuildTask());

            var result = tasks.RunAllAsync(env).Result;

            Assert.IsTrue(result.Success);
            Assert.IsTrue(tasks.All(x => x.RunAsAsyncCalled));
            Assert.IsTrue(tasks.All(x => x.RunAsAsyncEnvironmentArg == env));
        }
Exemple #6
0
        public void BuildTaskReplacesVariableTokensCaseInsensative()
        {
            var    writer          = new Mock.MockBuildOutputWriter();
            string testTokenValue1 = "SomeTokenValue";
            string testTokenValue2 = "AnotherTokenValue";

            using (var te = new BuildEnvironment("C:\\Build", writer))
            {
                te.Variables.Add("fOO", testTokenValue1);
                te.Variables.Add("bAr", testTokenValue2);

                var task = new BuildTask("echo ${foo} and ${Bar}").RunAsync(te);

                Assert.IsTrue(task.Result.Success);
                Assert.IsTrue(writer.StringWriter.ToString().Contains(testTokenValue1));
                Assert.IsTrue(writer.StringWriter.ToString().Contains(testTokenValue2));
            }
        }
Exemple #7
0
        public void TestStartProcessCreatesEnvironmentVariables()
        {
            var writer = new Mock.MockBuildOutputWriter()
            {
                PrefixSeverity = false
            };

            var agentOptions = new BuildAgentOptions()
            {
                AgentIdentifier  = "AgentID",
                ConcurrentBuilds = 1,
                WorkingPath      = "WorkingPath"
            };

            var codeInfo = new CodeRepositoryInfo()
            {
                Author             = "Author",
                RevisionIdentifier = "RevIdent"
            };

            var buildEntry = new BuildQueueEntry()
            {
                BuildNumber = 999
            };

            var project = new BuildProjectConfiguration()
            {
                ProjectID      = Guid.NewGuid(),
                Name           = "TestProject",
                RepositoryType = "svn",
                RepositoryPath = "repo-path",
                Variables      = new Dictionary <string, string>()
                {
                    { "VarTest", "123" }
                }
            };

            using (var env = new BuildEnvironment("C:\\Build", writer))
            {
                env.AddAgentVariables(agentOptions);
                env.AddCodeInfoVariables(codeInfo);
                env.AddGlobalVariables();
                env.AddQueueEntryVariables(buildEntry);
                env.AddProjectConfigurationVariables(project);

                var resultCode = env.StartProcessAsync("cmd.exe", "/c set").Result;

                Assert.AreEqual(0, resultCode);
            }

            var vars = new Dictionary <string, string>();

            using (var reader = new System.IO.StringReader(writer.StringWriter.ToString()))
            {
                string line;
                while (true)
                {
                    line = reader.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    var parts = line.Split(new char[] { '=' }, 2);

                    vars.Add(parts[0], parts[1]);
                }
            }

            Assert.AreEqual("true", vars["CI"]);
            Assert.AreEqual("C:\\Build", vars["CI_WORKINGPATH"]);

            Assert.AreEqual(Environment.MachineName, vars["CI_AGENTHOST"]);
            Assert.AreEqual(agentOptions.AgentIdentifier, vars["CI_AGENTIDENTIFIER"]);

            Assert.AreEqual(codeInfo.RevisionIdentifier, vars["CI_REVISIONIDENTIFIER"]);
            Assert.AreEqual(codeInfo.Author, vars["CI_REVISIONAUTHOR"]);

            Assert.IsNotNull(vars["CI_BUILDDATE"]);
            Assert.IsNotNull(vars["CI_BUILDDATETIME"]);

            Assert.AreEqual(project.NextBuildNumber, int.Parse(vars["CI_BUILDNUMBER"]));

            Assert.AreEqual(project.ProjectID.ToString(), vars["CI_PROJECTID"]);
            Assert.AreEqual(project.Name, vars["CI_PROJECTNAME"]);
            Assert.AreEqual(project.RepositoryType, vars["CI_REPOSITORYTYPE"]);
            Assert.AreEqual(project.RepositoryPath, vars["CI_REPOSITORYPATH"]);
            Assert.AreEqual(project.Variables["VarTest"], vars["CI_VARTEST"]);
        }