public void Buy_ControlPassedToPaymentSystem()
        {
            DeliverySystemSubstitute deliverySystem = new DeliverySystemSubstitute();

            deliverySystem.ResultOfIsItemPresent  = true;
            deliverySystem.ResultOfTryDeliverItem = true;

            VendingMachine vendingMachine = new VendingMachine(deliverySystem);

            VendingItem item = new VendingItem(new VendingItemId(0), ItemType.Drink, "Water", 1);

            vendingMachine.AddItemToCatalogue(item);

            PaymentSystemSubstitute paymentSystem = new PaymentSystemSubstitute();

            paymentSystem.ResultOfWithholdOfPayment = true;

            bool controlPassed;

            try
            {
                vendingMachine.BuyItem(item, paymentSystem);

                controlPassed = paymentSystem.ControlPassedTryWithholdPayment && paymentSystem.ControlPassedCompleteTransaction;
            }
            catch (Exception e)
            {
                controlPassed = paymentSystem.ControlPassedTryWithholdPayment && paymentSystem.ControlPassedRevokeTransaction;

                Assert.IsTrue(controlPassed);
            }
            Assert.IsTrue(controlPassed);
        }
        public void Buy_DenialOfPaymentSystem_ThrowsException()
        {
            DeliverySystemSubstitute deliverySystem = new DeliverySystemSubstitute();

            deliverySystem.ResultOfIsItemPresent  = true;
            deliverySystem.ResultOfTryDeliverItem = true;

            VendingMachine vendingMachine = new VendingMachine(deliverySystem);

            VendingItem item = new VendingItem(new VendingItemId(0), ItemType.Drink, "Water", 1);

            vendingMachine.AddItemToCatalogue(item);

            PaymentSystemSubstitute paymentSystem = new PaymentSystemSubstitute();

            paymentSystem.ResultOfWithholdOfPayment = false;

            Assert.Catch(() => vendingMachine.BuyItem(item, paymentSystem));
        }
        public void Buy_ControlPassedToDeliverySystem()
        {
            DeliverySystemSubstitute deliverySystem = new DeliverySystemSubstitute();

            deliverySystem.ResultOfIsItemPresent  = true;
            deliverySystem.ResultOfTryDeliverItem = true;

            VendingMachine vendingMachine = new VendingMachine(deliverySystem);

            VendingItem item = new VendingItem(new VendingItemId(0), ItemType.Drink, "Water", 1);

            vendingMachine.AddItemToCatalogue(item);

            PaymentSystemSubstitute paymentSystem = new PaymentSystemSubstitute();

            paymentSystem.ResultOfWithholdOfPayment = true;

            vendingMachine.BuyItem(item, paymentSystem);

            bool controlPassed = deliverySystem.ControlPassedIsItemPresent && deliverySystem.ControlPassedTryDeliverItem;

            Assert.IsTrue(controlPassed);
        }