Пример #1
0
        public ExerciseBuilder WithBeforeExerciseAction(IAction action)
        {
            var matcher = new EventMatcherMock();

            matcher.When(x => x.Matches(It.IsAny <IEvent>())).Return((IEvent @event) => @event is BeforeExerciseEvent);
            return(this.WithMatcherWithAction(new MatcherWithAction(matcher, action)));
        }
        public void execute_async_skips_actions_that_are_shorter_than_the_skip_ahead_even_if_the_context_is_paused()
        {
            var action1       = new ActionMock(MockBehavior.Loose);
            var action2       = new ActionMock(MockBehavior.Loose);
            var action3       = new ActionMock(MockBehavior.Loose);
            var eventMatcher1 = new EventMatcherMock();
            var eventMatcher2 = new EventMatcherMock();
            var eventMatcher3 = new EventMatcherMock();

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

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

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

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

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

            eventMatcher1
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher2
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher3
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            var sut = new ExerciseBuilder()
                      .AddMatcherWithAction(new MatcherWithAction(eventMatcher1, action1))
                      .AddMatcherWithAction(new MatcherWithAction(eventMatcher2, action2))
                      .AddMatcherWithAction(new MatcherWithAction(eventMatcher3, action3))
                      .Build();

            using (var executionContext = new ExecutionContext(TimeSpan.FromSeconds(13)))
            {
                executionContext.IsPaused = true;
                sut.ExecuteAsync(executionContext);

                action3
                .Verify(x => x.ExecuteAsync(executionContext))
                .WasCalledExactlyOnce();
            }
        }
        public void execute_async_executes_all_appropriate_actions()
        {
            var action1       = new ActionMock(MockBehavior.Loose);
            var action2       = new ActionMock(MockBehavior.Loose);
            var action3       = new ActionMock(MockBehavior.Loose);
            var eventMatcher1 = new EventMatcherMock();
            var eventMatcher2 = new EventMatcherMock();
            var eventMatcher3 = new EventMatcherMock();

            eventMatcher1
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher2
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is DuringRepetitionEvent);

            eventMatcher3
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is AfterSetEvent);

            var sut = new ExerciseBuilder()
                      .WithSetCount(2)
                      .WithRepetitionCount(3)
                      .AddMatcherWithAction(new MatcherWithAction(eventMatcher1, action1))
                      .AddMatcherWithAction(new MatcherWithAction(eventMatcher2, action2))
                      .AddMatcherWithAction(new MatcherWithAction(eventMatcher3, action3))
                      .Build();

            using (var executionContext = new ExecutionContext())
            {
                sut.ExecuteAsync(executionContext);

                action1
                .Verify(x => x.ExecuteAsync(executionContext))
                .WasCalledExactlyOnce();

                action2
                .Verify(x => x.ExecuteAsync(executionContext))
                .WasCalledExactly(times: 6);

                action3
                .Verify(x => x.ExecuteAsync(executionContext))
                .WasCalledExactly(times: 2);
            }
        }
        public void duration_returns_sum_of_action_durations()
        {
            var action1 = new ActionMock();
            var action2 = new ActionMock();
            var action3 = new ActionMock();

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

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

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

            var eventMatcher1 = new EventMatcherMock();
            var eventMatcher2 = new EventMatcherMock();
            var eventMatcher3 = new EventMatcherMock();

            eventMatcher1
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher2
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is DuringRepetitionEvent);

            eventMatcher3
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is AfterSetEvent);

            var sut = new ExerciseBuilder()
                      .WithSetCount(2)
                      .WithRepetitionCount(3)
                      .AddMatcherWithAction(new MatcherWithAction(eventMatcher1, action1))
                      .AddMatcherWithAction(new MatcherWithAction(eventMatcher2, action2))
                      .AddMatcherWithAction(new MatcherWithAction(eventMatcher3, action3))
                      .Build();

            Assert.Equal(TimeSpan.FromSeconds(30), sut.Duration);
        }
Пример #5
0
        public void duration_returns_sum_of_action_durations()
        {
            var action1 = new ActionMock();
            var action2 = new ActionMock();
            var action3 = new ActionMock();

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

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

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

            var eventMatcher1 = new EventMatcherMock();
            var eventMatcher2 = new EventMatcherMock();
            var eventMatcher3 = new EventMatcherMock();

            eventMatcher1
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher2
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is DuringRepetitionEvent);

            eventMatcher3
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is AfterSetEvent);

            var sut = new ExerciseBuilder()
                .WithSetCount(2)
                .WithRepetitionCount(3)
                .WithMatcherWithAction(new MatcherWithAction(eventMatcher1, action1))
                .WithMatcherWithAction(new MatcherWithAction(eventMatcher2, action2))
                .WithMatcherWithAction(new MatcherWithAction(eventMatcher3, action3))
                .Build();

            Assert.Equal(TimeSpan.FromSeconds(30), sut.Duration);
        }
        public void execute_async_does_not_skip_zero_duration_actions()
        {
            var action       = new ActionMock(MockBehavior.Loose);
            var eventMatcher = new EventMatcherMock();

            eventMatcher
            .When(x => x.Matches(It.IsAny <IEvent>()))
            .Return((IEvent @event) => @event is BeforeExerciseEvent);

            var sut = new ExerciseBuilder()
                      .AddMatcherWithAction(new MatcherWithAction(eventMatcher, action))
                      .Build();

            using (var executionContext = new ExecutionContext())
            {
                sut.ExecuteAsync(executionContext);

                action
                .Verify(x => x.ExecuteAsync(executionContext))
                .WasCalledExactlyOnce();
            }
        }
        public void execute_async_skips_actions_that_are_shorter_than_the_skip_ahead_even_if_the_context_is_paused()
        {
            var action1 = new ActionMock(MockBehavior.Loose);
            var action2 = new ActionMock(MockBehavior.Loose);
            var action3 = new ActionMock(MockBehavior.Loose);
            var eventMatcher1 = new EventMatcherMock();
            var eventMatcher2 = new EventMatcherMock();
            var eventMatcher3 = new EventMatcherMock();

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

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

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

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

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

            eventMatcher1
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher2
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher3
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            var sut = new ExerciseBuilder()
                .AddMatcherWithAction(new MatcherWithAction(eventMatcher1, action1))
                .AddMatcherWithAction(new MatcherWithAction(eventMatcher2, action2))
                .AddMatcherWithAction(new MatcherWithAction(eventMatcher3, action3))
                .Build();

            using (var executionContext = new ExecutionContext(TimeSpan.FromSeconds(13)))
            {
                executionContext.IsPaused = true;
                sut.ExecuteAsync(executionContext);

                action3
                    .Verify(x => x.ExecuteAsync(executionContext))
                    .WasCalledExactlyOnce();
            }
        }
        public void execute_async_does_not_skip_zero_duration_actions()
        {
            var action = new ActionMock(MockBehavior.Loose);
            var eventMatcher = new EventMatcherMock();

            eventMatcher
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            var sut = new ExerciseBuilder()
                .AddMatcherWithAction(new MatcherWithAction(eventMatcher, action))
                .Build();

            using (var executionContext = new ExecutionContext())
            {
                sut.ExecuteAsync(executionContext);

                action
                    .Verify(x => x.ExecuteAsync(executionContext))
                    .WasCalledExactlyOnce();
            }
        }
        public void execute_async_executes_all_appropriate_actions()
        {
            var action1 = new ActionMock(MockBehavior.Loose);
            var action2 = new ActionMock(MockBehavior.Loose);
            var action3 = new ActionMock(MockBehavior.Loose);
            var eventMatcher1 = new EventMatcherMock();
            var eventMatcher2 = new EventMatcherMock();
            var eventMatcher3 = new EventMatcherMock();

            eventMatcher1
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is BeforeExerciseEvent);

            eventMatcher2
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is DuringRepetitionEvent);

            eventMatcher3
                .When(x => x.Matches(It.IsAny<IEvent>()))
                .Return((IEvent @event) => @event is AfterSetEvent);

            var sut = new ExerciseBuilder()
                .WithSetCount(2)
                .WithRepetitionCount(3)
                .AddMatcherWithAction(new MatcherWithAction(eventMatcher1, action1))
                .AddMatcherWithAction(new MatcherWithAction(eventMatcher2, action2))
                .AddMatcherWithAction(new MatcherWithAction(eventMatcher3, action3))
                .Build();

            using (var executionContext = new ExecutionContext())
            {
                sut.ExecuteAsync(executionContext);

                action1
                    .Verify(x => x.ExecuteAsync(executionContext))
                    .WasCalledExactlyOnce();

                action2
                    .Verify(x => x.ExecuteAsync(executionContext))
                    .WasCalledExactly(times: 6);

                action3
                    .Verify(x => x.ExecuteAsync(executionContext))
                    .WasCalledExactly(times: 2);
            }
        }
Пример #10
0
 public ExerciseBuilder WithBeforeExerciseAction(IAction action)
 {
     var matcher = new EventMatcherMock();
     matcher.When(x => x.Matches(It.IsAny<IEvent>())).Return((IEvent @event) => @event is BeforeExerciseEvent);
     return this.WithMatcherWithAction(new MatcherWithAction(matcher, action));
 }