Esempio n. 1
0
        public void Both_Card_Accessed__Same_Time_Will_Reduce_Linked_Account_Balance()
        {
            var tasks = new List <Task>();

            for (int i = 0; i < 10; i++)
            {
                if (i % 2 == 0)
                {
                    tasks.Add(Task.Factory.StartNew(() => card2.DebitAmount(.5f)));
                }
                else
                {
                    tasks.Add(Task.Factory.StartNew(() => card1.DebitAmount(.5f)));
                }
            }
            Task.WaitAll(tasks.ToArray());

            Assert.AreEqual(5, jointAccount.Balance); //Init balance 10 , .5 * 5 + .5 * 5
        }