-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
New feature request: Access to Owin pipeline #53
Comments
I did a POC of how this could work by changing some code in WireMock.net and export a new nuget package, but "least intrusive" might not be a correct term. I had to make WireMockMiddlewareOptions, FluentMockServerSettings and IOwinSelfHost public.
Before this, the code looked like this:
And I had to add 2 optional arguments to the Start method I was using:
And of course pass these into the private constuctor and use them there:
The OwinSelfHost that I created in my solution is a copy of your version, but I made some changes to the StartServer method to initialize SignalR. This is just quick and dirty, my "real" OwinSelfHost would probably be more configurable, instead of having a hardcoded URI in there:
Not super happy about the resulting code changes... But at least I did get SignalR integrated into the solution I had and I could verify that that part would work in theory. |
1] and without fonts breaking, due to always being sent as string, instead of bytes with encoding, courtesy of the string Body property in ResponseMessage). --- This looks like a bug or a new feature 2] I will take a look at your poc code. And check if this can be build in a more easier way. |
Thanks, I appreciate that. If you need any input from me, please don't hesitate. |
1] This issue has been fixed in the code by 07f0399 2] I still have to look into this. 3] Does the mocking work with SignalR, I'm surprised that mocking works? Can you maybe provide a POC client or unit-test to test this ? |
Nice fix. I do not require a nuget package for this right now. I can wait with that for item 2. For 3, I am not really "faking" SignalR itself, but rather create a real signalr hub with the same name as the original. Here I can expose the same methods that I have on the real one, but the data these methods will expose will be fake. So instead of faking the mechanism itself, I just expose fake data with it if that makes sense, I actually fell today and had to get to the ER (hence my late reply) so I am typing (very slowly) with one hand and cannot easily create a POC right now, but once I heal up a bit I will see what I can do. |
That really unfortunately, get well soon! |
Hello @Rmkrs I did add some code which should make it possible to do additional pre and post setup based on the See this code 37244d5#diff-e13c7e694283c3ed3636ff01623747c4R64 at a new branch. Would this be a solution to your problem ? |
@StefH, that would definately solve the challenges we are having with the SignalR wireup. |
@Rmkrs I've merged that code into the main branch so you can use it from there. |
New NuGet is added which includes this functionality. I'm closing this issue for now, if you need more details, please open a new one. |
@Rmkrs |
Hey Stef,
We are looking into using WireMock.net for UI tests for one of our products. To give it some context, we have a single page Aurelia Frontend application talking to a backend using WebAPI2.
We serve the frontend files (/index, etc) but we also have /api/xxx where our backend responds.
And /api/signalr, where the signalr connection lives.
All on the same url:port.
We created a POC to provide fake api data to the frontend using WireMock and that works.
We had to do a little bit of "trickery" to be able to still host our frontend files, by making a "StaticResourceResponseProvider" that allows us to server files from disk based on the URI.
So all uri's now go to the StaticResourceResponseProvider, except for /api/, using the regex "^(?!/api/.$).*".
Per UI test we have different Given/RespondWith setups we do based on what /api/xxx calls we expect and require.
If we had access to the Owin pipeline you use inside WireMock.net we could hook this up a bit nicer (and without fonts breaking, due to always being sent as string, instead of bytes with encoding, courtesy of the string Body property in ResponseMessage).
But why we "really" need access to the Owin pipeline is because we also want to hook up SignalR. We cannot use Response.Create().WithProxy as that breaks the SignalR connection. So ideally I would want to register that on the IAppBuilder, such as:
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
We were looking at ways to accomplish this in WireMock.net, but found no readily available paths. One of the (least intrusive) solutions could be if IOwinSelfHost was public and it could be injected as an argument on the Start methods in FluentMockServer. Right now the private constructor there accepts settings and depending on the pragma NETSTANDARD, either AspNetCoreSelfHost or OwinSelfHost is spawned.
I could imagine creating my own implementation of OwinSelfHost where I can setup any Owin components I would like to use.
Or maybe you have a different/better idea, I am open to suggestions.
The text was updated successfully, but these errors were encountered: