Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void AddPerformerToAssignment()
        {
            var performerController = Controllers.GetPerformerController();
            Performer p = new Performer();
            performerController.PostPerformer(p);

            var assignmentController = Controllers.GetAssignmentController();
            Assignment a = new Assignment();
            a.performers.Add(p);
            assignmentController.PostAssignment(a);

            Assert.IsTrue(a.performers.Count > 0);
            Assert.IsTrue(a.performers.Contains(p));
        }
Exemplo n.º 3
0
        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);
        }
        // PUT api/Assignment/5
        public HttpResponseMessage PutAssignment(Assignment assignment)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            try
            {
                assignment.updated = DateTime.UtcNow;
                _db.Update(assignment);
                _db.Save();
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        // POST api/Assignment
        public HttpResponseMessage PostAssignment(Assignment assignment)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            try
            {
                assignment.created = DateTime.UtcNow;
                _db.Insert(assignment);
                _db.Save();
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, assignment);
                //response.Headers.Location = new Uri(Url.Link("Default", new { id = performer.performerID }));
                return response;
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        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);
        }