Пример #1
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));
        }
Пример #2
0
        public void CreatePerformer()
        {
            var controller = Controllers.GetPerformerController();

            int nrPerformersBefore = controller.GetPerformers().Count();
            var newPerformer = new Performer() { firstName = "Test", lastName = "Post Performer", birthDate = DateTime.Now };
            var respons = controller.PostPerformer(newPerformer);
            var addedPerformer = respons.Content.ReadAsAsync<Performer>().Result;
            int nrPerformersAfter = controller.GetPerformers().Count();

            Assert.IsTrue(respons.IsSuccessStatusCode);
            Assert.IsTrue(nrPerformersAfter == nrPerformersBefore + 1);
            Assert.IsTrue(addedPerformer.firstName == newPerformer.firstName);
            Assert.IsTrue(addedPerformer.lastName == newPerformer.lastName);
        }
Пример #3
0
        public void GetAllPerformers()
        {
            var controller = Controllers.GetPerformerController();

            int nrPerformersBefore = controller.GetPerformers().Count();

            var newPerformer1 = new Performer() { firstName = "Test", lastName = "Get Performers 1", birthDate = DateTime.Now };
            var newPerformer2 = new Performer() { firstName = "Test", lastName = "Get Performers 2", birthDate = DateTime.Now };

            var respons1 = controller.PostPerformer(newPerformer1);
            var respons2 = controller.PostPerformer(newPerformer2);

            var addedPerformer1 = respons1.Content.ReadAsAsync<Performer>().Result;
            var addedPerformer2 = respons2.Content.ReadAsAsync<Performer>().Result;

            var performers =  controller.GetPerformers();

            Assert.IsTrue(performers.ElementAt(addedPerformer1.id - 1).firstName == newPerformer1.firstName);
            Assert.IsTrue(performers.ElementAt(addedPerformer2.id - 1).firstName == newPerformer2.firstName);
        }
Пример #4
0
        public void DeletePerformer()
        {
            var controller = Controllers.GetPerformerController();

            var newPerformer = new Performer() { firstName = "Test", lastName = "Delete Performer", birthDate = DateTime.Now };
            var addedPerformer = controller.PostPerformer(newPerformer).Content.ReadAsAsync<Performer>().Result;
            var result = controller.DeletePerformer(addedPerformer.id);

            try
            {
                var getPerformer = controller.GetPerformer(addedPerformer.id);
                Assert.IsTrue(false);
            }
            catch
            {
                Assert.IsTrue(true);
            }

            Assert.IsTrue(result.IsSuccessStatusCode);
        }
Пример #5
0
        public void GetPerformersById()
        {
            var controller = Controllers.GetPerformerController();

            var newPerformer = new Performer() { firstName = "Test", lastName = "Get Performer By ID", birthDate = DateTime.Now };
            var result = controller.PostPerformer(newPerformer);
            var addedPerformer = result.Content.ReadAsAsync<Performer>().Result;
            var gottenPerformer = controller.GetPerformer(addedPerformer.id);

            Assert.IsTrue(gottenPerformer.lastName == newPerformer.lastName);
        }
Пример #6
0
        public void PutUpdatePerformer()
        {
            var controller = Controllers.GetPerformerController();

            var newPerformer = new Performer() { firstName = "Test", lastName = "Put Performer 1", birthDate = DateTime.Now };
            var addedPerformer = controller.PostPerformer(newPerformer).Content.ReadAsAsync<Performer>().Result;
            addedPerformer.lastName = "Put Performer 2";
            var result = controller.PutPerformer(addedPerformer);
            var puttedPerformer = controller.GetPerformer(addedPerformer.id);

            Assert.IsTrue(result.IsSuccessStatusCode);
            Assert.IsTrue(puttedPerformer.lastName == addedPerformer.lastName);
        }
Пример #7
0
        public void PatchUpdatePerformer()
        {
            var controller = Controllers.GetPerformerController();

            var newPerformer = new Performer() { firstName = "Test", lastName = "Patch Performer", birthDate = DateTime.Now };
            var addedPerformer = controller.PostPerformer(newPerformer).Content.ReadAsAsync<Performer>().Result;

            Delta<Performer> performer = new Delta<Performer>();
            performer.TrySetPropertyValue("country", "Sweden");
            controller.PatchPerformer(addedPerformer.id, performer);

            var gottenPerformer = controller.GetPerformer(addedPerformer.id);

            Assert.IsTrue(gottenPerformer.lastName == newPerformer.lastName);
            Assert.IsTrue(gottenPerformer.country == "Sweden");
        }
        public HttpResponseMessage PutPerformer(Performer performer)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        public HttpResponseMessage PostPerformer(Performer performer)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            try
            {
                //performer.oAuth = this.GetOAuth();
                performer.created = DateTime.UtcNow;
                _db.Insert(performer);
                _db.Save();
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, performer);
                //response.Headers.Location = new Uri(@"api/performer/" + performer.Id);
                return response;
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }
        }