public void ItReturnsACalculatorForAValidType() { var factory = new DiscountFactory(); Assert.True(factory.TryGetCalculator(typeof(PointOfSalesystem.Inventory.HarryPotter.Book1), out IDiscountCalculator calculator)); Assert.AreEqual(typeof(HarryPotterDiscountCalculator), calculator.GetType()); }
IReadOnlyCollection <Product> IProductService.ApplyPromoCodeDiscount(IEnumerable <Product> products, PromoCode promoCode) { List <Product> productList = products.ToList(); if (promoCode == null) { return(productList); } //Find the products where the promo code can be applied. var promoCodeEligibleProducts = PromoCodeEligibleProducts(productList, promoCode); // divide the amount between all procucts equally decimal discountAmount = promoCode.DiscountAmount; if (promoCode.DiscountType == (int)DiscountType.PromoCodeFixed) { decimal sum = promoCodeEligibleProducts.Sum(p => p.Price * p.Quantity); discountAmount = ((discountAmount / sum) * 100); } if (discountAmount > 100) { discountAmount = 100; } foreach (Product product in promoCodeEligibleProducts) { // subract the %age amount from BusinessVolume and CommissionableVolume decimal?BV = (decimal)product.BusinessVolumeEachOverride == 0 ? 0M : product.BusinessVolumeEachOverride; decimal?CV = (decimal)product.CommissionableVolumeEachOverride == 0 ? 0M : product.CommissionableVolumeEachOverride; decimal?BVPercent = (decimal)BV - (((discountAmount) * BV) / 100); decimal?CVPercent = (decimal)CV - (((discountAmount) * CV) / 100); Discount discount = new DiscountFactory().CreateDiscount(DiscountType.PromoCode, discountAmount, promoCode.Code, BVPercent, CVPercent ); product.EligibleDiscounts.Add(discount); product.ApplyDiscount(discount); product.ApplyDiscountType = discount.DiscountType; } if (promoCode.ApplyToItemCodes == "All") { return(promoCodeEligibleProducts.AsReadOnly()); } foreach (var product in promoCodeEligibleProducts) { var i = productList.FindIndex(c => c.ItemCode == product.ItemCode); productList[i] = product; } return(productList.AsReadOnly()); }
public void ItDoesntReturnsACalculatorForAnInValidType() { var factory = new DiscountFactory(); Assert.False(factory.TryGetCalculator(typeof(PointOfSalesystem.Inventory.DanBrown.Book1), out IDiscountCalculator calculator)); Assert.Null(calculator); }
/// <summary> /// Заполнение случайными данными /// </summary> /// <param name="sender">Отправитель события</param> /// <param name="e">Аргументы события</param> private void ButtonAddRandom_Click(object sender, EventArgs e) { var random = new Random(); var type = (Discounts)random.Next(-1, 2); double price = 0; double discountValue = 0; while (price == 0) { type = (Discounts)random.Next(-1, 2); switch (type) { case Discounts.Percent: { price = random.Next(100, 1000); discountValue = random.Next(1, 98); break; } case Discounts.Coupon: { price = random.Next(100, 1000); discountValue = random.Next(50, 980); break; } } } _checkList.Add(new CheckPosition(DiscountFactory.GetDiscount (type, discountValue), new Product(price))); }
protected override void RefreshData() { DiscountFactory discountFactory = new DiscountFactory(); DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard(); Collection <DiscountCard> cards = dg.Select(); Collection <ExtendedCard> ecards = new Collection <ExtendedCard>(); foreach (DiscountCard dc in cards) { ExtendedCard ec = new ExtendedCard(); ec.CardId = dc.RecordId; ec.Credit = dc.Credit; if (dc.ClientId != null) { ClientFactory clientFactory = new ClientFactory(); ClientGateway <Client> cg = (ClientGateway <Client>)clientFactory.GetClient(); Client c = cg.Select((int)dc.ClientId); ec.Name = c.Name + " " + c.Surname; ec.ClientId = (int)dc.ClientId; } ecards.Add(ec); } BindingList <ExtendedCard> bindingList = new BindingList <ExtendedCard>(ecards); cardsGrid.AutoGenerateColumns = false; cardsGrid.DataSource = bindingList; }
public double DiscountValueTest(double value) { var checkPosition = new CheckPosition(DiscountFactory.GetDiscount(Discounts.Coupon, value), new Product(100)); return(checkPosition.DiscountValue); }
public double CheckPositionDiscountTest(double price, Discounts type, double value) { var checkPosition = new CheckPosition(DiscountFactory.GetDiscount(type, value), new Product(price)); return(checkPosition.CheckPositionDiscount); }
public void firstInitialize() { ClientFactory clientFactory = new ClientFactory(); ClientGateway <Client> cg = (ClientGateway <Client>)clientFactory.GetClient(); TrainingFactory trainingFactory = new TrainingFactory(); TrainingGateway <Training> tg = (TrainingGateway <Training>)trainingFactory.GetTraining(); DiscountFactory discountFactory = new DiscountFactory(); DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard(); PurchaseFactory purchaseFactory = new PurchaseFactory(); PurchaseGateway <Purchase> pg = (PurchaseGateway <Purchase>)purchaseFactory.GetPurchase(); TicketFactory ticketFactory = new TicketFactory(); TicketGateway <Ticket> ticketg = (TicketGateway <Ticket>)ticketFactory.GetTicket(); Client client = cg.Select(tg.SelectLast().ClientId); clientName.Text = client.ToString(); if (client.CardId != null) { int toSetId = client.CardId ?? default(int); card = dg.Select(toSetId); } Ticket t = ticketg.Select(pg.SelectLast(card.RecordId).TicketId); ticketType.Text = t.Type; credit.Text = card.Credit.ToString(); }
public IList <Product> GetAllProductsFor(CustomerType customerType) { IDiscountStrategy discountStrategy = DiscountFactory.GetDiscountStrategyFor(customerType); IList <Product> products = _productRepository.FindAll(); products.Apply(discountStrategy); return(products); }
protected override bool DeleteRecord() { DiscountFactory discountFactory = new DiscountFactory(); DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard(); dg.Delete(card.RecordId); return(true); }
public double CheckPositionPriceTest(double value) { var discount = DiscountFactory.GetDiscount(Discounts.Coupon, 11); var product = new Product(value); var checkPosition = new CheckPosition(discount, product); return(checkPosition.CheckPositionPrice); }
public void ProductTest(double value) { var discount = DiscountFactory.GetDiscount(Discounts.Coupon, 11); var product = new Product(value); var checkPosition = new CheckPosition(discount, product); Assert.AreSame(product, checkPosition.Product); }
public IList <Product> GetAllProductsFor(CustomerType customerType) { IDiscountStrategy _discountStrategy = DiscountFactory.GetDiscountStrategyFor(customerType); IList <Product> _productList = _productRepository.FindAll(); if (_productList != null) { _productList.Apply(_discountStrategy); } return(_productList); }
public bool UpdateProductsFor(CustomerType customerType, IList <Product> productList) { IDiscountStrategy _discountStrategy = DiscountFactory.GetDiscountStrategyFor(customerType); try { _productRepository.Update(productList); return(true); } catch { return(false); } }
public void test_discount_one_hundred_shades_of_pink() { var marketingCampaign = new MarketingCampaign( new MockDateTimeService( new DateTime(2020, 7, 1, 0, 0, 0, 2) ) ); var net = new Money(102); var discount = DiscountFactory.Create(marketingCampaign, net); var total = discount.DiscountFor(net); Assert.Equal(new Money(96.9m), total); }
public void test_discount_one_thousand_shades_of_grey() { var marketingCampaign = new MarketingCampaign( new MockDateTimeService( new DateTime(2020, 7, 1) ) ); var net = new Money(1002); var discount = DiscountFactory.Create(marketingCampaign, net); var total = discount.DiscountFor(net); Assert.Equal(new Money(901.8m), total); }
/// <summary> /// Apply discout for all StockKeepingUnit on the list and returns the total price /// </summary> /// <param name="scannedProducts">The list of items to apply the discount on</param> /// <returns>total price after discount has been applied on the items or 0 if the list is empty</returns> public int ApplyDicountForCheckoutItems(List <StockKeepingUnit> scannedProducts) { if (_discountRules.Count( ) == 0) { return((int)scannedProducts.Sum(x => x.Price)); } List <StockKeepingUnit> nonePromoProducts = scannedProducts.Where(x => !x.IsPromoProduct).ToList( ); List <StockKeepingUnit> promotionalProducts = scannedProducts.Where(x => x.IsPromoProduct).ToList( ); int totalDiscountedPrice = DiscountFactory.GetTotalPriceAfterDiscountForProducts(promotionalProducts, _discountRules); return(totalDiscountedPrice + (int)nonePromoProducts.Sum(x => x.Price)); }
public void test_no_discount_on_cheap_item() { var marketingCampaign = new MarketingCampaign( new MockDateTimeService( new DateTime(2020, 7, 1, 0, 0, 0, 2) ) ); var net = new Money(80); var discount = DiscountFactory.Create(marketingCampaign, net); var total = discount.DiscountFor(net); Assert.Equal(new Money(80m), total); }
public void test_discount_crazy_sales_tonight_fun_radio() { var marketingCampaign = new MarketingCampaign( new MockDateTimeService( new DateTime(2020, 7, 3, 0, 0, 0, 2) ) ); var net = new Money(100); var discount = DiscountFactory.Create(marketingCampaign, net); var total = discount.DiscountFor(net); Assert.Equal(new Money(85m), total); }
protected override bool DeleteRecord() { DiscountFactory discountFactory = new DiscountFactory(); DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard(); DiscountCard c = dg.Select((int)client.CardId); c.ClientId = null; dg.Update(c); ClientFactory clientFactory = new ClientFactory(); ClientGateway <Client> cg = (ClientGateway <Client>)clientFactory.GetClient(); cg.Delete(client.RecordId); return(true); }
private ShoppingCartItem(IShoppingCartItem item) { ID = (item.ID != Guid.Empty) ? item.ID : Guid.NewGuid(); ItemCode = GlobalUtilities.Coalesce(item.ItemCode); ParentItemCode = GlobalUtilities.Coalesce(item.ParentItemCode); Description = item.ItemDescription; ItemDescription = item.ItemDescription; Quantity = item.Quantity; DynamicKitCategory = GlobalUtilities.Coalesce(item.DynamicKitCategory); GroupMasterItemCode = GlobalUtilities.Coalesce(item.GroupMasterItemCode); Type = item.Type; Category = item.Category; PriceTypeID = item.PriceTypeID; Price = item.Price; PriceEachOverride = item.PriceEachOverride; BusinessVolumeEachOverride = item.BusinessVolumeEachOverride; CommissionableVolumeEachOverride = item.CommissionableVolumeEachOverride; ApplyDiscountType = item.ApplyDiscountType; AppliedAmount = item.AppliedAmount; InventoryStatus = item.InventoryStatus; OtherCheck1 = item.OtherCheck1; OtherCheck2 = item.OtherCheck2; OtherCheck3 = item.OtherCheck3; OtherCheck4 = item.OtherCheck4; OtherCheck5 = item.OtherCheck5; Field1 = item.Field1; Field2 = item.Field2; if (item.ApplyDiscountType == DiscountType.Unknown) { Discounts = new List <Discount>(); } else { var factory = new DiscountFactory(); Discounts = new List <Discount> { factory.CreateDiscount(ApplyDiscountType, item.AppliedAmount) }; } }
public OrderDTO procOrder(OrderDTO orderinfo) { int totalAmount = orderinfo.items .Select(item => item.quanity * item.unitPrice) .Sum(); IDiscountPrice d = DiscountFactory.getDiscount(orderinfo.discount, totalAmount); if (d != null) { orderinfo.TotalPrice = d.calcTotalAmountbyDiscount(orderinfo.discount, totalAmount); } else { orderinfo.TotalPrice = totalAmount; } return(orderinfo); }
public async Task PrepareNewOrderEmailAsync_Should_Return_Proper_Template() { // arrange var emailTemplate = await File.ReadAllTextAsync("./Resources/Emails/NewOrder.html"); var expected = await File.ReadAllTextAsync("./Resources/Emails/NewOrderExpected.html"); emailTemplateManagerMock.Setup(s => s.ReadTemplateAsync(It.IsAny <string>())).ReturnsAsync(emailTemplate); var order = new Order(UserFactory.CreateUser(), ProductsOrderFactory.GetProductsOrders(), DiscountFactory.GetOrderDiscount(), ShipmentFactory.GetShipment(), 30, 139, "Some comment", null); // var sut = new EmailService(emailTemplateManagerMock.Object); // // //act // var result = await sut.PrepareNewOrderEmailAsync(order); // // // assert // result.Should().BeEquivalentTo(expected); }
public override bool OpenRecord(object primaryKey) { DiscountFactory discountFactory = new DiscountFactory(); DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard(); if (primaryKey != null) { int idCard = (int)primaryKey; card = dg.Select(idCard); newRecord = false; } else { card = new DiscountCard(); newRecord = true; } BindData(); return(true); }
/// <summary> /// Gives a total cost for all items in the basket, after eligible discounts have been applied /// </summary> /// <returns>Total cost</returns> private double CalculateBasketTotal() { double cost = 0; // Allow for other IDiscountCalculator var discountFactory = new DiscountFactory(); foreach (var basketItemStack in Items) { if (discountFactory.TryGetCalculator(basketItemStack.Value.First().GetType(), out IDiscountCalculator discountCalculator)) { discountCalculator.ConsiderItemForDiscount(basketItemStack); } cost += basketItemStack.Value.Sum(i => i.Price); } var totalDiscount = discountFactory.GetCalculators().Sum(c => c.TotalDiscount); return(cost - totalDiscount); }
public void DiscountBaseTest(Discounts type) { switch (type) { case Discounts.Coupon: { var discount = DiscountFactory.GetDiscount(type, 11); var checkPosition = new CheckPosition(discount, new Product(10)); Assert.AreSame(discount, checkPosition.DiscountBase); break; } case Discounts.Percent: { var discount = DiscountFactory.GetDiscount(type, 11); var checkPosition = new CheckPosition(discount, new Product(10)); Assert.AreSame(discount, checkPosition.DiscountBase); break; } } }
public string DiscountTypeTest(Discounts type) { switch (type) { case Discounts.Coupon: { var discount = DiscountFactory.GetDiscount(type, 11); var checkPosition = new CheckPosition(discount, new Product(10)); return(checkPosition.DiscountType); } case Discounts.Percent: { var discount = DiscountFactory.GetDiscount(type, 11); var checkPosition = new CheckPosition(discount, new Product(10)); return(checkPosition.DiscountType); } } return("Ошибка"); }
public ProductListResponse GetAllProductsFor(ProductListRequest request) { ProductListResponse productListResponse = new ProductListResponse(); try { IDiscountStrategy discountStrategy = DiscountFactory.GetDiscountStrategyFor(request.CustomerType); IList <Product> products = _productRepository.FindAll(); products.Apply(discountStrategy); productListResponse.Products = products.ConvertToProductListViewModel(); productListResponse.Success = true; } catch (Exception ex) { productListResponse.Success = false; productListResponse.Message = ex.Message; } return(productListResponse); }
private void acceptButton_Click(object sender, EventArgs e) { Training t = new Training(); t.LockerId = lockers[comboLocker.SelectedIndex].RecordId; t.ClientId = clients[comboClient.SelectedIndex].RecordId; t.TrainerId = trainers[comboTrainer.SelectedIndex].RecordId; t.ToGender = clients[comboClient.SelectedIndex].Gender; t.TimeFrom = DateTime.Now; ClientFactory clientFactory = new ClientFactory(); ClientGateway <Client> cg = (ClientGateway <Client>)clientFactory.GetClient(); Client c = cg.Select(t.ClientId); DiscountFactory discountFactory = new DiscountFactory(); DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard(); DiscountCard card = new DiscountCard(); if (c.CardId != null) { int toSetId = c.CardId ?? 0; card = dg.Select(toSetId); } TrainingFactory trainingFactory = new TrainingFactory(); TrainingGateway <Training> tg = (TrainingGateway <Training>)trainingFactory.GetTraining(); tg.Insert(t); if (card != null && card.Credit > 0) { Forms.ChangeCredit form = new Forms.ChangeCredit(); form.ShowDialog(); } else { MessageBox.Show("Training was added successfully but client " + c.Name + " " + c.Surname + " has no credit on card!", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } this.Dispose(); }
protected override bool SaveRecord() { DiscountFactory discountFactory = new DiscountFactory(); DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard(); if (GetData()) { if (newRecord) { dg.Insert(card); } else { dg.Update(card); } return(true); } else { return(false); } }