public void TestAddNewProject() { var controller = CreateMockProjectController(); var project = new Project(); project.Name = "New Project"; project.ProjectId = 3; var response = controller.Post(project); IProject newProject; Assert.IsTrue(response.TryGetContentValue<IProject>(out newProject)); Assert.AreEqual(project.ProjectId, newProject.ProjectId); }
public HttpResponseMessage Post(Project project) { try { var newProject = _businessLogic.CreateProject(project); var response = Request.CreateResponse(HttpStatusCode.Created, newProject); string uri = Url.Link("DefaultApi", new { id = project.ProjectId }); response.Headers.Location = new Uri(uri); return response; } catch (ValidationException e) { return Request.CreateResponse(HttpStatusCode.InternalServerError, e.Data); } catch (Exception e) { return Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message); } }