Closed cetk closed 4 months ago
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.
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
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.
This is using PactNet 3.x or below, which are deprecated versions. Please update to PactNet 4.x.
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
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.