Exemplo n.º 1
0
        public void DiscountTest()
        {
            IPriceDiscount pDiscount = new PriceDiscount();

            Assert.AreEqual(80, pDiscount.CalcDiscount(rate: 20, price: 100));
            Assert.AreEqual(80.004m, pDiscount.CalcDiscount(rate: 20, price: 100.005m));
            Assert.AreEqual(100, pDiscount.CalcDiscount(rate: 0, price: 100));
        }
Exemplo n.º 2
0
        public async Task <int> Handle(CreatePriceDiscountCommand request, CancellationToken cancellationToken)
        {
            var priceDiscount = new PriceDiscount();

            request.Rules.ToList().ForEach(x =>
            {
                priceDiscount.Rules.Add(x);
            });

            _context.PriceDiscounts.Add(priceDiscount);
            await _context.SaveChangesAsync(cancellationToken);

            return(priceDiscount.Id);
        }
Exemplo n.º 3
0
        static void Main()
        {
            Form1       view  = new Form1();
            List <item> items = item.all();

            CashierController controller = new CashierController(view, items);

            controller.Cashier.ClearDiscounts();

            PercentComboDiscount comboDiscount = new PercentComboDiscount();

            comboDiscount.Ids        = new int[] { 0, 2, 3 };
            comboDiscount.Quantities = new int[] { 2, 1, 1 };
            comboDiscount.Percent    = 40; //40%
            controller.Cashier.AddDiscount(comboDiscount);

            PriceComboDiscount comboDiscount1 = new PriceComboDiscount();

            comboDiscount1.Ids        = new int[] { 0, 2 };
            comboDiscount1.Quantities = new int[] { 1, 1 };
            comboDiscount1.Price      = 5000; //VND
            controller.Cashier.AddDiscount(comboDiscount1);

            PercentDiscount discount = new PercentDiscount();

            discount.ItemId  = 3;
            discount.Percent = 10; //10%
            //controller.Cashier.AddDiscount(discount);

            PriceDiscount discount1 = new PriceDiscount();

            discount1.ItemId = 2;
            discount1.Price  = 4000; //VND
            //controller.Cashier.AddDiscount(discount1);

            controller.LoadView();
            view.ShowDialog();
        }
Exemplo n.º 4
0
        public async Task ShouldApplyOnThursdayToAfricaAndSaveIt()
        {
            var tenant = new Tenant
            {
                TenantGroup = Domain.Enums.TenantGroup.A
            };

            Context.Tenants.Add(tenant);

            // lot w urodziny tenanta
            var priceDiscount1 = new PriceDiscount();

            priceDiscount1.Rules.Add(new PriceDiscountRule
            {
                FieldName = "IsOnTenantBirthday",
                Value     = "True"
            });
            // lot w czwartek do Afryki
            var priceDiscount2 = new PriceDiscount();

            priceDiscount2.Rules.Add(new PriceDiscountRule
            {
                FieldName = "To",
                Value     = "Africa"
            });
            priceDiscount2.Rules.Add(new PriceDiscountRule
            {
                FieldName = "IsOnThursday",
                Value     = "True"
            });

            Context.PriceDiscounts.AddRange(priceDiscount1, priceDiscount2);

            var flight = new Flight
            {
                DefaultPrice = 25,
                To           = "Africa",
                CreatedBy    = tenant,
                Thursday     = true
            };

            Context.Flights.Add(flight);

            var flightPurchase = new FlightPurchase
            {
                DepartureDateTime = DateTimeOffset.Parse("2021-02-11T10:00:00Z"), // czwartek
                Flight            = flight,
                Price             = 25,
                Tenant            = tenant
            };

            Context.FlightPurchases.Add(flightPurchase);
            Context.SaveChanges();

            var applyDiscountCommandHandler = new ApplyPriceDiscountCommandHandler(Context);
            var newPrice = await applyDiscountCommandHandler.Handle(new ApplyPriceDiscountCommand {
                FlightPurchase = _mapper.Map <FlightPurchaseDto>(flightPurchase)
            }, CancellationToken.None);

            // jedna zniżka uwzględniona
            Assert.AreEqual(20, newPrice);
            // zniżka zapisana dla tenanta grupy A
            Assert.IsTrue(Context.FlightPurchases.First().Discounts.Count > 0);
        }