Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to online purchase system");
            Console.WriteLine("Please type below Product name exactly to initiate the purchase");
            Console.WriteLine(" 1. PhysicalProduct \n 2. Book \n 3. Membership \n 4. UpgradeMembership \n 5. Video");

            ConcretePurchaseFactory cFactory = new ConcretePurchaseFactory();

            do
            {
                Console.WriteLine("Enter the Purchase Type");

                string type = Console.ReadLine();
                try
                {
                    IPurchase Purchase = cFactory.GetPurchaseType(type);

                    var actions = Purchase.Actions();

                    actions.ForEach(a => { Console.WriteLine(a); });
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Purchase"))
                    {
                        Console.WriteLine("Invalid Purchase");
                    }
                }

                Console.WriteLine("Type Exit to complete the purchase or press Enter to continue");
            } while(Console.ReadLine().ToLower() != "exit");
        }
Esempio n. 2
0
        public void TestMethod_ForVideo()
        {
            Purchase = factory.GetPurchaseType("Video");
            var actions = Purchase.Actions();

            Assert.IsNotNull(actions);
            Assert.IsTrue(actions.Count == 2);
        }
Esempio n. 3
0
        public void TestMethod_ForPhysicalProduct()
        {
            Purchase = factory.GetPurchaseType("PhysicalProduct");
            var actions = Purchase.Actions();

            Assert.IsNotNull(actions);
            Assert.IsTrue(actions.Count == 2);
        }
Esempio n. 4
0
        public void TestMethod_ForUpgradeMembership()
        {
            Purchase = factory.GetPurchaseType("UpgradeMembership");
            var actions = Purchase.Actions();

            Assert.IsNotNull(actions);
            Assert.IsTrue(actions.Count == 2);
        }
Esempio n. 5
0
        public void TestMethod_ForBook()
        {
            Purchase = factory.GetPurchaseType("Book");
            var actions = Purchase.Actions();

            Assert.IsNotNull(actions);
            Assert.IsTrue(actions.Count == 3);
        }