public void AddClientIdToAssignment2() { var context = new EntityFrameworkContextTest(); Client client = new Client() { companyName = "Test Add Client ID To Assignment" }; context.clients.Add(client); var assignmentController = Controllers.GetAssignmentController(); Assignment assignment = new Assignment(); assignment.clientId = client.id; context.assignments.Add(assignment); }
public void AddClientToAssignment() { var clientController = Controllers.GetClientController(); Client client = new Client() { companyName = "Test Add Client To Assignment" }; clientController.PostClient(client); var assignmentController = Controllers.GetAssignmentController(); Assignment assignment = new Assignment(); assignment.client = client; var addedAssignment = assignmentController.PostAssignment(assignment).Content.ReadAsAsync<Assignment>().Result; Assert.IsTrue(client.id == addedAssignment.client.id); Assert.IsTrue(client.id == addedAssignment.clientId); }
public void CreateClient() { var controller = Controllers.GetClientController(); int nrClientsBefore = controller.GetClients().Count(); var newClient = new Client() { companyName = "Test", contactPersonName = "Insert Client" }; var respons = controller.PostClient(newClient); var addedClient = respons.Content.ReadAsAsync<Client>().Result; int nrClientsAfter = controller.GetClients().Count(); Assert.IsTrue(respons.IsSuccessStatusCode); Assert.IsTrue(nrClientsAfter == nrClientsBefore + 1); Assert.IsTrue(addedClient.companyName == newClient.companyName); Assert.IsTrue(addedClient.contactPersonName == newClient.contactPersonName); }
public void GetAllClients() { var controller = Controllers.GetClientController(); int nrPerformersBefore = controller.GetClients().Count(); var newClient1 = new Client() { companyName = "Test", contactPersonName = "Get Clients 1" }; var newClient2 = new Client() { companyName = "Test", contactPersonName = "Get Clients 2" }; var respons1 = controller.PostClient(newClient1); var respons2 = controller.PostClient(newClient2); var addedClient1 = respons1.Content.ReadAsAsync<Client>().Result; var addedClient2 = respons2.Content.ReadAsAsync<Client>().Result; var performers = controller.GetClients(); Assert.IsTrue(performers.ElementAt(addedClient1.id - 1).contactPersonName == newClient1.contactPersonName); Assert.IsTrue(performers.ElementAt(addedClient2.id - 1).contactPersonName == newClient2.contactPersonName); }
public void DeleteClient() { var controller = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test", contactPersonName = "Delete Client" }; var addedClient = controller.PostClient(newClient).Content.ReadAsAsync<Client>().Result; var result = controller.DeleteClient(addedClient.id); try { var getPerformer = controller.GetClient(addedClient.id); Assert.IsTrue(false); } catch { Assert.IsTrue(true); } Assert.IsTrue(result.IsSuccessStatusCode); }
public void GetClientById() { var controller = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test", contactPersonName = "Get Client By ID" }; var result = controller.PostClient(newClient); var addedClient = result.Content.ReadAsAsync<Client>().Result; var gottenClient = controller.GetClient(addedClient.id); Assert.IsTrue(gottenClient.contactPersonName == newClient.contactPersonName); }
public void PutUpdateClient() { var controller = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test", contactPersonName = "Put Client 1" }; var addedClient = controller.PostClient(newClient).Content.ReadAsAsync<Client>().Result; addedClient.contactPersonName = "Put Client 2"; var result = controller.PutClient(addedClient); var puttedClient = controller.GetClient(addedClient.id); Assert.IsTrue(result.IsSuccessStatusCode); Assert.IsTrue(puttedClient.contactPersonName == addedClient.contactPersonName); }
public void PatchUpdateClient() { var controller = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test", contactPersonName = "Patch Client" }; var addedClient = controller.PostClient(newClient).Content.ReadAsAsync<Client>().Result; Delta<Client> client = new Delta<Client>(); client.TrySetPropertyValue("streetAddress", "Danderydsgatan 28"); controller.PatchClient(addedClient.id, client); var gottenPerformer = controller.GetClient(addedClient.id); Assert.IsTrue(gottenPerformer.contactPersonName == newClient.contactPersonName); Assert.IsTrue(gottenPerformer.streetAddress == "Danderydsgatan 28"); }
public void CreateAssignment() { var clientController = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test Create Assignment" }; clientController.PostClient(newClient); var assignmentController = Controllers.GetAssignmentController(); var nrAssignmentsBefore = assignmentController.GetAssignments().Count(); var newAssignment = new Assignment() { description = "Test Create Assignment", clientId = newClient.id }; var respons = assignmentController.PostAssignment(newAssignment); var addedAssignment = respons.Content.ReadAsAsync<Assignment>().Result; var nrAssignmentsAfter = assignmentController.GetAssignments().Count(); Assert.IsTrue(respons.IsSuccessStatusCode); Assert.IsTrue(nrAssignmentsAfter == nrAssignmentsBefore + 1); Assert.IsTrue(addedAssignment.description == newAssignment.description); }
public void PatchUpdateAssignment() { var clientController = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test Patch Assignment" }; clientController.PostClient(newClient); var assignmentController = Controllers.GetAssignmentController(); var newAssignment = new Assignment() { description = "Test Patch Assignment" }; var addedAssignment = assignmentController.PostAssignment(newAssignment).Content.ReadAsAsync<Assignment>().Result; Delta<Assignment> assignment = new Delta<Assignment>(); assignment.TrySetPropertyValue("description", "Test Patch Assignment 2"); assignmentController.PatchAssignment(addedAssignment.id, assignment); var gottenAssignment = assignmentController.GetAssignment(addedAssignment.id); Assert.IsTrue(gottenAssignment.description == newAssignment.description); }
public void PutUpdateAssignment() { var clientController = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test Put Update Assignment" }; clientController.PostClient(newClient); var assignmentController = Controllers.GetAssignmentController(); var newAssignment = new Assignment() { description = "Test Put Update Assignment", clientId = newClient.id }; var addedAssignment = assignmentController.PostAssignment(newAssignment).Content.ReadAsAsync<Assignment>().Result; addedAssignment.description = "Test Put Update Assignment 2"; var result = assignmentController.PutAssignment(addedAssignment); var puttedAssignment = assignmentController.GetAssignment(addedAssignment.id); Assert.IsTrue(result.IsSuccessStatusCode); Assert.IsTrue(puttedAssignment.description == addedAssignment.description); }
public void GetAssignmentById() { var clientController = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test Get Assignment By ID" }; clientController.PostClient(newClient); var assignmentController = Controllers.GetAssignmentController(); var newAssignment = new Assignment() { description = "Test Get Assignment By ID" }; var result = assignmentController.PostAssignment(newAssignment); var addedAssignment = result.Content.ReadAsAsync<Assignment>().Result; var gottenAssignment = assignmentController.GetAssignment(addedAssignment.id); Assert.IsTrue(gottenAssignment.description == newAssignment.description); }
public void GetAllAssignments() { var clientController = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test Get Assignments" }; clientController.PostClient(newClient); var assignmentController = Controllers.GetAssignmentController(); var nrAssignmentsBefore = assignmentController.GetAssignments().Count(); var newAssignment1 = new Assignment() { description = "Test Get Assignments 1", clientId = newClient.id }; var newAssignment2 = new Assignment() { description = "Test Get Assignments 2", clientId = newClient.id }; var respons1 = assignmentController.PostAssignment(newAssignment1); var respons2 = assignmentController.PostAssignment(newAssignment2); var addedAssignment1 = respons1.Content.ReadAsAsync<Assignment>().Result; var addedAssignment2 = respons2.Content.ReadAsAsync<Assignment>().Result; var assignments = assignmentController.GetAssignments(); var nrAssignmentsAfter = assignments.Count(); Assert.IsTrue(nrAssignmentsBefore == nrAssignmentsAfter - 2); Assert.IsTrue(assignments.Any(a => a.id == addedAssignment1.id && a.description == addedAssignment1.description)); Assert.IsTrue(assignments.Any(a => a.id == addedAssignment2.id && a.description == addedAssignment2.description)); }
public void DeleteAssignment() { var clientController = Controllers.GetClientController(); var newClient = new Client() { companyName = "Test Delete Assignment" }; clientController.PostClient(newClient); var assignmentController = Controllers.GetAssignmentController(); var newAssignment = new Assignment() { description = "Test Delete Assignment", clientId = newClient.id }; var addedAssignment = assignmentController.PostAssignment(newAssignment).Content.ReadAsAsync<Assignment>().Result; var result = assignmentController.DeleteAssignment(addedAssignment.id); try { var getAssignment = assignmentController.GetAssignment(addedAssignment.id); Assert.IsTrue(false); } catch { Assert.IsTrue(true); } Assert.IsTrue(result.IsSuccessStatusCode); }
// PUT api/Client public HttpResponseMessage PutClient(Client client) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } try { client.updated = DateTime.UtcNow; _db.Update(client); _db.Save(); } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Client public HttpResponseMessage PostClient(Client client) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } try { //client.oAuth = this.GetOAuth(); client.created = DateTime.UtcNow; _db.Insert(client); _db.Save(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, client); //response.Headers.Location = new Uri(Url.Link("Default", new { id = performer.performerID })); return response; } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } }