Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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");
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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"));
        }
Ejemplo n.º 6
0
        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.");
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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>());
        }
Ejemplo n.º 9
0
        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))));
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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");
            });
        }
Ejemplo n.º 12
0
        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>());
            });
        }
Ejemplo n.º 13
0
        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>());
            });
        }