Exemplo n.º 1
0
        public static void TestRecursiveUpdateFail()
        {
            CommandQueue queue = new CommandQueue();

            queue.Enqueue(
                Cmd.Queue(queue)
                );

            bool threwException = false;

            try {
                queue.Update(DELTA_TIME_RATE);
            } catch (InvalidOperationException) {
                threwException = true;
            }

            Assert.IsTrue(threwException, "Failed to throw exception from invalid state.");

            queue = new CommandQueue();
            queue.Enqueue(
                Cmd.Do(() => {
                queue.Update(DELTA_TIME_RATE);
            })
                );

            try {
                queue.Update(DELTA_TIME_RATE);
            } catch (InvalidOperationException) {
                threwException = true;
            }

            Assert.IsTrue(threwException, "Failed to throw exception from invalid state.");
        }
Exemplo n.º 2
0
        public static void TestQueue()
        {
            CommandQueue mainQueue   = new CommandQueue();
            CommandQueue secondQueue = new CommandQueue();

            bool firstCommandTriggered  = false;
            bool secondCommandTriggered = false;
            bool thirdCommandTriggered  = false;

            secondQueue.Enqueue(
                Cmd.Do(() => {
                Assert.IsTrue(!firstCommandTriggered);
                firstCommandTriggered = true;
            }),
                Cmd.Do(() => {
                Assert.IsTrue(firstCommandTriggered);
                Assert.IsTrue(!secondCommandTriggered);
                secondCommandTriggered = true;
            }),
                Cmd.Do(() => {
                Assert.IsTrue(firstCommandTriggered);
                Assert.IsTrue(secondCommandTriggered);
                Assert.IsTrue(!thirdCommandTriggered);
                thirdCommandTriggered = true;
            })
                );

            mainQueue.Enqueue(
                Cmd.Repeat(2,
                           Cmd.Queue(secondQueue)
                           )
                );

            while (!mainQueue.Update(DELTA_TIME_RATE))
            {
            }
        }