Ejemplo n.º 1
0
        public void execute_executes_each_child_action_in_order()
        {
            var childCount          = 10;
            var childExecutionOrder = new int[childCount];
            var executionOrder      = 0;
            var childActions        = Enumerable
                                      .Range(0, childCount)
                                      .Select(
                (i, _) =>
            {
                var childAction = new ActionMock(MockBehavior.Loose);
                childAction
                .When(x => x.Execute(It.IsAny <ExecutionContext>()))
                .Do(() => childExecutionOrder[i] = Interlocked.Increment(ref executionOrder))
                .Return(Observable.Return(Unit.Default));
                return(childAction);
            })
                                      .ToList();

            var sut = new SequenceActionBuilder()
                      .WithChildren(childActions)
                      .Build();

            using (var context = new ExecutionContext())
            {
                sut.Execute(context).Subscribe();

                for (var i = 0; i < childExecutionOrder.Length; ++i)
                {
                    Assert.Equal(i + 1, childExecutionOrder[i]);
                }
            }
        }
        public void execute_executes_each_child_action()
        {
            var action1 = new ActionMock(MockBehavior.Loose);
            var action2 = new ActionMock(MockBehavior.Loose);
            var action3 = new ActionMock(MockBehavior.Loose);
            var sut = new SequenceActionBuilder()
                .WithChild(action1)
                .WithChild(action2)
                .WithChild(action3)
                .Build();

            using (var context = new ExecutionContext())
            {
                sut.Execute(context).Subscribe();

                action1
                    .Verify(x => x.Execute(context))
                    .WasCalledExactlyOnce();

                action2
                    .Verify(x => x.Execute(context))
                    .WasCalledExactlyOnce();

                action3
                    .Verify(x => x.Execute(context))
                    .WasCalledExactlyOnce();
            }
        }
Ejemplo n.º 3
0
        public void execute_executes_each_child_action()
        {
            var action1 = new ActionMock(MockBehavior.Loose);
            var action2 = new ActionMock(MockBehavior.Loose);
            var action3 = new ActionMock(MockBehavior.Loose);
            var sut     = new SequenceActionBuilder()
                          .WithChild(action1)
                          .WithChild(action2)
                          .WithChild(action3)
                          .Build();

            using (var context = new ExecutionContext())
            {
                sut.Execute(context).Subscribe();

                action1
                .Verify(x => x.Execute(context))
                .WasCalledExactlyOnce();

                action2
                .Verify(x => x.Execute(context))
                .WasCalledExactlyOnce();

                action3
                .Verify(x => x.Execute(context))
                .WasCalledExactlyOnce();
            }
        }
Ejemplo n.º 4
0
        public void execute_completes_even_if_there_are_no_child_actions()
        {
            var sut = new SequenceActionBuilder()
                      .Build();

            var completed = false;

            sut
            .Execute(new ExecutionContext())
            .Subscribe(_ => completed = true);

            Assert.True(completed);
        }
Ejemplo n.º 5
0
        public void execute_skips_child_actions_that_are_shorter_than_the_skip_ahead_even_if_the_context_is_paused()
        {
            var action1 = new ActionMock();
            var action2 = new ActionMock();
            var action3 = new ActionMock(MockBehavior.Loose);

            action1
            .When(x => x.Execute(It.IsAny <ExecutionContext>()))
            .Throw();

            action2
            .When(x => x.Execute(It.IsAny <ExecutionContext>()))
            .Throw();

            action1
            .When(x => x.Duration)
            .Return(TimeSpan.FromSeconds(3));

            action2
            .When(x => x.Duration)
            .Return(TimeSpan.FromSeconds(8));

            action3
            .When(x => x.Duration)
            .Return(TimeSpan.FromSeconds(2));

            var sut = new SequenceActionBuilder()
                      .WithChild(action1)
                      .WithChild(action2)
                      .WithChild(action3)
                      .Build();

            using (var context = new ExecutionContext(TimeSpan.FromSeconds(11)))
            {
                context.IsPaused = true;
                sut.Execute(context).Subscribe();

                action3
                .Verify(x => x.Execute(context))
                .WasCalledExactlyOnce();
            }
        }
        public void execute_executes_each_child_action_in_order()
        {
            var childCount = 10;
            var childExecutionOrder = new int[childCount];
            var executionOrder = 0;
            var childActions = Enumerable
                .Range(0, childCount)
                .Select(
                    (i, _) =>
                    {
                        var childAction = new ActionMock(MockBehavior.Loose);
                        childAction
                            .When(x => x.Execute(It.IsAny<ExecutionContext>()))
                            .Do(() => childExecutionOrder[i] = Interlocked.Increment(ref executionOrder))
                            .Return(Observable.Return(Unit.Default));
                        return childAction;
                    })
                .ToList();
            
            var sut = new SequenceActionBuilder()
                .WithChildren(childActions)
                .Build();

            using (var context = new ExecutionContext())
            {
                sut.Execute(context).Subscribe();

                for (var i = 0; i < childExecutionOrder.Length; ++i)
                {
                    Assert.Equal(i + 1, childExecutionOrder[i]);
                }
            }
        }
        public void execute_completes_even_if_there_are_no_child_actions()
        {
            var sut = new SequenceActionBuilder()
                .Build();

            var completed = false;
            sut
                .Execute(new ExecutionContext())
                .Subscribe(_ => completed = true);

            Assert.True(completed);
        }
        public void execute_skips_child_actions_that_are_shorter_than_the_skip_ahead_even_if_the_context_is_paused()
        {
            var action1 = new ActionMock();
            var action2 = new ActionMock();
            var action3 = new ActionMock(MockBehavior.Loose);

            action1
                .When(x => x.Execute(It.IsAny<ExecutionContext>()))
                .Throw();

            action2
                .When(x => x.Execute(It.IsAny<ExecutionContext>()))
                .Throw();

            action1
                .When(x => x.Duration)
                .Return(TimeSpan.FromSeconds(3));

            action2
                .When(x => x.Duration)
                .Return(TimeSpan.FromSeconds(8));

            action3
                .When(x => x.Duration)
                .Return(TimeSpan.FromSeconds(2));

            var sut = new SequenceActionBuilder()
                .WithChild(action1)
                .WithChild(action2)
                .WithChild(action3)
                .Build();

            using (var context = new ExecutionContext(TimeSpan.FromSeconds(11)))
            {
                context.IsPaused = true;
                sut.Execute(context).Subscribe();

                action3
                    .Verify(x => x.Execute(context))
                    .WasCalledExactlyOnce();
            }
        }