Ejemplo n.º 1
0
        public void RunningACoroutineFromEverywhereShouldPropagateExceptions()
        {
            var coroutine = new ExeCoRoutine();

            coroutine.Enumerable = ExecuteAndThrowAfterInitialization().GetEnumerator();

            var target = new CoroutinesManager();

            target.TestInitialize();
            RunnerFactory.Initialize(() => target);

            target.Start();
            var parent = Task.Run(() =>
            {
                var task = CoroutineResult.WaitForCoroutine(coroutine);
                task.Wait();
            });

            Exception expected = null;

            try
            {
                parent.Wait();
            }
            catch (Exception ex)
            {
                expected = ex;
            }
            target.Stop();

            Assert.IsNotNull(expected);
        }
Ejemplo n.º 2
0
        public void ItShoudlBePossibleToStopTheManager()
        {
            Exception thrown    = null;
            var       coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(Execute(int.MaxValue));
            coroutine.Setup(a => a.OnError(It.IsAny <Exception>()))
            .Returns((Exception ex) =>
            {
                thrown = ex;
                return(false);
            });

            var target = new CoroutinesManager();

            target.StartCoroutine(coroutine.Object);

            target.Start();
            Thread.Sleep(200);
            target.Stop();
            Thread.Sleep(100);

            coroutine.Verify(a => a.Execute(), Times.AtLeastOnce);
            coroutine.Verify(a => a.OnError(It.IsAny <Exception>()), Times.Once);
            coroutine.Verify(a => a.OnError(It.IsAny <ManagerStoppedException>()), Times.Once);
            coroutine.Verify(a => a.OnDestroy(), Times.AtMostOnce);
        }
Ejemplo n.º 3
0
        public void RunningACoroutineFromEverywhere()
        {
            var coroutine = new ExeCoRoutine();

            coroutine.Enumerable = Execute().GetEnumerator();

            var target = new CoroutinesManager();

            target.TestInitialize();
            RunnerFactory.Initialize(() => target);

            target.Start();
            var parent = Task.Run(() =>
            {
                var task = CoroutineResult.WaitForCoroutine(coroutine);
                task.Wait();
            });

            parent.Wait();
            target.Stop();

            Assert.AreEqual(1, coroutine.Cycles);
        }