Соответствие XPath-запроса с WireMock.net - PullRequest
0 голосов
/ 15 октября 2019

Я хочу отправить ложный ответ из моей службы, когда запрос соответствует следующим характеристикам:

  • URL-адрес совпадает с / BATConnectWS / services / CoverApplication
  • Метод HTTP совпадает с POST
  • Соответствующий XPath должен соответствовать сумме 5000

Настройка кода:

var server = FluentMockServer.Start(new FluentMockServerSettings
{
    Urls = new[] { "http://+:8099" },
    StartAdminInterface = true,
    Logger = new WireMockConsoleLogger()
});

server
    .Given(Request.Create().WithPath("/*")).AtPriority(10)
    .RespondWith(Response.Create()
        .WithProxy("https://TheRealService.com/"));

server
    .Given(Request.Create().WithPath("/BATConnectWS/services/CoverApplication").UsingPost()
    .WithBody(new XPathMatcher(@"//applyForCreditLimit/application/RequestedAmount/text() = 5000")))
    .AtPriority(1)
    .RespondWith(Response.Create()
    .WithHeader("Content-Type", "text/xml; charset=utf-8")
    .WithCallback(req =>
    {
        return CoverApplicationResponseBuilder.CreateResponse(req);
    }));

Сообщение запроса:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <soap:Header>
        <wsa:Action>urn:applyForCreditLimit</wsa:Action>
        <wsa:MessageID>urn:uuid:6da4a592-90a0-4623-8c71-1e685cbdac33</wsa:MessageID>
        <wsa:ReplyTo>
            <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
        </wsa:ReplyTo>
        <wsa:To>http://localhost:58070/BATConnectWS/services/CoverApplication</wsa:To>
        <wsse:Security soap:mustUnderstand="1">
            <wsu:Timestamp wsu:Id="Timestamp-6befddc7-4e4f-4a76-a203-49b729bd483a">
                <wsu:Created>2019-10-15T08:22:37Z</wsu:Created>
                <wsu:Expires>2019-10-15T08:27:37Z</wsu:Expires>
            </wsu:Timestamp>
            <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-x-x-x-x-x">
                <wsse:Username>xxx</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxx</wsse:Password>
                <wsse:Nonce>xxx</wsse:Nonce>
                <wsu:Created>2019-10-15T08:22:37Z</wsu:Created>
            </wsse:UsernameToken>
        </wsse:Security>
    </soap:Header>
    <soap:Body>
        <applyForCreditLimit xmlns="http://atradius.com/connect/_2007_08/">
            <application>
                <CustomerId xmlns="">1234</CustomerId>
                <PolicyNr policyTypeIdentifier="NON_LEG" xmlns="">
                    <Id>5678</Id>
                </PolicyNr>
                <ExternalCoverId xmlns="">9101112</ExternalCoverId>
                <CustomerReference xmlns="">areference</CustomerReference>
                <Buyer registeredOffice="SYMPH" xmlns="">
                    <id xmlns="http://atradius.com/organisation/_2007_08/type/">13141516</id>
                    <countryTypeIdentifier xmlns="http://atradius.com/organisation/_2007_08/type/">AUT</countryTypeIdentifier>
                </Buyer>
                <RequestedAmount xmlns="">5000</RequestedAmount>
                <CurrencyCode xmlns="">EUR</CurrencyCode>
            </application>
        </applyForCreditLimit>
    </soap:Body>
</soap:Envelope>

Без * XPathMatcher будет послан смоделированный ответ.
При XPatchMatcher будет вызвана реальная служба (через)потому что не было совпадения WithBody в содержимом.

Каким должен быть запрос XPath для совпадения на сумму 5000 в элементе RequestedAmount?

1 Ответ

0 голосов
/ 08 ноября 2019

Это может быть связано с используемыми пространствами имен, может быть?

Если вас интересует только то, что в сообщении мыла есть какой-либо элемент RequestedAmount со значением 5000, вы можете просто использовать это, я думаю:

@"//RequestedAmount/text() = 5000"
...