public void TestDoUpdateOrderPos()
        {
            var context = MockContextFactory.Create();

            var testOrder = new Order()
            {
                Id           = 1,
                OrderStatus  = OrderStatus.New,
                CreationTime = new DateTime(2017, 2, 4, 17, 0, 0),
                Guests       = new List <Tablet>(),
                Positions    = new List <OrderPos>()
            };

            var testItem1 = new Itemtyp
            {
                Id          = 1,
                Number      = 1,
                Title       = "Burger",
                Description = "Burger with Fries",
                ItemPrice   = 15
            };

            context.Itemtyp.Add(testItem1);
            context.Order.Add(testOrder);
            context.SaveChanges();


            var orderService    = new OrderService(new MockDataService(context));
            var positionService = new OrderPosService(new MockDataService(context), orderService);

            positionService.AddOrderPos(testOrder.Id, testItem1.Id);
            positionService.DoUpdateOrderPosRequest(testOrder.Positions.First().Id, 3, "");
            context.SaveChanges();

            Assert.Equal(45, testOrder.Positions.First().PricePos);

            positionService.DoUpdateOrderPosRequest(testOrder.Positions.First().Id, 1, "");

            Assert.Equal(15, testOrder.Positions.First().PricePos);

            positionService.DoUpdateOrderPosRequest(testOrder.Positions.First().Id, 4, "");

            Assert.Equal(60, testOrder.Positions.First().PricePos);
        }
Example #2
0
        public static ItemTypeModel MapFromDatabase(Itemtyp m)
        {
            if (m == null)
            {
                return(null);
            }

            return(new ItemTypeModel
            {
                Id = m.Id,
                Number = m.Number,
                Title = m.Title,
                Description = m.Description,
                ItemPrice = m.ItemPrice,
                Category = m.Category,
                Image = m.Image,
                Priority = m.Priority
            });
        }
Example #3
0
        public void TestDoCalculateOrderPrice()
        {
            var context = MockContextFactory.Create();

            var waiter = new Tablet()
            {
                Id         = 4,
                Identifier = "brutus",
                Mode       = Mode.Waiter
            };

            var order1 = new Order
            {
                Id          = 4,
                OrderStatus = OrderStatus.New,
                PriceOrder  = 0,
                TableId     = 5,
                Waiter      = waiter
            };

            var order2 = new Order
            {
                Id          = 8,
                OrderStatus = OrderStatus.Active,
                PriceOrder  = 0,
                TableId     = 7,
                Waiter      = waiter
            };

            var itemA = new Itemtyp
            {
                Id          = 1,
                Number      = 1,
                Title       = "soup",
                Description = "tomatosoup",
                ItemPrice   = 9
            };

            var itemB = new Itemtyp
            {
                Id          = 2,
                Number      = 2,
                Title       = "salad",
                Description = "tomatosalad",
                ItemPrice   = 12
            };

            var positionSoup = new OrderPos
            {
                Amount              = 1,
                Id                  = 6,
                Order               = order2,
                OrderId             = order2.Id,
                PricePos            = 9,
                PricePaidByCustomer = 9,
                Itemtyp             = itemA,
                ItemtypId           = itemA.Id,
                PosStatus           = PosStatus.Active
            };

            var positionSalad = new OrderPos
            {
                Amount              = 1,
                Id                  = 8,
                Order               = order2,
                OrderId             = order2.Id,
                PricePos            = 12,
                PricePaidByCustomer = 12,
                Itemtyp             = itemA,
                ItemtypId           = itemA.Id,
                PosStatus           = PosStatus.Active
            };

            context.Tablet.Add(waiter);
            context.Order.Add(order1);
            context.Order.Add(order2);
            context.Itemtyp.Add(itemA);
            context.Itemtyp.Add(itemB);
            context.OrderPos.Add(positionSoup);
            context.OrderPos.Add(positionSalad);
            context.SaveChanges();


            var orderService = new OrderService(new MockDataService(context));

            orderService.DoCalulateOrderPrice(4);
            orderService.DoCalulateOrderPrice(8);

            context.SaveChanges();

            Assert.Equal(0, order1.PriceOrder);
            Assert.Equal(21, order2.PriceOrder);
        }
        public void TestAddOrderPos()
        {
            var context = MockContextFactory.Create();

            var testOrder = new Order()
            {
                Id           = 1,
                OrderStatus  = OrderStatus.New,
                CreationTime = new DateTime(2017, 2, 4, 17, 0, 0),
                Guests       = new List <Tablet>(),
                Positions    = new List <OrderPos>()
            };

            var testItem1 = new Itemtyp
            {
                Id          = 1,
                Number      = 1,
                Title       = "Burger",
                Description = "Burger with Fries",
                ItemPrice   = 15
            };

            var testItem2 = new Itemtyp
            {
                Id          = 2,
                Number      = 2,
                Title       = "Steak",
                Description = "Steak with Fries",
                ItemPrice   = 20
            };

            var testItem3 = new Itemtyp
            {
                Id          = 3,
                Number      = 3,
                Title       = "Toast",
                Description = "Toast with Fries",
                ItemPrice   = 10
            };

            context.Order.Add(testOrder);
            context.SaveChanges();

            var orderService = new OrderService(new MockDataService(context));
            var service      = new OrderPosService(new MockDataService(context), orderService);

            service.AddOrderPos(testOrder.Id, testItem1.Id);
            service.AddOrderPos(testOrder.Id, testItem2.Id);
            context.SaveChanges();

            Assert.Equal(2, testOrder.Positions.Count());
            Assert.Equal(2, testOrder.Positions.LastOrDefault().Number);

            var testOrder2 = new Order()
            {
                Id           = 2,
                OrderStatus  = OrderStatus.New,
                CreationTime = new DateTime(2017, 2, 9, 17, 0, 0),
                Guests       = new List <Tablet>(),
                Positions    = new List <OrderPos>()
            };

            context.Order.Add(testOrder2);
            context.SaveChanges();

            service.AddOrderPos(testOrder2.Id, testItem1.Id);
            service.AddOrderPos(testOrder2.Id, testItem2.Id);
            service.AddOrderPos(testOrder2.Id, testItem3.Id);
            context.SaveChanges();

            Assert.Equal(3, testOrder2.Positions.Count());
            Assert.Equal(3, testOrder2.Positions.LastOrDefault().Number);

            service.RemoveOrderPos(testOrder2.Id, testOrder2.Positions.First().Id);

            Assert.Equal(2, testOrder2.Positions.Count());
            Assert.Equal(3, testOrder2.Positions.LastOrDefault().Number);
        }