public void CanUpdatesTicketCorrectly()
 {
     var ticket = new Ticket();
     var orderSelector = new OrderSelector();
     orderSelector.UpdateTicket(ticket);
     Assert.AreEqual(ticket, orderSelector.SelectedTicket);
 }
        public void CanHandleTax()
        {
            var taxTemplate = new TaxTemplate { Name = "Tax", Rate = 10, AccountTransactionType = AccountTransactionType.Default };
            var taxTemplates = new List<TaxTemplate> { taxTemplate };

            var tost = new MenuItem("Tost") { Id = 1 };
            var hamburger = new MenuItem("Hamburger") { Id = 2 };
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default).Build();

            var order = ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", tost, taxTemplates, new MenuItemPortion { Price = 5, Name = "Adet" }, "", null);

            order.Quantity = 2;
            order.PortionCount = 2;
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", tost, taxTemplates, new MenuItemPortion { Price = 5, Name = "Adet" }, "", null);
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", hamburger, taxTemplates, new MenuItemPortion { Price = 7, Name = "Adet" }, "", null);
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", hamburger, taxTemplates, new MenuItemPortion { Price = 6, Name = "Adet" }, "", null);
            ticket.AddCalculation(new CalculationType() { AccountTransactionType = AccountTransactionType.Default, DecreaseAmount = true }, 10);
            ticket.Recalculate();

            var orderSelector = new OrderSelector();
            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(ticket.GetSum(), orderSelector.Selectors.Sum(x => x.TotalPrice));

            ticket.TaxIncluded = true;
            orderSelector = new OrderSelector();
            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(ticket.GetSum(), orderSelector.Selectors.Sum(x => x.TotalPrice));

        }        
 private static OrderSelector SetupOrderSelector()
 {
     var ticket = SetupTicket();
     var orderSelector = new OrderSelector();
     orderSelector.UpdateTicket(ticket);
     return orderSelector;
 }
        private static OrderSelector SetupOrderSelector()
        {
            var ticket        = SetupTicket();
            var orderSelector = new OrderSelector();

            orderSelector.UpdateTicket(ticket);
            return(orderSelector);
        }
        public void CanUpdatesTicketCorrectly()
        {
            var ticket        = new Ticket();
            var orderSelector = new OrderSelector();

            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(ticket, orderSelector.SelectedTicket);
        }
 public void CanHandleMultipleUpdates()
 {
     var ticket = SetupTicket();
     var orderSelector = new OrderSelector();
     orderSelector.UpdateTicket(ticket);
     Assert.AreEqual(28, orderSelector.RemainingTotal);
     orderSelector.UpdateTicket(ticket);
     Assert.AreEqual(28, orderSelector.RemainingTotal);
 }
        public void CanHandleMultipleUpdates()
        {
            var ticket        = SetupTicket();
            var orderSelector = new OrderSelector();

            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(28, orderSelector.RemainingTotal);
            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(28, orderSelector.RemainingTotal);
        }
        public void CanUpdatePaidTicketItems()
        {
            var ticket        = SetupTicket();
            var orderSelector = new OrderSelector();

            orderSelector.UpdateTicket(ticket);
            orderSelector.Select(1, 5);
            orderSelector.Select(2, 6);
            orderSelector.PersistSelectedItems();
            orderSelector.PersistTicket();
            Assert.AreEqual(2, ticket.PaidItems.Sum(x => x.Quantity));
        }
Beispiel #9
0
        public void CanHandleTax()
        {
            var taxTemplate = new TaxTemplate {
                Name = "Tax", Rate = 10, AccountTransactionType = AccountTransactionType.Default
            };
            var taxTemplates = new List <TaxTemplate> {
                taxTemplate
            };

            var tost = new MenuItem("Tost")
            {
                Id = 1
            };
            var hamburger = new MenuItem("Hamburger")
            {
                Id = 2
            };
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default).Build();

            var order = ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", tost, taxTemplates, new MenuItemPortion {
                Price = 5, Name = "Adet"
            }, "", null);

            order.Quantity     = 2;
            order.PortionCount = 2;
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", tost, taxTemplates, new MenuItemPortion {
                Price = 5, Name = "Adet"
            }, "", null);
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", hamburger, taxTemplates, new MenuItemPortion {
                Price = 7, Name = "Adet"
            }, "", null);
            ticket.AddOrder(AccountTransactionType.Default, Department.Default, "Emre", hamburger, taxTemplates, new MenuItemPortion {
                Price = 6, Name = "Adet"
            }, "", null);
            ticket.AddCalculation(new CalculationType()
            {
                AccountTransactionType = AccountTransactionType.Default, DecreaseAmount = true
            }, 10);
            ticket.Recalculate();

            var orderSelector = new OrderSelector();

            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(ticket.GetSum(), orderSelector.Selectors.Sum(x => x.TotalPrice));

            ticket.TaxIncluded = true;
            orderSelector      = new OrderSelector();
            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(ticket.GetSum(), orderSelector.Selectors.Sum(x => x.TotalPrice));
        }
        public void DoesTicketDiscountsWorks()
        {
            var ticket          = SetupTicket();
            var calculationType = new CalculationType
            {
                AccountTransactionType = AccountTransactionType.Default,
                DecreaseAmount         = true
            };

            ticket.AddCalculation(calculationType, 10);
            var orderSelector = new OrderSelector();

            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(28 - 2.8, orderSelector.Selectors.Sum(x => x.TotalPrice));
        }
        public void CanUpdateHalfPaidTicket()
        {
            var ticket        = SetupTicket();
            var orderSelector = new OrderSelector();

            orderSelector.UpdateTicket(ticket);
            orderSelector.Select(1, 5);
            orderSelector.Select(2, 6);
            orderSelector.PersistSelectedItems();
            orderSelector.PersistTicket();

            orderSelector = new OrderSelector();
            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(28 - 11, orderSelector.RemainingTotal);
        }
