public void TestAsynchronousUpdate()
        {
            using (
                ParticleSystemManager manager = new ParticleSystemManager(
                    this.mockedGraphicsDeviceService
                    )
                ) {
                // Add one particle system where there's stuff to do
                ParticleSystem <SimpleParticle> test = new ParticleSystem <SimpleParticle>(16);
                for (int index = 0; index < test.Capacity; ++index)
                {
                    test.AddParticle(new SimpleParticle());
                }
                test.Affectors.Add(new SlowAffector());
                manager.AddParticleSystem(test, dontPrune, new DummyRenderer <SimpleParticle>());

                // Add 16 other particle systems
                for (int index = 0; index < 16; ++index)
                {
                    manager.AddParticleSystem(
                        new ParticleSystem <SimpleParticle>(100),
                        dontPrune, new DummyRenderer <SimpleParticle>()
                        );
                }

                // Now update everything
                for (int repetition = 0; repetition < 2; ++repetition)
                {
                    IAsyncResult asyncResult = manager.BeginUpdate(2, 4, null, null);
                    manager.EndUpdate(asyncResult);
                }
            }
        }
 public void TestThrowOnWrongAsyncResultInEndUpdate()
 {
     using (
         ParticleSystemManager manager = new ParticleSystemManager(
             this.mockedGraphicsDeviceService
             )
         ) {
         IAsyncResult asyncResult = manager.BeginUpdate(1, 1, null, null);
         try {
             Assert.Throws <ArgumentException>(
                 delegate() { manager.EndUpdate(null); }
                 );
         }
         finally {
             manager.EndUpdate(asyncResult);
         }
     }
 }
        public void TestAsynchronousUpdateCallback()
        {
            using (
                ParticleSystemManager manager = new ParticleSystemManager(
                    this.mockedGraphicsDeviceService
                    )
                ) {
                CallbackReceiver receiver = new CallbackReceiver();
                object           state    = new object();

                IAsyncResult asyncResult = manager.BeginUpdate(
                    1, 1, receiver.Callback, state
                    );
                manager.EndUpdate(asyncResult);

                Assert.AreSame(state, receiver.State);
                Assert.IsFalse(asyncResult.CompletedSynchronously);
            }
        }
        public void TestThrowDuringAsynchronousUpdate()
        {
            using (
                ParticleSystemManager manager = new ParticleSystemManager(
                    this.mockedGraphicsDeviceService
                    )
                ) {
                ParticleSystem <SimpleParticle> test = new ParticleSystem <SimpleParticle>(4096);
                for (int index = 0; index < test.Capacity; ++index)
                {
                    test.AddParticle(new SimpleParticle());
                }
                test.Affectors.Add(new ExceptionThrowingAffector());

                manager.AddParticleSystem(test, dontPrune, new DummyRenderer <SimpleParticle>());

                IAsyncResult asyncResult = manager.BeginUpdate(1, 1, null, null);
                Assert.Throws <ArithmeticException>(
                    delegate() { manager.EndUpdate(asyncResult); }
                    );
            }
        }