WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.42k stars 209 forks source link

Is transforming contents of XML file supported.? #386

Closed dileepsam closed 4 years ago

dileepsam commented 4 years ago

Hi,

I am trying to use this as a standalone app to mock the server, when configured an XML file as a response,

how to transform the contents of the file.?

Thanks,

StefH commented 4 years ago

An XML response is just plain text, so you can transform all things you like.

dileepsam commented 4 years ago

I have configured response like below

"Response": {
    "BodyAsFile": "Success.xml",
    "Headers": {
      "Content-Type": "application/xml; charset=UTF-8"
    },
    "StatusCode": 201,
    "UseTransformer": true
  }

Success.xml contains Handlebar transformation which does not seem to work.

Am I missing something.?

StefH commented 4 years ago

Currently the transformation is only done for the filename, not yet for the file contents.

I'll take a look.

StefH commented 4 years ago

A preview NuGet is available on MyGet: WireMock.Net.1.0.38-ci-12271.nupkg

You need to provide an extra property ("UseTransformerForBodyAsFile": true)in the mapping:

{
    "Guid": "fd8ca21b-db82-48bc-ae5a-fc2153c2b0db",
    "Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "WildcardMatcher",
                    "Pattern": "/bodyasfile_transform123"
                }
            ]
        },
        "Methods": [
            "get"
        ]
    },
    "Response": {
        "StatusCode": 200,
        "Headers": { "Content-Type": "application/xml" },
        "BodyAsFile": "c:\\temp-wiremock\\__admin\\mappings\\_{{request.query.MyUniqueNumber}}_\\MyXmlResponse.xml",
        "UseTransformer": true,
        "UseTransformerForBodyAsFile": true
    }
}
dileepsam commented 4 years ago

Thank you, Stef. It works.

StefH commented 4 years ago

https://github.com/WireMock-Net/WireMock.Net/pull/388