public async Task PutBasicPost_ShouldReturn200_ShouldReturnPutObject() { //Arrange JSONPlaceHolderPostObject postObj = new JSONPlaceHolderPostObject { body = "putBody", title = "the title", nestedEl = new NestedPostElement { custom1 = "custom field value 1", custom2 = "even more custom fields" }, userId = Guid.NewGuid() }; string postId = "50"; //Act var response = await _jsonPlaceHolderServiceClient.PutPost(postId, postObj); //Assert response.statusCode.Should().Be(System.Net.HttpStatusCode.OK, "because the Put was successful and returned 200"); response.postObject.id.Should().Be(Int32.Parse(postId), string.Format("because we performed the PUT method on id {0}", postId)); response.postObject.Should().BeOfType <JSONPlaceHolderPostObject> (string.Format("because the Put call should have updated the body of id {0}", postId)); //Could do more assertions here on the response body }
public async Task PostBasicPost_ShouldReturn201_ShouldReturnPostedObject() { //Arrange //this ought to be a conflict //this is a conflict JSONPlaceHolderPostObject postObj = new JSONPlaceHolderPostObject { body = "body", title = "this is our title", nestedEl = new NestedPostElement { custom1 = "more custom fields", custom2 = "even more custom fields" }, userId = Guid.NewGuid() }; //Act var response = await _jsonPlaceHolderServiceClient.PostNewPost(postObj); //Assert response.statusCode.Should().Be(System.Net.HttpStatusCode.Created, "because the Post was successful and returned 201"); response.postObject.id.Should().Be(101, "because all new posts get a root level id of 101"); //Could do more assertions here on response body values }
public async Task <JSONPlaceHolderPostOneResponse> PutPost(string postId, JSONPlaceHolderPostObject postObj = null) { RestRequest request = new RestRequest(string.Format(putRoute, postId)); request.AddHeader("Accept", "application/json"); if (postObj != null) { request.AddJsonBody(postObj); } Console.WriteLine( string.Format("Calling JsonPlaceHolder Put at {0}{1} with body\n: {2} for id {3} ", _restClient.BaseUrl, request.Resource, postObj != null ? postObj.ToString() : "<no body>", postId)); var response = await _restClient.ExecuteAsync <JSONPlaceHolderPostObject>(request, Method.PUT); return(new JSONPlaceHolderPostOneResponse { statusCode = response.StatusCode, postObject = response.Data }); }
public async Task PutInvalidID_ShouldReturn404() { //Arrange JSONPlaceHolderPostObject postObj = new JSONPlaceHolderPostObject { body = "putBody", title = "the title", nestedEl = new NestedPostElement { custom1 = "custom field value 1", custom2 = "even more custom fields" }, userId = Guid.NewGuid() }; string postId = "101"; //Act var response = await _jsonPlaceHolderServiceClient.PutPost(postId, postObj); //Assert response.statusCode.Should().Be(System.Net.HttpStatusCode.NotFound, string.Format("because postObject with Id {0} does not exist in the system and thus it cannot be updated", postId)); }