Esempio n. 1
0
        public void CreateAndExecute()
        {
            Counter counter = new Counter();

            ActionTask<Counter> action = new ActionTask<Counter>(counter, c => { c.Increment(); });

            Assert.AreEqual(0, counter.Count);
            action.Execute();
            Assert.AreEqual(1, counter.Count);
        }
Esempio n. 2
0
        public void InvokeIncrementTenTimes()
        {
            ManualResetEvent handle = new ManualResetEvent(false);

            Counter counter = new Counter();
            Actor<Counter> actor = new Actor<Counter>(counter);

            actor.Send(c => { for (int k=1; k<=10; k++) c.Increment(); handle.Set(); });

            handle.WaitOne();

            Assert.AreEqual(10, counter.Count);
        }
Esempio n. 3
0
        public void InvokeIncrement()
        {
            ManualResetEvent handle = new ManualResetEvent(false);

            Counter counter = new Counter();
            Actor<Counter> actor = new Actor<Counter>(counter);

            actor.Send(c => { c.Increment(); handle.Set(); });

            handle.WaitOne();

            Assert.AreEqual(1, counter.Count);
        }
Esempio n. 4
0
        public void InvokeIncrementInAnotherThread()
        {
            ManualResetEvent handle = new ManualResetEvent(false);
            Thread thread = null;

            Counter counter = new Counter();
            Actor<Counter> actor = new Actor<Counter>(counter);

            actor.Send(c => { c.Increment(); thread = Thread.CurrentThread; handle.Set(); });

            handle.WaitOne();

            Assert.AreEqual(1, counter.Count);
            Assert.IsNotNull(thread);
            Assert.AreNotSame(Thread.CurrentThread, thread);
        }