Skip to content

TraceId and similar should be a fixed value when Testing with WebApplicationFactory #61207

Open
@snebjorn

Description

@snebjorn

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When using builder.Services.AddProblemDetails(); error output like 400 will have a traceId - which is useful.

{
  "type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "traceId": "00-9a91dea3f49537ea081001f1435df8f6-9a48ee11db3f47a3-00"
}

However when writing tests using WebApplicationFactory the returned traceId is out of my control or at least not straight forward to set to a known value.

Expected Behavior

traceId and similar tracking ids should be fixed or easily configurable when testing via WebApplicationFactory.

Steps To Reproduce

  1. Spin up a asp net web api
  2. Add builder.Services.AddProblemDetails();
  3. Make an endpoint return a bad request
  4. Write a test that checks the returned data
  5. Notice the traceId change

Exceptions (if any)

No response

.NET Version

9.0.202

Anything else?

The easy workaround is to ignore traceId in the test. But that's not the point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-mvc-testingMVC testing package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions