示例#1
0
        public void ShouldAct()
        {
            // Arrange
            MockCountdownTimerElapsedAction nextAction     = new MockCountdownTimerElapsedAction.Builder().Act().Build();
            MockCountdownTimer          mockCountdownTimer = new MockCountdownTimer.Builder().Build();
            CountdownTimerElapsedAction subject            = new CountdownTimerElapsedAction(nextAction);

            // Act
            subject.Act(mockCountdownTimer);

            // Assert
            nextAction.AssertActInvokedWith(mockCountdownTimer);
        }
示例#2
0
        public void ShouldGuardWhenFinished()
        {
            // Arrange
            MockCountdownTimerElapsedAction nextAction        = new MockCountdownTimerElapsedAction.Builder().Build();
            MockCountdownState mockCountdownState             = new MockCountdownState.Builder().Finished(Bool.True).Build();
            MockCountdownTimer mockCountdownTimer             = new MockCountdownTimer.Builder().CountdownState(mockCountdownState).Close().Build();
            CountdownTimerElapsedAction_FinishedGuard subject = new CountdownTimerElapsedAction_FinishedGuard(nextAction);

            // Act
            subject.Act(mockCountdownTimer);

            // Assert
            mockCountdownTimer.AssertCloseInvoked();
        }
示例#3
0
        public void ShouldNextActWhenNotFinished()
        {
            // Arrange
            MockCountdownTimerElapsedAction nextAction        = new MockCountdownTimerElapsedAction.Builder().Act().Build();
            MockCountdownState mockCountdownState             = new MockCountdownState.Builder().Finished(Bool.False).Build();
            MockCountdownTimer mockCountdownTimer             = new MockCountdownTimer.Builder().CountdownState(mockCountdownState).Build();
            CountdownTimerElapsedAction_FinishedGuard subject = new CountdownTimerElapsedAction_FinishedGuard(nextAction);

            // Act
            subject.Act(mockCountdownTimer);

            // Assert
            nextAction.AssertActInvokedWith(mockCountdownTimer);
        }
        public void Close_ShouldInvokeTimerBookEnd()
        {
            //Arrange
            MockCountdownTimerElapsedAction mockCountdownTimerElapsedAction = new MockCountdownTimerElapsedAction.Builder().Build();
            MockTimerBookEnd     mockTimerBookEnd     = new MockTimerBookEnd.Builder().Close().Build();
            MockCountdownTracker mockCountdownTracker = new MockCountdownTracker.Builder().Build();
            CountdownTimer       subject = new TestCountdownTimer(mockCountdownTimerElapsedAction, mockTimerBookEnd, mockCountdownTracker);

            //Act
            subject.Stop();

            //Assert
            mockTimerBookEnd.AssertCloseInvoked();
        }
        public void ShouldNextActAndInvoke()
        {
            // Arrange
            MockCountdownTimerElapsedAction nextAction = new MockCountdownTimerElapsedAction.Builder().Act().Build();
            MockCountdownTimer mockCountdownTimer      = new MockCountdownTimer.Builder().Invoke().Build();
            CountdownTimerElapsedAction_Update subject = new CountdownTimerElapsedAction_Update(nextAction);

            // Act
            subject.Act(mockCountdownTimer);

            // Assert
            nextAction.AssertActInvokedWith(mockCountdownTimer);
            mockCountdownTimer.AssertInvokeInvokedWith(TimerProgress.More);
        }
        public void ShouldGuardWhenLast()
        {
            // Arrange
            MockCountdownTimerElapsedAction nextAction    = new MockCountdownTimerElapsedAction.Builder().Build();
            MockCountdownState mockCountdownState         = new MockCountdownState.Builder().Last(Bool.True).Build();
            MockCountdownTimer mockCountdownTimer         = new MockCountdownTimer.Builder().CountdownState(mockCountdownState).Invoke().Build();
            CountdownTimerElapsedAction_LastGuard subject = new CountdownTimerElapsedAction_LastGuard(nextAction);

            // Act
            subject.Act(mockCountdownTimer);

            // Assert
            mockCountdownTimer.AssertInvokeInvokedWith(TimerProgress.Last);
        }
        public void CountdownState_ShouldReturnAccurateState()
        {
            //Arrange
            //Arrange
            MockCountdownState mockCountdownState = new MockCountdownState.Builder().Build();
            MockCountdownTimerElapsedAction mockCountdownTimerElapsedAction = new MockCountdownTimerElapsedAction.Builder().Build();
            MockTimerBookEnd     mockTimerBookEnd     = new MockTimerBookEnd.Builder().Build();
            MockCountdownTracker mockCountdownTracker = new MockCountdownTracker.Builder().CountdownState(mockCountdownState).Build();
            CountdownTimer       subject = new TestCountdownTimer(mockCountdownTimerElapsedAction, mockTimerBookEnd, mockCountdownTracker);

            //Act
            ICountdownState actual = subject.CountdownState();

            //Assert
            actual.Should().Be(mockCountdownState);
        }
        public void Start_ShouldInvokeTimerBookEnd()
        {
            //Arrange
            //Arrange
            MockCountdownTimerElapsedAction mockCountdownTimerElapsedAction = new MockCountdownTimerElapsedAction.Builder().Build();
            MockTimerBookEnd     mockTimerBookEnd     = new MockTimerBookEnd.Builder().Start().Build();
            MockCountdownTracker mockCountdownTracker = new MockCountdownTracker.Builder().Restart().Build();
            CountdownTimer       subject = new TestCountdownTimer(mockCountdownTimerElapsedAction, mockTimerBookEnd, mockCountdownTracker);

            //Act
            subject.Start();

            //Assert
            mockCountdownTracker.AssertRestartInvoked();
            mockTimerBookEnd.AssertStartInvoked();
        }
        public void Invoke_ShouldTriggerEvent()
        {
            //Arrange
            //Arrange
            MockCountdownTimerElapsedAction mockCountdownTimerElapsedAction = new MockCountdownTimerElapsedAction.Builder().Build();
            MockTimerBookEnd     mockTimerBookEnd     = new MockTimerBookEnd.Builder().Build();
            MockCountdownTracker mockCountdownTracker = new MockCountdownTracker.Builder().Increment().Build();
            CountdownTimer       subject = new TestCountdownTimer(mockCountdownTimerElapsedAction, mockTimerBookEnd, mockCountdownTracker);
            CountdownEvent       latch   = new CountdownEvent(1);

            subject.TimerEvent += (time, more) => latch.Signal();

            //Act
            subject.Invoke(TimerProgress.More);

            //Assert
            latch.Wait(10).Should().BeTrue();
            mockCountdownTracker.AssertIncrementInvoked();
        }