Пример #1
0
        public void ItShouldBePossibleToInvokeCoroutineAndWait()
        {
            var ct    = new CoroutineTestThread();
            var subCr = new LocalInvokerCoroutine();

            subCr.ActionAsTask = true;

            var cr = new LocalInvokerCoroutine();

            cr.Coroutine = subCr;
            ct.Initialize();
            ct.AddCoroutine(cr);
            ct.StepForward();

            for (int i = 0; i < 12; i++)
            {
                ct.StepForward();
                Thread.Sleep(20);
            }

            Thread.Sleep(200);
            Assert.AreEqual(subCr.NormalCalls, 2);
            Assert.AreEqual(subCr.StepFunctionCall, 1);
            Assert.AreEqual("ActionAsTask", subCr.RealResult);


            Assert.AreEqual(cr.NormalCalls, 2);
            Assert.AreEqual(cr.StepFunctionCall, 0);
            Assert.AreEqual("ActionAsTaskTasked", cr.CoroutineResult);
        }
Пример #2
0
        public void ItShouldBePossibleToInvokeCoroutineStatically()
        {
            var cr = new LocalInvokerCoroutine();

            cr.ActionAsTask = true;

            Coroutine.CallCoroutine(cr.Run());
            Thread.Sleep(200);
            Assert.AreEqual(cr.NormalCalls, 2);
            Assert.AreEqual(cr.StepFunctionCall, 1);
            Assert.AreEqual("ActionAsTask", cr.RealResult);
        }
Пример #3
0
        public void ItShouldBePossibleToInvokeLocalAndWaitWithReturnValues()
        {
            var          ct     = new CoroutineTestThread();
            const string result = "TestResult";
            var          cr     = new LocalInvokerCoroutine(result);

            ct.Initialize();
            ct.AddCoroutine(cr);
            ct.StepForward();

            for (int i = 0; i < 12; i++)
            {
                ct.StepForward();
            }
            Assert.AreEqual(cr.NormalCalls, 2);
            Assert.AreEqual(cr.StepFunctionCall, 10);
            Assert.AreEqual(result, cr.RealResult);
        }
Пример #4
0
        public void ItShouldBePossibleToInvokeActionAsTask()
        {
            var ct = new CoroutineTestThread();
            var cr = new LocalInvokerCoroutine();

            cr.ActionAsTask = true;
            ct.Initialize();
            ct.AddCoroutine(cr);
            ct.StepForward();

            for (int i = 0; i < 12; i++)
            {
                ct.StepForward();
                Thread.Sleep(20);
            }
            Assert.IsTrue(cr.NormalCalls == 2 || cr.NormalCalls == 1);
            Assert.AreEqual(cr.StepFunctionCall, 1);
            Assert.AreEqual("ActionAsTask", cr.RealResult);
        }