static void Main(string[] args) { Console.WriteLine("Please Select Payment Type : CreditCard or DebitCard or Cash"); string PaymentType = Console.ReadLine(); Console.WriteLine("Payment type is : " + PaymentType); Console.WriteLine("\nPlease enter Amount to Pay : "); double Amount = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Amount is : " + Amount); PaymentContext context = new PaymentContext(); if ("CreditCard".Equals(PaymentType, StringComparison.InvariantCultureIgnoreCase)) { context.SetPaymentStrategy(new CreditCardPaymentStrategy()); } else if ("DebitCard".Equals(PaymentType, StringComparison.InvariantCultureIgnoreCase)) { context.SetPaymentStrategy(new DebitCardPaymentStrategy()); } else if ("Cash".Equals(PaymentType, StringComparison.InvariantCultureIgnoreCase)) { context.SetPaymentStrategy(new CashPaymentStrategy()); } context.Pay(Amount); Console.ReadKey(); }
public void Test_Payment() { IPaymentStrategy paymentStrategy = new DebitCardPaymentStrategy(); PaymentContext paymentContext = new PaymentContext(paymentStrategy); paymentContext.Pay(135.1); paymentStrategy = new CashCardPaymentStrategy(); paymentContext.SetPaymentStrategy(paymentStrategy); paymentContext.Pay(57.1); paymentStrategy = new CreditCardPaymentStrategy(); paymentContext.SetPaymentStrategy(paymentStrategy); paymentContext.Pay(45.96); }