private void TestAddAudioSysThenEntitySysLoopImpl(Game game, int loopCount, int loopCountSum)
        {
            var listenerProcessor = game.Entities.Processors.OfType <AudioListenerProcessor>().First();

            if (loopCount == 1)
            {
                // add the listeners entities to the entity system.
                game.Entities.Add(rootEntity);
                AudioListenerProcessor.AssociatedData list1Data = null;
                AudioListenerProcessor.AssociatedData list2Data = null;

                // check that the entities are immediately present in the matching entity list after addition to the Entity system.
                Assert.DoesNotThrow(() => list1Data = listenerProcessor.MatchingEntitiesForDebug[listComp1Entity], "Listener Component 1 entity is not present in listener processor matching entities");
                Assert.DoesNotThrow(() => list2Data = listenerProcessor.MatchingEntitiesForDebug[listComp2Entity], "Listener Component 2 entity is not present in listener processor matching entities");

                // check that the entities' position are immediately computed after addition to the Entity system.
                Assert.AreEqual(2 * new Vector3(loopCountSum, 2 * loopCountSum, 3 * loopCountSum), list1Data.AudioListener.Position, "The Position of the listener1 is not valid at loop turn " + loopCount);
                Assert.AreEqual(Vector3.Zero, list2Data.AudioListener.Position, "The Position of the listener2 is not valid at loop turn " + loopCount);

                // check that the listener components are marked for update immediately after addition to the Entity system.
                Assert.IsTrue(list1Data.ShouldBeComputed, "The value of should be computed for listener 1 is not valid at loop turn " + loopCount);
            }
            else if (loopCount > 2 && loopCount < 5)
            {
                var list1Data = listenerProcessor.MatchingEntitiesForDebug[listComp1Entity];
                var list2Data = listenerProcessor.MatchingEntitiesForDebug[listComp2Entity];

                // check the values of the Positions after update
                Assert.AreEqual(2 * new Vector3(loopCountSum, 2 * loopCountSum, 3 * loopCountSum), list1Data.AudioListener.Position, "The Position of the listener1 is not valid at loop turn " + loopCount);
                Assert.AreEqual(Vector3.Zero, list2Data.AudioListener.Position, "The Position of the listener2 is not valid at loop turn " + loopCount);

                // check the values of the Velocities after update
                Assert.AreEqual(2 * new Vector3(loopCount, 2 * loopCount, 3 * loopCount), list1Data.AudioListener.Velocity, "The velocity of the listener1 is not valid at loop turn " + loopCount);
                Assert.AreEqual(Vector3.Zero, list2Data.AudioListener.Velocity, "The velocity of the listener2 is not valid at loop turn " + loopCount);

                // check the values of the Forward vectors after update
                Assert.IsTrue((list2Data.AudioListener.Forward - new Vector3(0, -1, 0)).Length() < 1e-7, "The forward vector of listener2 is not valid at loop turn " + loopCount);
                Assert.AreEqual(new Vector3(0, 0, 1), list1Data.AudioListener.Forward, "The forward vector of the listener1 is not valid at loop turn " + loopCount);

                // check the values of the Up vectors after update
                Assert.IsTrue((list2Data.AudioListener.Up - new Vector3(0, 0, 1)).Length() < 1e-7, "The Up vector of the listener2 is not valid at loop turn " + loopCount);
                Assert.AreEqual(new Vector3(0, 1, 0), list1Data.AudioListener.Up, "The Up vector of listener1 is not valid at loop turn " + loopCount);

                // check that component is still marked for update for next turn.
                Assert.IsTrue(list1Data.ShouldBeComputed, "The value of should be computed for listener 1 is not valid at loop turn " + loopCount);
            }
            else
            {
                game.Exit();
            }
        }
        private void TestAddEntitySysThenAudioSysLoopImpl(Game game, int loopCount, int loopCountSum)
        {
            var audio             = game.Audio;
            var listenerProcessor = game.Entities.Processors.OfType <AudioListenerProcessor>().First();

            if (loopCount == 1)
            {
                AudioListenerProcessor.AssociatedData list1Data = null;
                AudioListenerProcessor.AssociatedData list2Data = null;

                // check that the entities are present in the processor matching list even though they have not been added to the audio system
                Assert.DoesNotThrow(() => list1Data = listenerProcessor.MatchingEntitiesForDebug[listComp1Entity], "Listener Component 1 entity is not present in listener processor matching entities");
                Assert.DoesNotThrow(() => list2Data = listenerProcessor.MatchingEntitiesForDebug[listComp2Entity], "Listener Component 2 entity is not present in listener processor matching entities");

                // check that the entities are not marked for update when they have not been added the audio System.
                Assert.IsFalse(list1Data.ShouldBeComputed, "The value of should be computed for listener 1 is not valid at loop turn " + loopCount);
            }
            else if (loopCount == 2)
            {
                // add listener 1 to the audio system.
                audio.AddListener(listComp1);
                AudioListenerProcessor.AssociatedData list1Data = listenerProcessor.MatchingEntitiesForDebug[listComp1Entity];
                AudioListenerProcessor.AssociatedData list2Data = listenerProcessor.MatchingEntitiesForDebug[listComp2Entity];

                // check that listener 1 is marked for update but not listener 2.
                Assert.IsTrue(list1Data.ShouldBeComputed, "The value of should be computed for listener 1 is not valid at loop turn " + loopCount);
                Assert.IsFalse(list2Data.ShouldBeComputed, "The value of should be computed for listener 2 is not valid at loop turn " + loopCount);

                // check that the listener 1's position is valid immediately after its addition to the audio system.
                Assert.AreEqual(2 * new Vector3(loopCountSum, 2 * loopCountSum, 3 * loopCountSum), list1Data.AudioListener.Position, "The Position of the listener1 is not valid at loop turn " + loopCount);
            }
            else if (loopCount == 3)
            {
                // add listener 2 to the audio system.
                audio.AddListener(listComp2);
                AudioListenerProcessor.AssociatedData list1Data = listenerProcessor.MatchingEntitiesForDebug[listComp1Entity];
                AudioListenerProcessor.AssociatedData list2Data = listenerProcessor.MatchingEntitiesForDebug[listComp2Entity];

                // check that both listeners are marked for update.
                Assert.IsTrue(list1Data.ShouldBeComputed, "The value of should be computed for listener 1 is not valid at loop turn " + loopCount);
                Assert.IsTrue(list2Data.ShouldBeComputed, "The value of should be computed for listener 2 is not valid at loop turn " + loopCount);

                // check that the listener 2's position is valid directly after its addition to the system.
                Assert.AreEqual(Vector3.Zero, list2Data.AudioListener.Position, "The Position of the listener2 is not valid at loop turn " + loopCount);

                // check the listener 1's position, velocity, up and forward values have been correctly updated.
                Assert.AreEqual(2 * new Vector3(loopCountSum, 2 * loopCountSum, 3 * loopCountSum), list1Data.AudioListener.Position, "The Position of the listener1 is not valid at loop turn " + loopCount);
                Assert.AreEqual(2 * new Vector3(loopCount, 2 * loopCount, 3 * loopCount), list1Data.AudioListener.Velocity, "The velocity of the listener1 is not valid at loop turn " + loopCount);
                Assert.AreEqual(new Vector3(0, 0, 1), list1Data.AudioListener.Forward, "The forward vector of the listener1 is not valid at loop turn " + loopCount);
                Assert.AreEqual(new Vector3(0, 1, 0), list1Data.AudioListener.Up, "The Up vector of listener1 is not valid at loop turn " + loopCount);
            }
            else if (loopCount > 3 && loopCount < 6)
            {
                var list1Data = listenerProcessor.MatchingEntitiesForDebug[listComp1Entity];
                var list2Data = listenerProcessor.MatchingEntitiesForDebug[listComp2Entity];

                // check that both listeners' position are correctly updated.
                Assert.AreEqual(2 * new Vector3(loopCountSum, 2 * loopCountSum, 3 * loopCountSum), list1Data.AudioListener.Position, "The Position of the listener1 is not valid at loop turn " + loopCount);
                Assert.AreEqual(Vector3.Zero, list2Data.AudioListener.Position, "The Position of the listener2 is not valid at loop turn " + loopCount);

                // check that both listeners' velocity are correctly updated.
                Assert.AreEqual(2 * new Vector3(loopCount, 2 * loopCount, 3 * loopCount), list1Data.AudioListener.Velocity, "The velocity of the listener1 is not valid at loop turn " + loopCount);
                Assert.AreEqual(Vector3.Zero, list2Data.AudioListener.Velocity, "The velocity of the listener2 is not valid at loop turn " + loopCount);

                // check that both listeners' up vector are correctly updated.
                Assert.AreEqual(new Vector3(0, 1, 0), list1Data.AudioListener.Up, "The Up vector of listener1 is not valid at loop turn " + loopCount);
                Assert.IsTrue((list2Data.AudioListener.Up - new Vector3(0, 0, 1)).Length() < 1e-7, "The Up vector of the listener2 is not valid at loop turn " + loopCount);

                // check that both listeners' forward vector are correctly updated.
                Assert.AreEqual(new Vector3(0, 0, 1), list1Data.AudioListener.Forward, "The forward vector of the listener1 is not valid at loop turn " + loopCount);
                Assert.IsTrue((list2Data.AudioListener.Forward - new Vector3(0, -1, 0)).Length() < 1e-7, "The forward vector of listener2 is not valid at loop turn " + loopCount);

                // check that both listeners are still marked for update for next turn.
                Assert.IsTrue(list1Data.ShouldBeComputed, "The value of should be computed for listener 1 is not valid at loop turn " + loopCount);
            }
            else
            {
                game.Exit();
            }
        }