public ActionResult <RClientOut> PutClient(int id, [FromBody] RClientIn rClientIn)
 {
     logger.LogInformation(13, "PutClient Called");
     try
     {
         if (rClientIn == null || rClientIn.ClientID != id)
         {
             return(BadRequest());
         }
         if (!dc.IsInClients(id))
         {
             Client toAdd = Mapper.RClientInToClient(rClientIn);
             Client added = dc.AddClient(toAdd);
             return(CreatedAtAction(nameof(GetClient), new { id = added.Id }, Mapper.ClientToRClientOut(added)));
         }
         Client toUpdate = Mapper.RClientInToClient(rClientIn);
         dc.UpdateClient(toUpdate);
         RClientOut updatedClient = Mapper.ClientToRClientOut(dc.GetClient(toUpdate.Id));
         return(Ok(updatedClient));
     }
     catch (Exception ex)
     {
         return(NotFound(ex.Message));
     }
 }
        public void POSTClient_InValidObject_ReturnsNotFound()
        {
            RClientIn c = new RClientIn("trala", "simpsonlaan 12");

            kbController.ModelState.AddModelError("format error", "int expected");
            var response = kbController.PostClient(c).Result;

            Assert.IsType <NotFoundObjectResult>(response);
        }
        public void PUTClient_InValidObject_ReturnsBadRequest()
        {
            RClientIn c = new RClientIn("trala", "simpsonlaan 12");

            c.ClientID = 5;
            var response = kbController.PutClient(2, c);

            Assert.IsType <BadRequestResult>(response.Result);
        }
        public void POSTClient_ValidObject_ReturnsCreatedAtAction()
        {
            RClientIn client     = new RClientIn("trala", "simpsonlaan 12");
            Client    clientRepo = new Client(client.Name, client.Address);

            mockRepo.Setup(repo => repo.AddClient(clientRepo)).Returns(clientRepo);;
            var response = kbController.PostClient(client);

            Assert.IsType <CreatedAtActionResult>(response.Result);
        }
        public void PUTClient_InValidObject_ReturnsNotFound()
        {
            RClientIn c = new RClientIn("trala", "simpsonlaan 12");

            c.ClientID = 2;
            kbController.ModelState.AddModelError("simulated exception", "duno client already in db");
            var response = kbController.PutClient(2, c).Result;

            Assert.IsType <NotFoundObjectResult>(response);
        }
        public void PUTClient_InValidId_ReturnsNotFound()
        {
            RClientIn c = new RClientIn("trala", "simpsonlaan 12");

            c.ClientID = 2;
            Client clientRepo = new Client(c.Name, c.Address);

            clientRepo.Id = 2;
            mockRepo.Setup(repo => repo.UpdateClient(clientRepo)).Throws(new Exception("Client not in DB."));
            var response = kbController.PutClient(2, c).Result;

            Assert.IsType <NotFoundObjectResult>(response);
        }
 public ActionResult <RClientOut> PostClient([FromBody] RClientIn rClientIn)
 {
     logger.LogInformation(12, "PostClient Called");
     try
     {
         Client toAdd = Mapper.RClientInToClient(rClientIn);
         Client added = dc.AddClient(toAdd);
         return(CreatedAtAction(nameof(GetClient), new { id = added.Id }, Mapper.ClientToRClientOut(added)));
     }
     catch (Exception ex)
     {
         return(NotFound(ex.Message));
     }
 }
        public void POSTClient_ValidObject_ReturnsCorrectItem()
        {
            RClientIn c = new RClientIn("trala", "simpsonlaan 12");

            c.ClientID = 2;
            Client clientRepo = new Client(c.Name, c.Address);

            clientRepo.Id = 2;
            mockRepo.Setup(repo => repo.AddClient(clientRepo)).Returns(clientRepo);
            var tussenResponse = kbController.PostClient(c);
            var response       = tussenResponse.Result as CreatedAtActionResult;
            var item           = response.Value as RClientOut;

            Assert.IsType <RClientOut>(item);
            Assert.Equal(Constants.URI + 2, item.ClientIdString);
            Assert.Equal(c.Name, item.Name);
            Assert.Equal(c.Address, item.Address);
        }