예제 #1
0
        public void TestPostSetsLocationHeader()
        {
            var controller = new PersonController(new MockPersonRepository());

            controller.Request = new HttpRequestMessage
            {
                RequestUri = new Uri("http://localhost/api/people")
            };

            controller.Configuration = new HttpConfiguration();
            controller.Configuration.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional });

            controller.RequestContext.RouteData = new HttpRouteData(route: new HttpRoute(),
                values: new HttpRouteValueDictionary { { "controller", "people" } });

            var person = new Person { FirstName = "Added", MiddleName = "The", LastName = "NewPerson" };
            var response = controller.Post(person);

            IPerson resultPerson;
            response.TryGetContentValue<IPerson>(out resultPerson);

            Assert.AreEqual("http://localhost/api/people/" + resultPerson.PersonId, response.Headers.Location.AbsoluteUri);
        }
예제 #2
0
 public PersonController CreateMockPersonController()
 {
     var controller = new PersonController(new MockPersonRepository());
     controller.Request = new HttpRequestMessage();
     controller.Configuration = new HttpConfiguration();
     return controller;
 }