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); }
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); }
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); }
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); }