Skip to content

StatusCodeShouldBeSuccess incorrectly runs the default exact 200 assertion alongside the 2xx range check #228

Description

@dat-honguyen

Summary

There are 2 bugs:

  • Calling StatusCodeShouldBeSuccess() on a scenario does not disable the default "expected status code 200" assertion. This causes two problems:

    • False failures for valid 2xx codes: A response with status 201, 202, 204, etc. is a successful response, but the scenario fails with "Expected status code 200, but was 201/202/204" because the default exact 200 check still runs.
    • Misleading error messages: When a non 2xx code is returned, example 500, the failure message says "Expected status code 200, but was 500" instead of the more accurate "Expected a status code between 200 and 299, but was 500".
  • There is another bug in the happy test case that suppresses the bug above:

    • The test named using_scenario_with_StatusCodeShouldBeSuccess_happy_path was actually testing the failure case (wrapping in ShouldBeThrownBy expecting an exception). There was no test verifying that a valid 2xx response (204) passes StatusCodeShouldBeSuccess() without throwing.

Expected Behavior

StatusCodeShouldBeSuccess() should only validate that the status code falls in the 200–299 range. It should suppress the default exact 200 check.

Steps to Reproduce

await host.Scenario(x =>
{
x.Get.Url("/returns-204");
x.StatusCodeShouldBeSuccess(); //throws: "Expected status code 200, but was 204"
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions