AdminApiMappingBuilder do not expose WithHeader for Request #695

Closed
opened 2025-12-29 15:31:10 +01:00 by adam · 3 comments
Owner

Originally created by @scrocquesel-ml150 on GitHub (Jun 4, 2025).

Originally assigned to: @StefH on GitHub.

I'm using WireMock.Net.Testcontainers 1.8.9, and I want to match a request on a header like this sample. But WithHeader doesn't exist.

The following code do not compile.
I have to add the package WireMock.Net.Shared to gain access to MatchBehaviour but it is not enough.

Container.CreateWireMockAdminClient().GetMappingBuilder()
                    .Given(m => m
                        .WithRequest(req => req
                            .UsingGet()
                            .WithHeader("Authorization", "*", MatchBehaviour.RejectOnMatch) // see compilation error below
                            .WithPath("/api/hello"))
                        .WithResponse(rsp => rsp
                            .WithBodyAsJson(new
                            {
                                message = "world"
                            })
                            .WithHeaders(h => h.Add("Content-Type", "application/json"))
                        ));

error CS1061: 'RequestModelBuilder' does not contain a definition for 'WithHeader' and no accessible extension method 'WithHeader' accepting a first argument of type 'RequestModelBuilder' could be found (are you missing a using directive or an assembly reference?)

Originally created by @scrocquesel-ml150 on GitHub (Jun 4, 2025). Originally assigned to: @StefH on GitHub. I'm using `WireMock.Net.Testcontainers` 1.8.9, and I want to match a request on a header like this [sample](https://github.com/wiremock/WireMock.Net/wiki/Request-Matchers#reversing-the-match-behaviour-with-matchbehaviourrejectonmatch). But WithHeader doesn't exist. The following code do not compile. I have to add the package `WireMock.Net.Shared` to gain access to `MatchBehaviour` but it is not enough. ``` c# Container.CreateWireMockAdminClient().GetMappingBuilder() .Given(m => m .WithRequest(req => req .UsingGet() .WithHeader("Authorization", "*", MatchBehaviour.RejectOnMatch) // see compilation error below .WithPath("/api/hello")) .WithResponse(rsp => rsp .WithBodyAsJson(new { message = "world" }) .WithHeaders(h => h.Add("Content-Type", "application/json")) )); ``` ` error CS1061: 'RequestModelBuilder' does not contain a definition for 'WithHeader' and no accessible extension method 'WithHeader' accepting a first argument of type 'RequestModelBuilder' could be found (are you missing a using directive or an assembly reference?) `
adam added the feature label 2025-12-29 15:31:10 +01:00
adam closed this issue 2025-12-29 15:31:10 +01:00
Author
Owner

@StefH commented on GitHub (Jun 4, 2025):

@scrocquesel-ml150

The convience-method WithHeader does not yet exists, for now you can use:

.WithHeaders(headersBuilder => headersBuilder
            .Add(headerBuilder => headerBuilder
                .WithName("Authorization")
                .WithMatchers(matchersBuilder => matchersBuilder
                    .Add(matcherBuilder => matcherBuilder
                        .WithName("WildcardMatcher")
                        .WithPattern("*")
                        .WithRejectOnMatch(true)
                    )
                )
            )
        );
@StefH commented on GitHub (Jun 4, 2025): @scrocquesel-ml150 The convience-method `WithHeader` does not yet exists, for now you can use: ``` c# .WithHeaders(headersBuilder => headersBuilder .Add(headerBuilder => headerBuilder .WithName("Authorization") .WithMatchers(matchersBuilder => matchersBuilder .Add(matcherBuilder => matcherBuilder .WithName("WildcardMatcher") .WithPattern("*") .WithRejectOnMatch(true) ) ) ) ); ```
Author
Owner

@StefH commented on GitHub (Jun 4, 2025):

https://github.com/wiremock/WireMock.Net/pull/1306

@StefH commented on GitHub (Jun 4, 2025): https://github.com/wiremock/WireMock.Net/pull/1306
Author
Owner

@scrocquesel-ml150 commented on GitHub (Jun 5, 2025):

Thank you. I don't know why but autocompletion didn't work properly and it was hard to guess the correct methods without the generated code source available.

@scrocquesel-ml150 commented on GitHub (Jun 5, 2025): Thank you. I don't know why but autocompletion didn't work properly and it was hard to guess the correct methods without the generated code source available.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#695