Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pact request body with inner object gives internal server error in Pact Net #494

Closed
cetk opened this issue Feb 26, 2024 · 6 comments
Closed

Comments

@cetk
Copy link

cetk commented Feb 26, 2024

_mockProviderService.UponReceiving("a request to create a new event")
    .With(new ProviderServiceRequest{
        Method = HttpVerb.Post, Path = "/events",
        Headers =
            new Dictionary<string, object>{
                {"Content-Type", "application/json; charset=utf-8"}},
        Body =
            new {eventId, eventType = "DetailsView",
                 timestamp = new TimeObject{date = "2024-02-25 21:38:57.290"}}})
    .WillRespondWith(new ProviderServiceResponse{Status = 201});
@mefellows
Copy link
Member

mefellows commented Feb 26, 2024

I don't believe you can just pass objects to the DSL arbitrarily, unless they have an implicit conversion to a JSON type. The input to the interaction needs to map to the payload that will actually be sent over the wire.

NOTE: you can use the code gates (```) to better format your code and aid with readability. I have updated your question to do that now.

@cetk
Copy link
Author

cetk commented Feb 26, 2024

Thanks for reply. In java, we have PactDslJsonBody which I believe is extension to DslBody in which we can pass arrays or objects like this -
private val postRequestBody: PactDslJsonBody = PactDslJsonBody()
.array("events")
.uuid(currentUserId.toString())
.uuid(participantId.toString())
.closeArray().asBody()
.array("eventItems")
.object()
.stringValue("title", "Event Item 1")
.stringValue("notes", "Notes for item 1")
.booleanType("editable", true)
.closeObject()
.closeArray().asBody()
.and("title", "Event Title")
.object("schedule")
.stringType("startAt", "2023-01-19T12:41:41.111503Z")
.stringType("endAt", "2023-02-19T12:41:41.111503Z")
.closeObject()
.asBody()

can be used as
@Pact(consumer = "Event-api-consumer", provider = "Event-service-conversations")
fun postEventPact(builder: PactDslWithProvider): RequestResponsePact {
return builder
.given("user exists")
.uponReceiving("a request to create a event")
.path("/$BASE_URL$EVENTS_PATH")
.method("POST")
.headers(requestHeaders)
.body(postRequestBody)
.willRespondWith()
// .headers(headers)
.status(HttpStatus.SC_CREATED)
.body(postResponseBody)
.toPact()
}

I am looking for .NET version for PactDslJsonBody

@cetk
Copy link
Author

cetk commented Feb 27, 2024

Adding to above, I am using .NET framework 4.6.2, don't have liberty to upgrade to latest version for .NET framework or .NET Core. I may upgrade PactNet if it will resolve above error.

@adamrodger
Copy link
Contributor

This is using PactNet 3.x or below, which are deprecated versions. Please update to PactNet 4.x.

@adamrodger adamrodger closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2024
@mefellows
Copy link
Member

See also the docs for the 3.x.x line (including working examples) here: https://github.com/pact-foundation/pact-net/tree/3.0.2

@cetk
Copy link
Author

cetk commented Mar 1, 2024

Thanks for reply. I understand upgrading the version but my project uses .NET framework 4.6.1 and I believe the latest PactNet version doesn't support this .NET framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants