예제 #1
0
        public void AddOrderIngredients(List <orderingredient> ingredients, int orderId)
        {
            try
            {
                foreach (var i in ingredients)
                {
                    if (i.quantity < 1)
                    {
                        continue;
                    }

                    orderingredient orderIngredient = new orderingredient()
                    {
                        orderid      = orderId,
                        ingredientid = i.ingredientid,
                        quantity     = i.quantity
                    };

                    repository.AddOrderIngredient(orderIngredient);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #2
0
        public void CreateOrderTest()
        {
            order order = new order()
            {
                orderid        = 1,
                name           = "Bob",
                phonenumber    = "888-888-8888",
                pickupdatetime = DateTime.Now,
                statustypeid   = 1
            };

            orderingredient cheese = new orderingredient()
            {
                orderid      = 1,
                ingredientid = 1,
                quantity     = 1
            };

            List <orderingredient> ingredients = new List <orderingredient>();

            ingredients.Add(cheese);

            Mock <IOrderRepository> mockRepository = new Mock <IOrderRepository>();

            mockRepository.Setup(s => s.CreateOrder(It.IsAny <order>())).Returns(() => order);

            OrderService orderService = new OrderService(mockRepository.Object);

            order addedOrder = orderService.CreateOrder(order, ingredients);

            Assert.AreEqual(order, addedOrder);
        }
예제 #3
0
        public void GetOrdersTest_AreEqual()
        {
            order order = new order()
            {
                orderid        = 1,
                name           = "Leszek",
                phonenumber    = "888-888-8888",
                pickupdatetime = DateTime.Now,
                startdatetime  = DateTime.Now,
                enddatetime    = DateTime.Now,
                statustypeid   = 1
            };

            List <order> orders = new List <order>();

            orders.Add(order);

            orderingredient orderIngredient = new orderingredient()
            {
                orderid      = 1,
                ingredientid = 1,
                quantity     = 1
            };

            List <orderingredient> orderIngredients = new List <orderingredient>();

            orderIngredients.Add(orderIngredient);

            ingredient cheese = new ingredient()
            {
                ingredientid = 1,
                name         = "Cheese",
                price        = 2
            };

            List <ingredient> ingredients = new List <ingredient>();

            ingredients.Add(cheese);

            Mock <IOrderRepository> mockRepository = new Mock <IOrderRepository>();

            mockRepository.Setup(s => s.GetOrders()).Returns(() => orders);
            mockRepository.Setup(s => s.GetOrderIngredients(It.IsAny <int>())).Returns(() => orderIngredients);
            mockRepository.Setup(s => s.GetIngredients()).Returns(() => ingredients);

            OrderService orderService = new OrderService(mockRepository.Object);

            List <CustomerOrderResult> resultOrders = orderService.GetOrders();

            Assert.AreEqual(1, resultOrders.FirstOrDefault().orderid);
            Assert.AreEqual("Cheese", resultOrders.FirstOrDefault().orderingredientresults.FirstOrDefault().name);
        }
예제 #4
0
 public void AddOrderIngredient(orderingredient orderIngredient)
 {
     try
     {
         string query = "INSERT INTO dbo.orderingredients VALUES (" + orderIngredient.orderid + "," + orderIngredient.ingredientid + "," + orderIngredient.quantity + ")";
         db.Database.ExecuteSqlCommand(query);
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #5
0
        public void GetOrderIngredientsTest()
        {
            orderingredient orderIngredient = new orderingredient()
            {
                orderid      = 1,
                ingredientid = 1,
                quantity     = 1
            };

            List <orderingredient> orderIngredients = new List <orderingredient>();

            orderIngredients.Add(orderIngredient);

            Mock <IOrderRepository> mockRepository = new Mock <IOrderRepository>();

            mockRepository.Setup(s => s.GetOrderIngredients(It.IsAny <int>())).Returns(() => orderIngredients);

            OrderService orderService = new OrderService(mockRepository.Object);

            List <OrderIngredientResult> resultIngredients = orderService.GetOrderIngredients(1);

            Assert.AreEqual(orderIngredient.orderid, resultIngredients.FirstOrDefault().orderid);
            Assert.AreEqual(orderIngredient.ingredientid, resultIngredients.FirstOrDefault().ingredientid);
        }