public async Task TestThatPostUpdateWithNotCorrectModel() { //send request to the server to /Update/id/1 XMLUpdEmployee xempl = new XMLUpdEmployee("AQA", "Strong", "John Doe", "test", "3"); HttpContent content = new StringContent(JsonConvert.SerializeObject(xempl)); content.Headers.ContentType.MediaType = MediaTypeNames.Application.Json; HttpResponseMessage response = await _client.PostAsync(urlupdateid, content); Assert.AreEqual(response.StatusCode, HttpStatusCode.BadRequest, "Sorry, the response status is not BadRequest"); }
public IActionResult EmployeeUpdate(int id, XMLUpdEmployee employee) { if (UpdateHelpers.IsNull(employee)) { ModelState.AddModelError("Error", "The model body cannot be empty or null"); return(BadRequest(ModelState)); } var emp = _repo.GetAll().Where(x => x.ID == id); if (emp.Count() < 1) { return(BadRequest("Cant find matching ID")); } var newemp = UpdateHelpers.XmlEmployeeToEmployee(employee, emp.First()); newemp.ID = id; _repo.Update(newemp); return(Ok(newemp)); }