示例#1
0
        public void StopForOneTarget()
        {
            ResetFlags();

            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;

            var object1 = new object();
            var object2 = new object();
            var object3 = new object();

            coroutineMgr.StartCoroutine(object1, FirstEnumerator());
            timeProvider.OnUpdate += Raise.Event <Action>();
            coroutineMgr.StartCoroutine(object2, SecondEnumerator());
            coroutineMgr.StopAllCoroutinesForTarget(object1);
            coroutineMgr.StartCoroutine(object3, ThirdEnumerator());
            timeProvider.OnUpdate += Raise.Event <Action>();
            timeProvider.OnUpdate += Raise.Event <Action>();

            Assert.IsFalse(_firstFlag);
            Assert.IsTrue(_secondFlag);
            Assert.IsTrue(_thirdFlag);
        }
示例#2
0
        public void Test()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();

            timeProvider.deltaTime.Returns(1.0f);
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            coroutineMgr.StartCoroutine(this, WaitCoroutine());

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.IsTrue(_flag1);
            Assert.IsFalse(_flag2);
            Assert.IsFalse(_flag3);
            Assert.IsFalse(_flag4);

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.IsTrue(_flag1);
            Assert.IsTrue(_flag2);
            Assert.IsFalse(_flag3);
            Assert.IsFalse(_flag4);

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.IsTrue(_flag1);
            Assert.IsTrue(_flag2);
            Assert.IsTrue(_flag3);
            Assert.IsFalse(_flag4);

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.IsTrue(_flag1);
            Assert.IsTrue(_flag2);
            Assert.IsTrue(_flag3);
            Assert.IsTrue(_flag4);
        }
        public void CoroutineRunTest(ICoroutineManager coroutineMgr)
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();

            coroutineMgr.TimeProvider = timeProvider;
            var coroutine = (EnumeratorCoroutineProcessor)coroutineMgr.StartCoroutine(this, InterruptableCoroutine());

            var state = coroutine.State;

            Assert.AreEqual(CoroutineState.NotStarted, state);
            coroutine.OnStateChange += newState => state = newState;

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.AreEqual(1, _count);
            coroutine.Pause();
            Assert.AreEqual(CoroutineState.Paused, state);
            Assert.AreEqual(CoroutineState.Paused, coroutine.State);

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.AreEqual(1, _count);
            coroutine.Resume();
            Assert.AreEqual(CoroutineState.InProgress, state);
            Assert.AreEqual(CoroutineState.InProgress, coroutine.State);

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.AreEqual(11, _count);
            coroutine.Stop();
            Assert.AreEqual(CoroutineState.Stopped, state);
            Assert.AreEqual(CoroutineState.Stopped, coroutine.State);

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.AreEqual(11, _count);
            Assert.IsTrue(coroutine.IsCompleted);
        }
        public void CheckCorrectProcessWhenError()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            Assert.Throws <Exception>(() => coroutineMgr.StartCoroutine(this, CorrectProcessWhenError()));
        }
        public void ProcessorInYielding()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            coroutineMgr.StartCoroutine(this, ProcessorCoroutine());
            Assert.Throws <UsingCoroutineProcessorInYieldingException>(() => timeProvider.OnUpdate += Raise.Event <Action>());
        }
示例#6
0
        public void SameCoroutinesRightWay()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            coroutineMgr.StartCoroutine(this, SimpleCoroutine());
            Assert.DoesNotThrow(() => coroutineMgr.StartCoroutine(this, SimpleCoroutine()));
        }
示例#7
0
        public void Test()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            coroutineMgr.StartCoroutine(this, SimpleCoroutine());
            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.IsTrue(_flag);
        }
        public void UnityYieldInstuctionNotSupportedWaitForFixedUpdate()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            coroutineMgr.StartCoroutine(this, UnityWaitForFixedUpdate());
            Assert.Throws <UnityYieldInstructionNotSupportedException>(() => timeProvider.OnUpdate += Raise.Event <Action>());
            Assert.DoesNotThrow(() => timeProvider.OnUpdate += Raise.Event <Action>());
        }
示例#9
0
        public void NullParameters()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            Assert.Throws <ArgumentNullException>(() => coroutineMgr.StartCoroutine(null, SimpleCoroutine()));
            Assert.Throws <ArgumentNullException>(() => coroutineMgr.StartCoroutine(this, null));
            Assert.Throws <ArgumentNullException>(() => coroutineMgr.StopAllCoroutinesForTarget(null));
        }
示例#10
0
        public void SameCoroutinesWrongWay()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            var enumerator = SimpleCoroutine();

            coroutineMgr.StartCoroutine(this, enumerator);
            Assert.Throws <DuplicateEnumeratorException>(() => coroutineMgr.StartCoroutine(this, enumerator));
        }
示例#11
0
        public void SameCoroutinesReading()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            var enumerator = SimpleCoroutine();

            coroutineMgr.StartCoroutine(this, enumerator);
            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.DoesNotThrow(() => coroutineMgr.StartCoroutine(this, enumerator));
        }
示例#12
0
        public void Test()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;

            coroutineMgr.StartCoroutine(this, IgnoreCoroutine());
            for (var i = 0; i < 16; i++)
            {
                timeProvider.OnUpdate += Raise.Event <Action>();
            }
            Assert.IsTrue(_flag);
        }
示例#13
0
        public void Test()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            var coroutine = coroutineMgr.StartCoroutine(this, ParentCoroutine());

            Assert.AreEqual(new[]
            {
                0,
                0,
                0,
                0
            }, _flags);

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.AreEqual(new[]
            {
                1,
                1,
                1,
                0
            }, _flags);
            Assert.IsFalse(coroutine.IsCompleted);

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.AreEqual(new[]
            {
                1,
                3,
                3,
                1
            }, _flags);
            Assert.IsFalse(coroutine.IsCompleted);

            timeProvider.OnUpdate += Raise.Event <Action>();
            Assert.AreEqual(new[]
            {
                2,
                4,
                4,
                1
            }, _flags);
            Assert.IsTrue(coroutine.IsCompleted);
        }
        public void Test()
        {
            var isCompleted  = false;
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();
            var coroutineMgr = new CoroutineManager();

            coroutineMgr.TimeProvider = timeProvider;
            var coroutineProcessor = coroutineMgr.StartCoroutine(this, CompletableCoroutine());

            coroutineProcessor.OnComplete += processor => isCompleted = true;

            for (var i = 0; i <= STEPS_COUNT; i++)
            {
                timeProvider.OnUpdate += Raise.Event <Action>();
            }

            Assert.IsTrue(isCompleted);
        }
示例#15
0
        public void Test()
        {
            var timeProvider = CoroutineSystemTestUtil.TestTimeProvider();

            _coroutineManager = new CoroutineManager();
            _coroutineManager.TimeProvider = timeProvider;

            _coroutineManager.StartCoroutine(this, AddEnumerator());

            timeProvider.OnUpdate += Raise.Event <Action>();
            timeProvider.OnUpdate += Raise.Event <Action>();
            timeProvider.OnUpdate += Raise.Event <Action>();
            timeProvider.OnUpdate += Raise.Event <Action>();
            timeProvider.OnUpdate += Raise.Event <Action>();

            Assert.IsTrue(_firstFlag);
            Assert.AreEqual(_secondFlag, 1);
            Assert.AreEqual(_thirdFlag, 1);
        }
 public void Initialize() => _coroutineManager = new CoroutineManager
 {
     TimeProvider = CoroutineSystemTestUtil.TestTimeProvider()
 };