Skip to content

RestRequest post fails when using AddBody with string. This worked fine in 107.3.0. #1886

Closed
@HHasenack

Description

@HHasenack

This piece of code works just fine using restsharp v107.3.0 but failes when using 108.0.1

public async Task PostTest()
        {
            var calcId = await AddCalculationSetup();

            string paramValue = "InvalidValue";

            // Set a parameter with an invalid value
            var request = new RestRequest($"{url}/CalculationSetups/{calcId}/Parameters/InheritsFromCalcSetup").
                              AddBody(paramValue);
            var response = await restClient.ExecutePostAsync(request); 
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, response.Content);
           . . .

The controller handler involved looks like this, but doesnt get called when using restclient v108, as stated before v107 works fine.

. . .
        /// <summary>
        /// Set a value for a parameter
        /// </summary>
        /// <param name="projectIdentifier">identifier of the project</param>
        /// <param name="itemIdentifier">identifier of the parameterized collection item</param>
        /// <param name="parameterIdentifier">identifier of the parammeter</param>
        /// <param name="value">value for the param</param>
        [HttpPost]
        [SwaggerOperation("Set a value for a parameter")]
        [Route("{parameterIdentifier}")]
        [SwaggerResponse(StatusCodes.Status201Created)]
        [SwaggerResponse(StatusCodes.Status404NotFound, Type = typeof(string))]
        [SwaggerResponse(StatusCodes.Status400BadRequest)]
        public virtual IActionResult Post(string projectIdentifier, string itemIdentifier, string parameterIdentifier, [FromBody] object value)
        { . . . }

The Assert in the unit test statement fails, and error returned is:

 PostTest
   Source: ValueSetTest.cs line 30
   Duration: 200 ms

  Message: 
Assert.AreEqual failed. Expected:<Created>. Actual:<BadRequest>. {
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "traceId": "00-4fc8ce2dfbaa969137ff4f9482017569-1090e9c87770ee73-00",
  "errors": {
    "$": [
      "'I' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0."
    ],
    "value": [
      "The value field is required."
    ]
  }
}

  Stack Trace: 
ValueSetTest.PostTest() line 40
ThreadOperations.ExecuteWithAbortSafety(Action action)

  • Thx, Hans

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions