public void CoroutineThreadIntShouldBeExecutedTheRightNumberOfCyclesByHundredsOfThings()
        {
            // ReSharper disable once ConvertToConstant.Local
            int cycleLength     = 100;
            int coroutinesCount = 30;
            int runningTimeMs   = 1000;
            var ft = new CoroutineThread(1);
            var fl = new List <WaitCoroutine>();

            for (int i = 0; i < coroutinesCount; i++)
            {
                var fb = new WaitCoroutine(cycleLength);
                fl.Add(fb);
                ft.AddCoroutine(fb);
            }

            ft.Start();
            Thread.Sleep(1000 + 100);
            ft.Stop();
            Thread.Sleep(300);
            var total = 0;

            foreach (var fb in fl)
            {
                total += fb.Cycles;
                Console.WriteLine("Result: " + fb.Cycles);
            }
            Console.WriteLine("Total: " + total);
            Assert.IsTrue(total > 100, "Executed " + total);
        }
        public void CoroutineThreadIntShouldBePossibleToPauseAndRestart()
        {
            // ReSharper disable once ConvertToConstant.Local
            int hundred = 100;
            var ft      = new CoroutineThread(1);
            var first   = new WaitCoroutine(hundred);
            var second  = new WaitCoroutine(200);

            ft.AddCoroutine(first, second);
            ft.Start();
            Thread.Sleep(1000);
            ft.Pause();
            Thread.Sleep(300);
            var firstCycles  = first.Cycles;
            var secondCycles = second.Cycles;

            Assert.AreEqual(ft.Status, CoroutineThreadStatus.Paused);
            Thread.Sleep(1500);
            Assert.AreEqual(firstCycles, first.Cycles);
            Assert.AreEqual(secondCycles, second.Cycles);
            ft.Start();
            Thread.Sleep(300);
            Assert.AreEqual(CoroutineThreadStatus.Running, ft.Status);
            ft.Stop();
            Thread.Sleep(300);
            Assert.AreEqual(CoroutineThreadStatus.Stopped, ft.Status);

            Assert.IsTrue(firstCycles <= first.Cycles);
            Assert.IsTrue(secondCycles <= second.Cycles);
        }
        public void CoroutineIntItShouldBePossibleToDoOneLevelNesting()
        {
            var ft = new CoroutineThread(1);
            var co = new SingleNestedCoroutine();

            ft.AddCoroutine(co);
            ft.Start();
            Thread.Sleep(100);
            Assert.IsTrue(co.RunFinished);
            Assert.IsTrue(co.FirstCallFinished);
            ft.Stop();
        }
        public void CoroutineIntShouldCallTheCoroutine()
        {
            // ReSharper disable once ConvertToConstant.Local
            int hundred = 100;
            var ft      = new CoroutineThread(1);
            var co      = new CoroutineCallingLocal();

            ft.AddCoroutine(co);
            ft.Start();
            Thread.Sleep(100);
            ft.Stop();
            Thread.Sleep(300);
            Assert.IsTrue(co.LocalCalled);
            Assert.IsTrue(co.LocalSetted);
        }
        public void CoroutineThreadIntShouldBeExecutedTheRightNumberOfCycles()
        {
            var ft     = new CoroutineThread(1);
            var first  = new WaitCoroutine(100);
            var second = new WaitCoroutine(200);

            ft.AddCoroutine(first, second);
            ft.Start();
            Thread.Sleep(1100);
            ft.Stop();
            Thread.Sleep(300);
            Assert.IsTrue((first.Cycles + second.Cycles) >= 13, "Cycles were " + (first.Cycles + second.Cycles));
            Console.WriteLine("First: " + first.Cycles);
            Console.WriteLine("Second: " + second.Cycles);
        }
        public void CoroutineIntShouldCallTheCoroutineWaitingForIt()
        {
            // ReSharper disable once ConvertToConstant.Local
            int hundred = 100;
            var ft      = new CoroutineThread(1);
            var co      = new LocalCoroutineWithWait();

            ft.AddCoroutine(co);
            ft.Start();
            Thread.Sleep(1000);
            ft.Stop();
            Thread.Sleep(300);
            Assert.IsTrue(co.LocalCalled);
            Assert.IsTrue(co.LocalSetted);
            Assert.AreEqual(0, co.Counter);
        }
        public void CoroutineIntShouldCallTheCoroutineWithData()
        {
            // ReSharper disable once ConvertToConstant.Local
            int hundred = 100;
            var data    = new Exception();
            var ft      = new CoroutineThread(1);
            var co      = new LocalCoroutineWithData(data);

            ft.AddCoroutine(co);
            ft.Start();
            Thread.Sleep(1000);
            ft.Stop();
            Thread.Sleep(300);
            Assert.IsTrue(co.LocalCalled);
            Assert.IsTrue(co.LocalSetted);
            Assert.AreEqual(data, co.Result);
        }
        public void CoroutineThreadIntShouldHandleCorrectlyTheSubroutines()
        {
            // ReSharper disable once ConvertToConstant.Local
            int hundred = 100;
            var ft      = new CoroutineThread(1);
            var first   = new CoroutineWithSub(hundred);
            var second  = new CoroutineWithSub(200);

            ft.AddCoroutine(first);            //, second);
            ft.Start();
            Thread.Sleep(1000);
            ft.Stop();
            Thread.Sleep(300);
            //Assert.AreEqual(15, (int)(first.Cycles + second.Cycles));
            Console.WriteLine("First: " + first.Cycles);
            Console.WriteLine("Second: " + second.Cycles);
        }