Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Feb 07 22:21
    StefH assigned #883
  • Feb 07 22:20
    chrisw11112 edited #883
  • Feb 07 22:19
    chrisw11112 edited #883
  • Feb 07 22:18
    chrisw11112 opened #883
  • Feb 07 22:18
    chrisw11112 labeled #883
  • Feb 06 19:56
    StefH labeled #882
  • Feb 06 19:55
    StefH assigned #882
  • Feb 06 19:55
    StefH opened #882
  • Feb 06 19:50
    StefH closed #881
  • Feb 04 19:51
    StefH updated the wiki
  • Feb 04 19:50
    StefH updated the wiki
  • Feb 02 12:49
    StefH synchronize #881
  • Feb 01 20:44
    StefH labeled #881
  • Feb 01 20:44
    StefH assigned #881
  • Feb 01 20:44
    StefH opened #881
  • Feb 01 09:42
    StefH closed #880
  • Feb 01 09:42
    StefH closed #879
  • Feb 01 09:29
    StefH labeled #880
  • Feb 01 09:29
    StefH opened #880
  • Feb 01 09:29
    StefH assigned #880
Stef Heyenrath
@StefH
@SunmasterFourteen can you please create an issue on the GitHub project?
narendrachava
@narendrachava
Hi,
I'm trying to use WireMock.Net for the first time. I'm using StandAlone app (as a Console application in .NET core) and I'm able to successfully record the mappings and replay them on my local machine (windows) during test execution.
But when I try to execute the tests in CI/CD pipeline, I get a connection refused error, although wiremock server is up and running (from the log).
Any idea what is going on here ?
8/20/2020 1:37:54 AM [Info] : WireMock.Net server listening at http://localhost:8700
 $ echo "$(curl -H 'Accept:*/*' http://localhost:8700)"
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to localhost port 8700: Connection refused
Stef Heyenrath
@StefH
@narendrachava This is difficult to see what's the cause.
Is the standalone still running when you execute the CURL command?
And maybe it's better not to use a fixed port, but a dynamic one. Unless you are certain the port is free is can be used by WireMock.Net
narendrachava
@narendrachava
@StefH Thanks for the response, Yeah, you're right, turns out that the server isn't running when CURL command is executed. I had a "Console.Read" statement at the end, to keep the server running. But, looks like in Linux , that statement doesn't keep the process alive.
Now I'm running the server as a background service wrapping the implementation as"IHostedService". But now the problem is, CI/CD runner is stuck after the CURL command is executed.. doesn't exit successfully.. trying to figure that out..
Cezary Piątek
@cezarypiatekGC
Hi, I would like to use WireMock.Net in my project but I need to handle the following scenario. When we run tests locally (in VisualStudio) then we want to run WireMock in memory using WireMockServer.Start. When we run tests in CI then we want to use docker container with WireMock and connect to it from the test code and from the tested application. Besides that difference, we would like to have a consistent API to define mocking rules. However, it doesn't seem to be possible right now because WireMock client uses different models to define mappings (MappingModel) and the MappingConverter which could convert IMapping to MappingModel has internal modifier. Is it possible to expose the method which could perform that conversion? Or am I doing something wrong and there's an option to define Mappings once and use it with WireMockServer and with standalone (docker) app?
2 replies
Cezary Piątek
@cezarypiatekGC
Ofc, WireMockServer has WithMapping method which accepts MappingModel but creating MappingModel manually seems to be a very tedious task. I Would prefer to use that fluent interface with Request.Create() and Response.Create()
genesispvtltd
@genesispvtltd
Hi I am new to wiremock but I need to know the answers to the following questions. I have a automation test suite running against an api. Sometimes this api is not available then I need automation test to be run against wiremock server and this should happen automatically I mean wiremock should be intelligent enough to understand the live url is down and it will call the stubs allready created. I tried wiremock standalone version and this is not happening. I started the wiremock on proxy mode and the live url is up and running I sent a request and it does hit live url, and then next I block the live url using the windows host file. I restareted wiremock and I again sent the request to wiremock server running in proxy mode but it fails and send me "No connection could be made because the target machine actively refused it." please help me to understand why I am facing this issue Below is my code also please understand I am ussing csharp code to write my stubs and i want them to be added as static mappings as well so I am doing it in the code............................................................................................................................................... class Program
{
static void Main(string[] args)
{
var hostFile = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
IConfiguration appSettings = new ConfigurationBuilder()
.AddJsonFile(Path.Combine(hostFile, "appsettings.json"), true, true)
.Build();
// Proxying,Play, Record
appSettings["mode"] = "Proxying";
appSettings["url"] = "http://localhost:7777";
appSettings["proxyUrl"] = "https://mySecurityApi.com";
        WireMockServerSettings settings = null;

                 settings = new WireMockServerSettings
                {
                    Urls = new[] { appSettings["url"] },
                    StartAdminInterface = true,

                    AllowPartialMapping =true,
                    Logger = new WireMockConsoleLogger(),
                     ProxyAndRecordSettings = new ProxyAndRecordSettings
                     {
                         Url = appSettings["proxyUrl"],                          
                     }
                 };



        var wiremockServer = StandAloneApp.Start(settings);

        wiremockServer            
          .Given(              
          Request.Create().WithPath("/Accounts/api/securityhelper/getauthtoken")
          .UsingGet()                          
          .WithCookie("paycorAuth", new RegexMatcher(".*"))

          )
          //.AtPriority(100)
          .RespondWith(
            Response.Create()
             .WithProxy(appSettings["proxyUrl"])
             .WithBody("12345")
          );

        wiremockServer.SaveStaticMappings();


        Console.WriteLine("Press any key to stop the server");
        Console.ReadKey();

    }
}
msutar021
@msutar021
I am new to wiremock.net. I need to create stub for https soap service. Can someone please share a sample or let me know if we can achieve this using wiremock.net
Stef Heyenrath
@StefH
@msutar021 If you have some example requests and responses, just create mappings for these, just like other mocks. Else you could use the proxy and record fnctionality to get example requests/responses.

