public void Should_Not_Execute_OnError_Method_If_Run_Completed() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <OnErrorRunCompletedTask>(); // When fixture.Run("--target", "OnErrorRunCompletedTask"); // Then fixture.Log.DidNotReceive().Error("OnError: {0}", "An exception"); }
public void Should_Return_Zero_On_Success() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <DummyTask>(); // When var result = fixture.Run("--target", "dummytask"); // Then Assert.Equal(0, result); }
public void Should_Execute_OnError_Method_If_RunAsync_Failed() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <OnErrorRunAsyncFailedTask>(); // When fixture.Run("--target", "OnErrorRunAsyncFailedTask"); // Then fixture.Log.Received(1).Error("OnError: {0}", "An exception"); }
public void Should_Abort_Build_If_Task_That_Is_Not_ContinueOnError_Throws() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <ThrowingTask>(); // When var result = fixture.Run("--target", "ThrowingTask"); // Then Assert.NotEqual(0, result); }
public void Should_Install_Tools() { // Given var fixture = new CakeHostFixture(); fixture.Host.ConfigureServices(s => s.UseTool(new Uri("foo:?package=Bar"))); fixture.RegisterTask <DummyTask>(); // When var result = fixture.Run("--target", "dummytask"); // Then fixture.Installer.Received(1).Install( Arg.Is <PackageReference>(p => p.OriginalString == "foo:?package=Bar")); }
public void Should_Throw_If_Dependency_Is_Not_A_Valid_Task() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <InvalidDependencyTask>(); fixture.Strategy = Substitute.For <IExecutionStrategy>(); // When var result = fixture.Run("--target", "InvalidDependencyTask"); // Then Assert.NotEqual(0, result); fixture.Log.Received(1).Error("Error: {0}", "The dependency 'DateTime' is not a valid task."); }
public void Should_Set_Working_Directory_From_Options_If_Set() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <DummyTask>(); fixture.Host.UseWorkingDirectory("./Foo"); fixture.FileSystem.CreateDirectory("/Working/Foo"); // When fixture.Run(); // Then Assert.Equal("/Working/Foo", fixture.Environment.WorkingDirectory.FullPath); }
public void Should_Execute_Tasks() { // Given var fixture = new CakeHostFixture(); fixture.Strategy = Substitute.For <IExecutionStrategy>(); fixture.RegisterTask <DummyTask>(); // When var result = fixture.Run("--target", "dummytask"); // Then fixture.Strategy .Received(1) .ExecuteAsync(Arg.Is <CakeTask>(t => t.Name == "DummyTask"), Arg.Any <ICakeContext>()); }
public void Should_pass_target_within_cakeContext_arguments() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <DummyTask>(); fixture.Strategy = Substitute.For <IExecutionStrategy>(); // When fixture.Run("--target", nameof(DummyTask)); // Then fixture.Strategy .Received(1) .ExecuteAsync(Arg.Any <CakeTask>(), Arg.Is <ICakeContext>(cc => cc.Arguments.HasArgument("target") && cc.Arguments.GetArgument("target").Equals(nameof(DummyTask)))); }
public void Should_Call_Setup_On_Registered_Task_Lifetime() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <DummyTask>(); var lifetime = new FakeTaskLifetime(); fixture.Host.ConfigureServices(services => services.AddSingleton <IFrostingTaskSetup>(lifetime)); // When var result = fixture.Run("--target", "dummytask"); // Then Assert.Equal(0, result); Assert.Equal(1, lifetime.SetupCount); }
public void Should_Execute_Finally_Method_After_All_Methods() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <FinallyTask>(); // When fixture.Run("--target", "FinallyTask"); // Then Received.InOrder(() => { fixture.Log.Information("Run method called"); fixture.Log.Information("OnError method called"); fixture.Log.Information("Finally method called"); }); }
public void Should_Execute_Dependee_Task() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <CleanTask>(); fixture.RegisterTask <DependeeTask>(); fixture.Strategy = Substitute.For <IExecutionStrategy>(); // When fixture.Run("--target", nameof(CleanTask)); // Then Received.InOrder(() => { fixture.Strategy.ExecuteAsync(Arg.Is <CakeTask>(t => t.Name == nameof(DependeeTask)), Arg.Any <ICakeContext>()); fixture.Strategy.ExecuteAsync(Arg.Is <CakeTask>(t => t.Name == nameof(CleanTask)), Arg.Any <ICakeContext>()); }); }
public void Should_Execute_Tasks_In_Correct_Order() { // Given var fixture = new CakeHostFixture(); fixture.RegisterTask <BuildTask>(); fixture.RegisterTask <CleanTask>(); fixture.RegisterTask <UnitTestsTask>(); fixture.Strategy = Substitute.For <IExecutionStrategy>(); // When fixture.Run("--target", "UnitTestsTask"); // Then Received.InOrder(() => { fixture.Strategy.ExecuteAsync(Arg.Is <CakeTask>(t => t.Name == "CleanTask"), Arg.Any <ICakeContext>()); fixture.Strategy.ExecuteAsync(Arg.Is <CakeTask>(t => t.Name == "BuildTask"), Arg.Any <ICakeContext>()); fixture.Strategy.ExecuteAsync(Arg.Is <CakeTask>(t => t.Name == "UnitTestsTask"), Arg.Any <ICakeContext>()); }); }