public void PUTOrder_ValidObject_ReturnsCorrectItem()
        {
            Client c = new Client("bart", "simpsonlaan 12");

            c.Id = 2;
            Order o = new Order(Product.Duvel, 10, c);

            o.Id = 1;
            Order gettedOrder = new Order(Product.Duvel, 10, c);

            gettedOrder.Client = c;
            gettedOrder.Id     = 1;
            ROrderIn oi = new ROrderIn(c.Id, "Duvel", o.Amount)
            {
                OrderId = 1
            };

            mockRepo.Setup(repo => repo.GetClient(oi.ClientId)).Returns(c);
            mockRepo.Setup(repo => repo.UpdateOrder(o)).Returns(gettedOrder);
            mockRepo.Setup(repo => repo.IsInOrders(o.Id)).Returns(true);
            mockRepo.Setup(repo => repo.GetOrder(o.Id)).Returns(o);
            var response = kbController.PutOrder(oi.ClientId, o.Id, oi) as OkObjectResult;

            Assert.Equal(oi.Amount, (response.Value as ROrderOut).Amount);
            Assert.Equal(Constants.URI + oi.ClientId, (response.Value as ROrderOut).ClientId);//
            Assert.Equal(Constants.URI + oi.ClientId + "/Bestelling/" + oi.OrderId, (response.Value as ROrderOut).OrderId);
            Assert.Equal(oi.Product, (response.Value as ROrderOut).Product);
        }
 public IActionResult PutOrder(int clientId, int orderId, [FromBody] ROrderIn rOrderIn)
 {
     logger.LogInformation(23, "PutOrder Called");
     try
     {
         if (rOrderIn == null || rOrderIn.ClientId != clientId || rOrderIn.OrderId != orderId)
         {
             return(BadRequest());
         }
         if (!dc.IsInOrders(orderId))
         {
             if (!Enum.IsDefined(typeof(Product), rOrderIn.Product))
             {
                 return(NotFound("product not found."));
             }
             Order toAdd = Mapper.ROrderInToOrder(rOrderIn, dc);
             Order added = dc.AddOrder(toAdd, clientId);
             return(CreatedAtAction(nameof(GetClient), new { id = added.Id }, Mapper.OrderToROrderOut(added)));
         }
         Order toUpdate = Mapper.ROrderInToOrder(rOrderIn, dc);
         dc.UpdateOrder(toUpdate);
         ROrderOut updatedOrder = Mapper.OrderToROrderOut(dc.GetOrder(toUpdate.Id));
         return(Ok(updatedOrder));
     }
     catch (Exception ex)
     {
         return(NotFound(ex.Message));
     }
 }
        public void POSTOrder_InValidClientId_ReturnsBadRequest()
        {
            ROrderIn o        = new ROrderIn(2, "Duvel", 10);
            var      response = kbController.PostOrder(3, o).Result;

            Assert.IsType <BadRequestObjectResult>(response);
        }
        public void POSTOrder_InValidProduct_ReturnsNotFound()
        {
            ROrderIn o = new ROrderIn(2, "Duvel", 10);

            kbController.ModelState.AddModelError("format error", "int expected");
            var response = kbController.PostOrder(2, o).Result;

            Assert.IsType <NotFoundObjectResult>(response);
        }
        public void PUTOrder_InValidObjectException_ReturnsNotFound()
        {
            ROrderIn o = new ROrderIn(2, "Duff", 10);

            o.OrderId = 1;
            mockRepo.Setup(repo => repo.IsInOrders(1)).Throws(new Exception());
            var response = kbController.PutOrder(2, 1, o);

            Assert.IsType <NotFoundObjectResult>(response);
        }
        public void POSTOrder_ValidObject_ReturnsCreatedAtAction()
        {
            Client c = new Client("bart", "simpsonlaan 12");

            c.Id = 2;
            Order o           = new Order(Product.Duvel, 10, c);
            Order gettedOrder = new Order(Product.Duvel, 10, c);

            gettedOrder.Client = c;
            gettedOrder.Id     = 1;
            ROrderIn oi = new ROrderIn(c.Id, "Duvel", o.Amount);

            mockRepo.Setup(repo => repo.GetClient(oi.ClientId)).Returns(c);
            mockRepo.Setup(repo => repo.AddOrder(o, c.Id)).Returns(gettedOrder);
            var response = kbController.PostOrder(oi.ClientId, oi);

            Assert.IsType <CreatedAtActionResult>(response.Result);
        }
 public ActionResult <ROrderOut> PostOrder(int clientId, [FromBody] ROrderIn rOrderIn)
 {
     logger.LogInformation(22, "PostOrder Called");
     try
     {
         if (rOrderIn.ClientId != clientId)
         {
             return(BadRequest("Input is invalid"));
         }
         if (!Enum.IsDefined(typeof(Product), rOrderIn.Product))
         {
             return(NotFound("product not found."));
         }
         Order toAdd = Mapper.ROrderInToOrder(rOrderIn, dc);
         Order added = dc.AddOrder(toAdd, clientId);
         return(CreatedAtAction(nameof(GetClient), new { id = added.Id }, Mapper.OrderToROrderOut(added)));
     }
     catch (Exception ex)
     {
         return(NotFound(ex.Message));
     }
 }