Ejemplo n.º 1
0
        public IEnumerator TimerEmitTime()
        {
            UnityEventListenerMock timerCompleteMock = new UnityEventListenerMock();
            UnityEventValueListenerMock <float> timerElapsedTimeMock   = new UnityEventValueListenerMock <float>();
            UnityEventValueListenerMock <float> timerRemainingTimeMock = new UnityEventValueListenerMock <float>();

            subject.Completed.AddListener(timerCompleteMock.Listen);
            subject.ElapsedTimeEmitted.AddListener(timerElapsedTimeMock.Listen);
            subject.RemainingTimeEmitted.AddListener(timerRemainingTimeMock.Listen);

            float beginTime = Time.time;
            float startTime = 0.5f;

            subject.StartTime = startTime;

            Assert.IsFalse(timerElapsedTimeMock.Received);
            Assert.IsFalse(timerRemainingTimeMock.Received);

            subject.EmitElapsedTime();
            Assert.IsTrue(timerElapsedTimeMock.Received);
            Assert.AreApproximatelyEqual(timerElapsedTimeMock.Value, 0f, Tolerance);

            subject.EmitRemainingTime();
            Assert.IsTrue(timerRemainingTimeMock.Received);
            Assert.AreApproximatelyEqual(timerRemainingTimeMock.Value, 0.5f, Tolerance);

            timerElapsedTimeMock.Reset();
            timerRemainingTimeMock.Reset();

            subject.Begin();

            Assert.IsFalse(timerCompleteMock.Received);

            subject.EmitElapsedTime();
            Assert.IsTrue(timerElapsedTimeMock.Received);
            Assert.AreApproximatelyEqual(timerElapsedTimeMock.Value, 0f, Tolerance);

            subject.EmitRemainingTime();
            Assert.IsTrue(timerRemainingTimeMock.Received);
            Assert.AreApproximatelyEqual(timerRemainingTimeMock.Value, 0.5f, Tolerance);

            timerElapsedTimeMock.Reset();
            timerRemainingTimeMock.Reset();

            yield return(new WaitForSeconds(0.2f));

            float elapsedTime   = Time.time - beginTime;
            float remainingTime = startTime + (beginTime - Time.time);

            subject.EmitElapsedTime();
            Assert.IsTrue(timerElapsedTimeMock.Received);
            Assert.AreEqual(timerElapsedTimeMock.Value, elapsedTime);

            subject.EmitRemainingTime();
            Assert.IsTrue(timerRemainingTimeMock.Received);
            Assert.AreEqual(timerRemainingTimeMock.Value, remainingTime);

            timerElapsedTimeMock.Reset();
            timerRemainingTimeMock.Reset();

            yield return(new WaitForSeconds(0.3f));

            Assert.IsTrue(timerCompleteMock.Received);

            subject.EmitElapsedTime();
            Assert.IsTrue(timerElapsedTimeMock.Received);
            Assert.AreApproximatelyEqual(timerElapsedTimeMock.Value, 0.5f, Tolerance);

            subject.EmitRemainingTime();
            Assert.IsTrue(timerRemainingTimeMock.Received);
            Assert.AreApproximatelyEqual(timerRemainingTimeMock.Value, 0f, Tolerance);
        }