public void Test_PriceFactory_ReturnsPrivilegedPriceProduct() { var priceRequest = new PriceRequest { UserType = (long)UserTypeEnum.NormalUser }; PriceCalculatorFactory factory = new PriceCalculatorFactory(); var arg = new AbstractPriceCreateArg { UserType = (UserTypeEnum)priceRequest.UserType }; var product = new AbstractPriceCreateResponse { Product = new NormalPriceProduct(null) }; factoryMock.Setup(p => p.Create(arg)).Returns(product); var result = factory.Create(arg); Assert.NotNull(result.Product); Assert.True(result.Product.GetType() == typeof(NormalPriceProduct)); }
/// <summary> /// This method applies the appropriate discounts on each of the scanned item /// The discount is applied by invoking the corresponding Discount Type interface /// </summary> public void CheckOut() { try { //Assign product details to each scanned item AssignProductDetailsToScannedItems(); //get unique scanned items var uniqueProductIds = scannedItems.Select(i => i.ProductId).Distinct().ToList(); //Apply the discount for each set of unique scanned items uniqueProductIds.ForEach(pId => { //If the scanned item is not present in the Product catalog then price will not be calculated //If the scanned item is not present in the Product catalog then Product id = 0 if (pId != 0) { var items = scannedItems.FindAll(item => item.ProductId == pId); var discountType = Products.Find(p => p.ProductId == pId).DiscountType; calculator = PriceCalculatorFactory.GetPriceCalculator(discountType); if (calculator != null) { var discount = Discounts.Find(dis => dis.ProductId == pId); //Call the Calculator calculator.CalculatePrice(items, discount); } } }); } catch (Exception ex) { throw new ApplicationException("Exception during Checkout process", ex); } PrintReceipt(); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteProductPriceManager" /> class. /// </summary> /// <param name="serviceClientArgsFactory">The service client args factory.</param> /// <param name="priceCalculatorFactory">The price calculator factory.</param> /// <param name="shopContext">The shop context.</param> public RemoteProductPriceManager(ServiceClientArgsFactory serviceClientArgsFactory, PriceCalculatorFactory priceCalculatorFactory, ShopContext shopContext) : base(priceCalculatorFactory, shopContext) { Assert.ArgumentNotNull(serviceClientArgsFactory, "serviceClientArgsFactory"); this.serviceClientArgsFactory = serviceClientArgsFactory; }
/// <summary> /// Initializes a new instance of the <see cref="ProductPriceManager" /> class. /// </summary> /// <param name="priceCalculatorFactory">The price calculator factory.</param> /// <param name="shopContext">The shop context.</param> public ProductPriceManager(PriceCalculatorFactory priceCalculatorFactory, ShopContext shopContext) { this.priceCalculatorFactory = priceCalculatorFactory; this.shopContext = shopContext; }