Example #1
0
        public void SalesmanShouldGetMoney()
        {
            Salesman salesman = new Salesman("Tor");
            Customer customer = new Customer("Hans");

            salesman.Wallet.Balance = 1000;
            var previousAmount = salesman.Wallet.Balance;

            salesman.GetItems().Add(ItemFactory.GetRandomItem(salesman));
            salesman.SellItem();

            // Waiting for the logic in other threads to finish
            Thread.Sleep(300);

            Assert.That(previousAmount, Is.LessThan(salesman.Wallet.Balance));
        }
Example #2
0
        public void ShouldBeThreadSafe()
        {
            ArrayList customers = new ArrayList();

            for (int i = 0; i < 10; i++)
            {
                customers.Add(PersonFactory.GetPerson(PersonType.Customer));
            }

            Salesman salesman = new Salesman("Knut");

            for (int i = 0; i < 20; i++)
            {
                salesman.GetItems().Add(ItemFactory.GetRandomItem(salesman));
                salesman.SellItem();
            }

            // Waiting for the logic in other threads to finish
            Thread.Sleep(500);

            int       uniqueCount = 0;
            ArrayList items       = new ArrayList();

            foreach (Customer c in customers)
            {
                foreach (IItem item in c.GetItems())
                {
                    if (!items.Contains(item))
                    {
                        items.Add(item);
                        uniqueCount++;
                    }
                }
            }
            Assert.That(uniqueCount, Is.EqualTo(20));
        }