public void PutPerson_ShouldFail_WhenDifferentID()
        {
            var controller = new PeopleController(new TestPersonContext());

            var badresult = controller.PutPerson(999, GetDemoPerson());
            Assert.IsInstanceOfType(badresult, typeof(BadRequestResult));
        }
        public void GetPerson_ShouldReturnPersonWithSameID()
        {
            var context = new TestPersonContext();
            context.People.Add(GetDemoPerson());

            var controller = new PeopleController(context);
            var result = controller.GetPerson(1) as OkNegotiatedContentResult<Person>;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Content.ID);
        }
        public void DeletePerson_ShouldReturnOK()
        {
            var context = new TestPersonContext();
            var item = GetDemoPerson();
            context.People.Add(item);

            var controller = new PeopleController(context);
            var result = controller.DeletePerson(1) as OkNegotiatedContentResult<Person>;

            Assert.IsNotNull(result);
            Assert.AreEqual(item.ID, result.Content.ID);
        }
        public void GetPersons_ShouldReturnAllPersons()
        {
            var context = new TestPersonContext();
            context.People.Add(new Person { ID = 1, FirstName = "Jake", LastName = "Sully" });
            context.People.Add(new Person { ID = 2, FirstName = "Don", LastName = "Blair" });
            context.People.Add(new Person { ID = 3, FirstName = "Nathan", LastName = "Lee" });

            var controller = new PeopleController(context);
            var result = controller.GetPeople();

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count());
        }
        public void GetPeople()
        {
            var controller = new PeopleController(new TestPersonContext());
            var person = GetDemoPerson();
            var result =
                controller.PostPerson(person) as CreatedAtRouteNegotiatedContentResult<Person>;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.RouteName, "DefaultApi");
            Assert.AreEqual(result.RouteValues["id"], result.Content.ID);
            Assert.AreEqual(result.Content.FirstName, person.FirstName);
            Assert.AreEqual(result.Content.LastName, person.LastName);
        }
        public void PutPerson_ShouldReturnStatusCode()
        {
            var controller = new PeopleController(new TestPersonContext());

            var person = GetDemoPerson();

            var result = controller.PutPerson(person.ID, person) as StatusCodeResult;
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
        }