public void PostingNewJobShouldReturnJson() { BrowserResponse response; PostJobRequest request = new PostJobRequest(); response = browser.Post("/api/jobs", with => { with.JsonBody(request); }); response.ContentType.Should().StartWith("application/json"); }
public void PostingNewJobShouldReturnItsIdentifier() { BrowserResponse response; PostJobRequest request = new PostJobRequest(); response = browser.Post("/api/jobs", with => { with.JsonBody(request); }); response.Body.DeserializeJson <PostJobResponse>().id.Should().HaveLength(32); }
public void PostingNewJobShouldReturn200() { BrowserResponse response; PostJobRequest request = new PostJobRequest(); response = browser.Post("/api/jobs", with => { with.JsonBody(request); }); response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task <IActionResult> PostJobAsync([FromBody] PostJobRequest request) { var response = new SingleResponse <Job>(); try { var existingEntity = await DbContext .GetJobsByJobTitleAsync(new Job { JobTitle = request.JobTitle }); if (existingEntity != null) { ModelState.AddModelError("JobTitle", "Job already exists"); } if (!ModelState.IsValid) { return(BadRequest()); } // Create entity from request model var entity = request.ToEntity(); // Add entity to repository DbContext.Add(entity); // Save entity in database await DbContext.SaveChangesAsync(); // Set the entity to response model response.Model = entity; } catch (Exception ex) { response.DidError = true; response.ErrorMessage = "There was an internal error"; Logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(PostJobAsync), ex); } return(response.ToHttpCreatedResponse()); }
public void PostingNewJobShouldReturnJson() { BrowserResponse response; PostJobRequest request = new PostJobRequest(); response = browser.Post("/api/jobs", with => { with.JsonBody(request); }); response.ContentType.Should().StartWith("application/json"); }
public void PostingNewJobShouldReturnItsIdentifier() { BrowserResponse response; PostJobRequest request = new PostJobRequest(); response = browser.Post("/api/jobs", with => { with.JsonBody(request); }); response.Body.DeserializeJson<PostJobResponse>().id.Should().HaveLength(32); }
public void PostingNewJobShouldReturn200() { BrowserResponse response; PostJobRequest request = new PostJobRequest(); response = browser.Post("/api/jobs", with => { with.JsonBody(request); }); response.StatusCode.Should().Be(HttpStatusCode.OK); }