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'")); }
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'")); }
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.")); }
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")); }