Пример #1
0
        public static void DefaultTaskExists(Baufile baufile, string tempFile, string output)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given a baufile with a default task"
                .f(() =>
                {
                    tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
                    baufile = Baufile.Create(scenario).WriteLine(
                        @"Require<Bau>().Do(() => File.Create(@""" + tempFile + @""").Dispose()).Run();");
                })
                .Teardown(() => File.Delete(tempFile));

            "When I execute the baufile"
                .f(() => output = baufile.Run());

            "Then the task is executed"
                .f(() => File.Exists(tempFile).Should().BeTrue());

            "And I am informed that the default task was executed"
                .f(() => output.Should().ContainEquivalentOf("starting 'default'"));

            "And I am informed about execution time"
                .f(() => output.Should().ContainEquivalentOf("finished 'default' after "));
        }
Пример #2
0
        public static void ExecutingAnInlineTask(Baufile baufile, string tempFile, string output)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given a baufile with a default task with an inline task"
                .f(() =>
                {
                    tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
                    baufile = Baufile.Create(scenario).WriteLine(
            @"Require<Bau>()
            .Do(() =>
            {
            var task = new BauTask();
            task.Actions.Add(() => File.Create(@""" + tempFile + @""").Dispose());
            task.Execute();
            })
            .Run();");
                })
                .Teardown(() => File.Delete(tempFile));

            "When I execute the baufile"
                .f(() => output = baufile.Run());

            "Then the task is executed"
                .f(() => File.Exists(tempFile).Should().BeTrue());

            "And I should not be informed that a task with no name was executed"
                .f(() => output.Should().NotContainEquivalentOf("starting ''"));
        }
Пример #3
0
        public static void ExecutingATaskFromAnotherTask(Baufile baufile, string tempFile, string[] executedTasks, string output)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given bau is required"
                .f(() => baufile = Baufile.Create(scenario).WriteLine(
            @"var executed = new List<string>();

            var bau = Require<Bau>();"));

            "And a non-default task"
                .f(c => baufile.WriteLine(
            @"bau.Task(""non-default"")
            .Do(() => executed.Add(""non-default""))"));

            "And a default task which executes the non-default task"
                .f(() =>
                {
                    tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
                    baufile.WriteLine(
            @".Task(""default"")
            .Do(() =>
            {
            bau.Execute(""non-default"");
            executed.Add(""default"");
            using(var file = File.CreateText(@""" + tempFile + @"""))
            {
            file.Write(string.Join(Environment.NewLine, executed));
            };
            })");
                })
            .Teardown(() => File.Delete(tempFile));

            "And the tasks are executed"
                .f(() => baufile.WriteLine(
            @".Run();"));

            "When I execute the baufile"
                .f(() => output = baufile.Run());

            "Then two tasks are executed"
                .f(() =>
                {
                    File.Exists(tempFile).Should().BeTrue();
                    executedTasks = File.ReadAllText(tempFile).Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    executedTasks.Length.Should().Be(2);
                });

            "And the non-default task is executed first"
                .f(() => executedTasks[0].Should().Be("non-default"));

            "And the default task is executed second"
                .f(() => executedTasks[1].Should().Be("default"));

            "And I am informed that the non-default task was executed"
                .f(() => output.Should().ContainEquivalentOf("starting 'non-default'"));

            "And I am informed that the default task was executed"
                .f(() => output.Should().ContainEquivalentOf("starting 'default'"));
        }
Пример #4
0
        public static void NonexistentTask(string tag, string code, Baufile baufile, Exception ex)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given a baufile containing {0}"
                .f(() => baufile = Baufile.Create(string.Concat(scenario, ".", tag)).WriteLine(code));

            "When I execute a non-existent task"
                .f(() => ex = Record.Exception(() => baufile.Run("non-existent")));

            "Then execution should fail"
                .f(() => ex.Should().NotBeNull());

            "And I am informed that the non-existent task was not found"
                .f(() => ex.Message.Should().ContainEquivalentOf("'non-existent' task not found"));
        }
Пример #5
0
        public static void CompilationFails(Baufile baufile, Exception ex)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given a baufile containing an unknown name"
                .f(() => baufile = Baufile.Create(scenario).WriteLine(@"x"));

            "When I execute the baufile"
                .f(() => ex = Record.Exception(() => baufile.Run()));

            "Then execution should fail"
                .f(() => ex.Should().NotBeNull());

            "And I am informed that member could not be found"
                .f(() => ex.Message.Should().ContainEquivalentOf("the name 'x' does not exist in the current context"));
        }
Пример #6
0
        public static void MultipleTasks(Baufile baufile, string tempFile1, string tempFile2, string output)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given bau is required"
                .f(() => baufile = Baufile.Create(scenario).WriteLine(
            @"var bau = Require<Bau>();"));

            "And a non-default task"
                .f(() =>
                {
                    tempFile1 = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
                    baufile.WriteLine(
            @"
            bau.Task(""non-default1"").Do(() => File.Create(@""" + tempFile1 + @""").Dispose());");
                })
                .Teardown(() => File.Delete(tempFile1));

            "And another non-default task"
                .f(() =>
                {
                    tempFile2 = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
                    baufile.WriteLine(
            @"
            bau.Task(""non-default2"").Do(() => File.Create(@""" + tempFile2 + @""").Dispose());");
                })
                .Teardown(() => File.Delete(tempFile2));
            "And the tasks are executed"
                .f(() => baufile.WriteLine(
            @"
            bau.Run();"));

            "When I execute both non-default tasks"
                .f(() => output = baufile.Run("non-default1", "non-default2"));

            "Then the first task is executed"
                .f(() => File.Exists(tempFile1).Should().BeTrue());

            "And the second task is executed"
                .f(() => File.Exists(tempFile2).Should().BeTrue());

            "And I am informed that the first task was executed"
                .f(() => output.Should().ContainEquivalentOf("starting 'non-default1'"));

            "And I am informed that the second task was executed"
                .f(() => output.Should().ContainEquivalentOf("starting 'non-default2'"));
        }
Пример #7
0
        public static void ExecutionFails(Baufile baufile, Exception ex, string message)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given a baufile which throws an exception"
                .f(() => baufile = Baufile.Create(scenario).WriteLine(
                    @"throw new Exception(""" + (message = Guid.NewGuid().ToString()) + @""");"));

            "When I execute the baufile"
                .f(() => ex = Record.Exception(() => baufile.Run()));

            "Then execution should fail"
                .f(() => ex.Should().NotBeNull());

            "And I see details of the exception"
                .f(() => ex.Message.Should().Contain(message));
        }
Пример #8
0
        public static void ExecutingACommandUsingFluentSyntax(Baufile baufile)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given a baufile with an exec task which uses the Exec extension method"
                .f(() => baufile = Baufile.Create(scenario, true).WriteLine(
            @"Require<Bau>()
            .Exec(""default"")
            .Do(exec => exec.Run(@""..\Bau.Test.Acceptance.CreateFile.exe"").With(""foo.txt"").In(@""" + scenario + @"""))
            .Run();"));

            "When I execute the baufile"
                .f(() => baufile.Run());

            "Then the task succeeds"
                .f(() => File.Exists(Path.Combine(Baufile.Directory, scenario, "foo.txt")).Should().BeTrue());
        }
Пример #9
0
        public static void ExecutingACommand(Baufile baufile)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given a baufile with an exec task which succeeds"
                .f(() => baufile = Baufile.Create(scenario, true).WriteLine(
            @"Require<Bau>()
            .Task<Exec>(""default"")
            .Do(exec =>
            {
            exec.WorkingDirectory = @""" + scenario + @""";
            exec.Command = @""..\Bau.Test.Acceptance.CreateFile.exe"";
            exec.Args = new[] { ""foo.txt"" };
            })
            .Run();"));

            "When I execute the baufile"
                .f(() => baufile.Run());

            "Then the task succeeds"
                .f(() => File.Exists(Path.Combine(Baufile.Directory, scenario, "foo.txt")).Should().BeTrue());
        }
Пример #10
0
        public static void ReenablingATask(Baufile baufile, string tempFile, string[] executedTasks)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given bau is required"
                .f(() => baufile = Baufile.Create(scenario).WriteLine(
            @"var bau = Require<Bau>();"));

            "And a non-default task which depends on and reenables another non-default task"
                .f(c => baufile.WriteLine(
            @"
            var executed = new List<string>();

            bau.Task(""non-default"").DependsOn(""other-non-default"")
            .Do(() =>
            {
            bau.Reenable(""other-non-default"");
            executed.Add(""non-default"");
            });"));

            "And another non-default task"
                .f(c => baufile.WriteLine(
            @"
            bau.Task(""other-non-default"")
            .Do(() => executed.Add(""other-non-default""));"));

            "And a default task which depends on both non-default tasks"
                .f(() =>
                {
                    tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
                    baufile.WriteLine(
            @"
            bau.Task(""default"")
            .DependsOn(""non-default"", ""other-non-default"")
            .Do(() =>
            {
            executed.Add(""default"");
            using(var file = File.CreateText(@""" + tempFile + @"""))
            {
            file.Write(string.Join(Environment.NewLine, executed));
            };
            });");
                })
                .Teardown(() => File.Delete(tempFile));

            "And the tasks are executed"
                .f(() => baufile.WriteLine(
            @"
            bau.Run();"));

            "When I execute the baufile"
                .f(() => baufile.Run());

            "Then four tasks are executed"
                .f(() =>
                {
                    File.Exists(tempFile).Should().BeTrue();
                    executedTasks = File.ReadAllText(tempFile).Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    executedTasks.Length.Should().Be(4);
                });

            "And the other non-default task is executed first"
                .f(() => executedTasks[0].Should().Be("other-non-default"));

            "And the non-default task is executed second"
                .f(() => executedTasks[1].Should().Be("non-default"));

            "And the other non-default task is executed third for the second time"
                .f(() => executedTasks[2].Should().Be("other-non-default"));

            "And the default task is executed fourth"
                .f(() => executedTasks[3].Should().Be("default"));
        }
Пример #11
0
        public static void DependencyFails(Baufile baufile, string tempFile, Exception ex)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given bau is required"
                .f(() => baufile = Baufile.Create(scenario).WriteLine(
            @"var bau = Require<Bau>();"));

            "And a non-default task which fails"
                .f(c => baufile.WriteLine(
            @"
            bau.Task(""non-default"")
            .Do(() => { throw new Exception();} );"));

            "And a default task which depends on the non-default task"
                .f(() =>
                {
                    tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
                    baufile.WriteLine(
            @"
            bau.Task(""default"")
            .DependsOn(""non-default"")
            .Do(() => File.CreateText(@""" + tempFile + @""").Dispose());");
                })
                .Teardown(() => File.Delete(tempFile));

            "And the tasks are executed"
                .f(() => baufile.WriteLine(
            @"
            bau.Run();"));

            "When I execute the baufile"
                .f(() => ex = Record.Exception(() => baufile.Run()));

            "Then execution should fail"
                .f(() => ex.Should().NotBeNull());

            "And the default task is not executed"
                .f(() => File.Exists(tempFile).Should().BeFalse());

            "And I am informed that the non-default task was executed"
                .f(() => ex.Message.Should().ContainEquivalentOf("'non-default' task failed."));
        }
Пример #12
0
        public static void ExecutionFails(Baufile baufile, Exception ex)
        {
            var scenario = MethodBase.GetCurrentMethod().GetFullName();

            "Given a baufile with an exec task which fails"
                .f(() => baufile = Baufile.Create(scenario).WriteLine(
            @"Require<Bau>().Task<Exec>().Do(exec => exec.Command = @""..\Bau.Test.Acceptance.CreateFile.exe"").Run();"));

            "When I execute the baufile"
                .f(() => ex = Record.Exception(() => baufile.Run()));

            "Then execution fails"
                .f(() => ex.Should().NotBeNull());

            "And I am informed that the task failed"
                .f(() => ex.Message.Should().ContainEquivalentOf("'default' task failed"));

            "And I am informed that the command exited with a non-zero exit code"
                .f(() =>
                {
                    ex.Message.Should().ContainEquivalentOf("the command exited with code ");
                    ex.Message.Should().NotContainEquivalentOf("the command exited with code 0");
                });
        }