@genesispvtltd I did already comment on your issue (WireMock-Net/WireMock.Net#580) and I'll copy-paste the info also here as a reference:

Short answer: WireMock.Net does not yet support a "Smart Proxy" functionality as you describe.

Long answer: This can probably be implemented as defined here:
Scenario 1
In case the real endpoint is up (we need to determine the criteria for up, like != 200 OK), proxy the request + response to the real endpoint.

Scenario 2
In case the real endpoint is down, try to find a configured mapping:

If the mapping is found, return that mapping.
If the mapping is not found, just return default 404 'mapping not found'.

genesispvtltd
@genesispvtltd

@StefH need some information regarding NTLM authentication some of our endpoints are using NTLM authentication so i need to use proxying there so the code looks like below Cookie AuthCookie = null;
try
{

            var authRequest = WebRequest.Create("https://localhost:7777/Accounts/Auth") as HttpWebRequest;
            authRequest.CookieContainer = new CookieContainer();
            authRequest.AllowAutoRedirect = false;
            authRequest.ContentType = "application/x-www-form-urlencoded";
            authRequest.KeepAlive = true;
            CredentialCache userCredentials = new CredentialCache();
            userCredentials.Add(
                new Uri("https://live.com/"),
                "NTLM",
                new NetworkCredential("username", "Password", ""));
            authRequest.Credentials = userCredentials;


            using (var authResponse = authRequest.GetResponse() as HttpWebResponse)
            {
                AuthCookie = authResponse.Cookies["payment"];


            }
        }
        catch (Exception ex)
        {


        }

And I have created a stub as well wireMockServer
.Given(
Request.Create().WithPath("/Accounts/Auth")
.UsingGet()

    )
    .RespondWith(
      Response.Create()
       .WithProxy(proxyUrl)
    );

But when I proxy I am getting the underlying connection is closed message any example how I can use NTLM authentication I would appreciate thanks

sumit1112
@sumit1112
Hi,
I am trying to use wire-mock docker with static mapping files. How can I do that? Is including mapping files is possible at run time? If not can you please provide me a docker file which I can use to use static files/folders to be included while running.
Stef Heyenrath
@StefH
hvariant
@hvariant
Hi there, I'm wondering if it's possible to use states without scenario? or somehow make a default scenario?
we have a lot of stubs and I need to use state but don't want to change every single one just to make this one thing work
hvariant
@hvariant
actually, will scenarios from different instances of WireMockServer interfere with each other?
hvariant
@hvariant
can you mix stubs with scenario and stubs without scenario?
I think I'm misunderstanding how it works
hvariant
@hvariant
I think I found a bug but I don't have time to create an example at the moment
Stef Heyenrath
@StefH
@hvariant : you can define "normal mappings" besides "special mappings" which needs a scenario. This should just work fine.
Or do you mean something else?
lukasT1010
@lukasT1010

Hello!
I try to install the WireMock.Net NuGet package (https://www.nuget.org/packages/WireMock.Net/) with the command line: "Install-Package WireMock.Net"

After a while, the command line tells me: "Install-Package: Unable to find dependent package(s) (Handlebars.Net)"? Handlebars.Net is a dependency of WireMock, however, I thought, NuGet resolves the dependencies automatically.

Stef Heyenrath
@StefH
@lukasT1010 - Handlebars.Net is referenced via Handlebars.Net.Helpers, this is used by WireMock.Net
David Kennedy Souza Araújo
@DavidUser
Hello! I am having a problem using the Logger configuration
I need to just log to console when a test with the mock request fails
Commonly I use or forward the ITestOutputHelper to the application
That way I know what is happening on failure otherwise the console keep clean.
The problem is that using the FluentMockServer I had no option
            _serviceMock = FluentMockServer.Start(new FluentMockServerSettings {
                    Logger = new WireMockConsoleLogger()
                });
I get console log to everything or nothing
The Logger is a IWireMockLogger instead a ILogger
David Kennedy Souza Araújo
@DavidUser
Does someone know how to turn around?
Stef Heyenrath
@StefH
David Kennedy Souza Araújo
@DavidUser
@StefH it works great! Thanks
Stef Heyenrath
@StefH

@StefH it works great! Thanks

+1

msutar021
@msutar021

I want to create a mock response for SOAP service which accepts XML request body. I'm using XPathMatcher for request matching. Request is matching successfully. I need to read one attribute of request.body and create the response using that.
My XML request is like this. I need the token id to create the response body.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.Test.nl/XMLHeader/10" xmlns:req="http://www.Test.nl/Betalen/card/Services/RdplDbTknLystByOvkLyst/8/Req">
<soapenv:Header>
<ns:ReqHeader>
<ns:HeaderVersion>10</ns:HeaderVersion>
<ns:MessageId>MsgId10</ns:MessageId>
<ns:ServiceVersion>8</ns:ServiceVersion>
<ns:MessageTimestamp>?</ns:MessageTimestamp>
</ns:ReqHeader>
</soapenv:Header>
<soapenv:Body>
<req:RdplDbTknLystByOvkLyst_REQ>
<req:Code>CSC</req:Code>
<!--Optional:-->
<req:Detail>Test</req:Detail>
<req:TokenIdLijst>
<!--1 to 10 repetitions:-->
<req:Tokenid>0000083256</req:Tokenid>
<req:Tokenid>0000083259</req:Tokenid>
</req:TokenIdLijst>
</req:RdplDbTknLystByOvkLyst_REQ>
</soapenv:Body>
</soapenv:Envelope>
I am using these matcher model while creating mapping
var matcherModel = new MatcherModel
{
Name = "WildcardMatcher",
Pattern = "/xpathsoap",
RejectOnMatch = false,
IgnoreCase = true
};

        var bodymatcherModel = new MatcherModel
        {
            Name = "XPathMatcher",
            Pattern = "//*[local-name() = 'RdplDbTknLystByOvkLyst_REQ']",
            IgnoreCase = true
        };

I am trying to get the response as below.
var response = new ResponseModel()
{
StatusCode = 201,
Headers = header,
Body = "{{ XPath.SelectNodes request.body \"//TokenIdLijst/Tokenid \"}}",
UseTransformer = true
};
I am able to get the whole request.body. But Response.body is always empty after applying xpath.

msutar021
@msutar021
How to get attribute from the request in the above situation
Stef Heyenrath
@StefH
@msutar021 Can you post your question on the GitHub ?
https://github.com/WireMock-Net/WireMock.Net/issues
That's easier to read.
Andrei Yakubovich
@AndreiYakubovich

Hi everyone.
I need some help.
I have situation like that:
One wiremock server which starts in static [BeforeTestRun] (I need special port, so can not run it on every test).
Many unit tests which work in parallel.
Every unit test use wiremock with the same path, but they have InScenario(testName).
For example test1 ping google.com and should get NotFound.
I have added .InScenario("test1").
Test2 should get InternalError on the same request. I have added .InScenario("test2").

But when you run 10+ tests at once, some of them gets wrong responses (not from their scenarios).
it looks like the scenarios are mixing.

How should I specify the scenarion for every separate test correctly?

msutar021
@msutar021
Is there good example for Response templating in .net. I need to create a dynamic soap response with multiple nodes based on the request.
Tmp Email
@tmpemailadd24_gitlab
Hello everyone,
Just a few quick question and was wondering if anyone may encounter this too:
  • Is it possible to call the generated url directly (eg. _server.Urls[0]) as going to the link from browser does not seem to show anything & it keeps loading?
  • Has anyone encounter additional error response (eg. 404) besides the set .RespondWith(...) status code?
    Thanks!
Stef Heyenrath
@StefH
@tmpemailadd24_gitlab
  1. When WireMock.Net is running as console, docker or web-app, you should be able to go to the _server.Urls[0], but when no mappings are defined, you shouild get 404
  2. In case of an 404 (mapping not found), you can use the additional error log to see how good the request was matched.
Gnannondorf
@Gnannondorf
Hey, I'm trying to write an E2E test where I'm trying to mock three external dependencies using WireMock.NET. How would I setup my WireMock server to respond to each of the three different base URLs? Can I simply add multiple base URLs and go on with creating different requests with different paths?
Richard Tasker
@ritasker
Morning all, I am having trouble matching the body of a request with the JSONPath matcher. The content contains an array of strings and I want to return a different response if the array contains a specific string.
Richard Tasker
@ritasker
I have tried 'data.myArray[*] == 'my value'`data.myArrary.indexOf('my value') != -1 and data.myArrary[?(@ == 'my value')] != null from a couple of SO answers, but all fail to match and return 404
Any advice would be helpful thanks.
Stef Heyenrath
@StefH
@ritasker Can you please create an question with source code / example messages on the github project?

@Gnannondorf
That could maybe work. (maybe you need to update your hosts file)

Another option could be to use different ports.

Mario Diaz
@devmariodiaz
Thanks, Stef, Wiremock is the greatest library to build Mocks
mamta singh
@mamtasingh123_twitter
Hi @StefH , I am using wiremock.net for my integration tests. when I run tests one by one all are passing but when I am running all the tests in group the test with post request is giving internal server error. This test is runs after get requests. Can you pls help?
Stef Heyenrath
@StefH
@mamtasingh123_twitter : this is difficult to say without looking the code. Can you please create an issue and provide as much as details as possible?