static public ISku CreateandReturnObj(SkuType skuType) { ISku ObjSelector = null; switch (skuType) { case SkuType.A: ObjSelector = new SkuTypeA(); break; case SkuType.B: ObjSelector = new SkuTypeB(); break; case SkuType.C: ObjSelector = new SkuTypeC(); break; case SkuType.D: ObjSelector = new SkuTypeD(); break; case SkuType.CD: ObjSelector = new SkuTypeCD(); break; } return(ObjSelector); }
public void ScenarioA() { SKUService sKUService = new SKUService(); ISku sku = sKUService; List <SKU> skuScenarioA = new List <SKU> { new SKU { Id = "a" }, new SKU { Id = "b" }, new SKU { Id = "c" } }; foreach (SKU pr in skuScenarioA) { sku.GetPriceByType(pr); } int output = sku.GetTotalPrice(skuScenarioA); Assert.AreEqual(100, output); }
static void Main(string[] args) { SKUService sKUService = new SKUService(); ISku sku = sKUService; List <SKU> skus = new List <SKU>(); Console.WriteLine("Total number of orders"); int a = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < a; i++) { Console.WriteLine("Enter the type of product:A,B,C or D"); string type = Console.ReadLine(); SKU p = new SKU(type); skus.Add(p); sku.GetPriceByType(p); } int totalPrice = sku.GetTotalPrice(skus); Console.WriteLine(totalPrice); Console.ReadLine(); }
public bool TryGetSku(string item, out ISku sku) { sku = AvailableSkus.SingleOrDefault(s => (item ?? "").Equals(s.Name.ToString(), StringComparison.InvariantCultureIgnoreCase)); return(sku != null); }
static void Main(string[] args) { bool flag = false; double result = 0; int numberC = 0; int numberD = 0; double TotalValue = 0; //Here calling all one by one for calculating all amounts. //We can conditionally create instance and process the order accordingly. //To calculate all order (sum) i'm assuming user will accept number of products (units) ISku ObjInterface = null; Console.Write("Enter number of Units For A: "); string input = Console.ReadLine(); if (!string.IsNullOrEmpty(input)) { ObjInterface = SkuFactory.CreateandReturnObj(SkuType.A); result = ObjInterface.ActivePromotion(Convert.ToInt32(input)); TotalValue += result; } Console.Write("Enter number of Units For B: "); input = Console.ReadLine(); if (!string.IsNullOrEmpty(input)) { ObjInterface = SkuFactory.CreateandReturnObj(SkuType.B); result = ObjInterface.ActivePromotion(Convert.ToInt32(input)); TotalValue += result; } Console.Write("Enter number of Units For C : "); input = Console.ReadLine(); if (!string.IsNullOrEmpty(input)) { numberC = Convert.ToInt32(input); } Console.Write("Enter number of Units For D : "); input = Console.ReadLine(); if (!string.IsNullOrEmpty(input)) { numberD = Convert.ToInt32(input); } if (numberC > 0 && numberD > 0) { ObjInterface = SkuFactory.CreateandReturnObj(SkuType.CD); int totalNumberofUnits = numberC + numberD; result = ObjInterface.ActivePromotion(totalNumberofUnits); TotalValue = TotalValue + result; flag = true; } if (numberC >= 1 && (!flag)) { ObjInterface = SkuFactory.CreateandReturnObj(SkuType.C); result = ObjInterface.ActivePromotion(numberC); TotalValue = TotalValue + result; } if (numberD >= 1 && (!flag)) { ObjInterface = SkuFactory.CreateandReturnObj(SkuType.D); result = ObjInterface.ActivePromotion(numberD); TotalValue = TotalValue + result; } Console.WriteLine("Final Total Order Value : " + TotalValue); Console.ReadLine(); }