Beispiel #12
0
        /// <summary>
        /// 构建查询。
        /// </summary>
        /// <param name="predicate">筛选表达式。</param>
        /// <param name="page">分页信息接口。</param>
        /// <param name="predicate">排序选择器数组。</param>
        /// <returns></returns>
        protected IQueryable <TRecord> BuildQueryable(Expression <Func <TRecord, bool> > predicate, IPage page, params OrderSelector <TRecord>[] orderSelectors)
        {
            IQueryable <TRecord> queryable = Queryable;

            if (predicate != null)
            {
                queryable = queryable.Where(predicate);
            }
            var hasPage = page != null;

            if (hasPage && orderSelectors.IsEmpty())
            {
                //默认Id升序
                orderSelectors = new OrderSelector <TRecord>[] { OrderUtil.Ascending <TRecord>(s => new { s.Id }) };
            }
            queryable = OrderUtil.OrderBy(queryable, orderSelectors);
            if (hasPage)
            {
                queryable = queryable.Skip(page.PageSize.Value * (page.PageNumber.Value - 1)).Take(page.PageSize.Value);
            }
            return(queryable);
        }
        protected int GetCountItemsNexFilter(OrderSelector nextOrderSelector)
        {
            if (nextOrderSelector == null)
            {
                return(0);
            }

            if (nextOrderSelector is OrderSelectorByStatus)
            {
                return(OrderStatuses.Count);
            }

            if (nextOrderSelector is OrderSelectorByCity)
            {
                return(Cities.Count);
            }

            if (nextOrderSelector is OrderSelectorByCustomer)
            {
                return(Customers.Count);
            }

            return(0);
        }
 public OrederSelectorByOrderDate(OrderSelector nextOrderSelector) : base(nextOrderSelector)
 {
 }
 public OrderSelectorByCustomer(OrderSelector nextOrderSelector) : base(nextOrderSelector)
 {
     _nextOrderSelector = nextOrderSelector;
 }
 public OrderSelectorByCity(OrderSelector nextOrderSelector) : base(nextOrderSelector)
 {
     _nextOrderSelector = nextOrderSelector;
 }
 public OrderSelectorByStatus(OrderSelector nextOrderSelector) : base(nextOrderSelector)
 {
     _nextOrderSelector = nextOrderSelector;
 }
 public void DoesTicketDiscountsWorks()
 {
     var ticket = SetupTicket();
     var calculationType = new CalculationType
                                   {
                                       AccountTransactionType = AccountTransactionType.Default,
                                       DecreaseAmount = true
                                   };
     ticket.AddCalculation(calculationType, 10);
     var orderSelector = new OrderSelector();
     orderSelector.UpdateTicket(ticket);
     Assert.AreEqual(28 - 2.8, orderSelector.Selectors.Sum(x => x.TotalPrice));
 }
 public void CanUpdatePaidTicketItems()
 {
     var ticket = SetupTicket();
     var orderSelector = new OrderSelector();
     orderSelector.UpdateTicket(ticket);
     orderSelector.Select(1, 5);
     orderSelector.Select(2, 6);
     orderSelector.PersistSelectedItems();
     orderSelector.PersistTicket();
     Assert.AreEqual(2, ticket.PaidItems.Sum(x => x.Quantity));
 }
        public void CanUpdateHalfPaidTicket()
        {
            var ticket = SetupTicket();
            var orderSelector = new OrderSelector();
            orderSelector.UpdateTicket(ticket);
            orderSelector.Select(1, 5);
            orderSelector.Select(2, 6);
            orderSelector.PersistSelectedItems();
            orderSelector.PersistTicket();

            orderSelector = new OrderSelector();
            orderSelector.UpdateTicket(ticket);
            Assert.AreEqual(28 - 11, orderSelector.RemainingTotal);
        }
 protected OrderSelector(OrderSelector nextOrderSelector)
 {
     NextOrderSelector = nextOrderSelector;
 }