c# - How do I mock HttpResponseBase.End()? -
I'm using MUQ to make a fake object of the HTPRpacebase. I should be able to verify that the HTTPRPS Pacebase End () was called in my library. To do this, I specify some text and some text before calling. Again I will check that the call to end () call the HTPRPSpacebase Output exists in the output.
The problem is, how can I not make fun of HTPRECAppbase? End () so that it is closed processing, as it is in ASP.NET.
create public static HTTPPSpacebusHTPRPSpacebase () {var mock = new mock & lt; HTTPRPSSpaceBase & gt; (); String Vector output = new stringwriter (); Fake.setupproperty (x = & gt; x.StatusCode); fake. Setting Gate (x = & gt; x.Output) Return (output); Fake. Setup (x = & gt; x.End ()) / * What should I do here? * /; Fake. Setup (x = & gt; x.Write (any; string & gt; ())). Callback & lt; String & gt; (S => Output. Writ (s)); Return fake. Object; }
It is a bit unclear to me that what you are trying to achieve, But from your statement, it seems that you are trying to behave like a special implementation of your abstraction. In other words, because HttpResponse.End () has a specific behavior, do you want your fake behavior to be the same?
In general, it is not easy to do this especially with the Moq, because it has no concept of expectations respectively (as opposed to Rhinomox) however, A.
You may be able to use a callback with the setting of the last method to toggle any flag that determines another behavior of the fake, but it will not be particularly beautiful . I am thinking about something like this: Expiration = bool = wrong; Var Mock = New Mock & Lt; HTTPRPSPacebase & gt; (); Counterfeit. Setup (x = & gt; x.End ()). Callback ((=); end = true); // 'Ended' and other setup associated with callback
There is a double implementation in all other setups, based on this the end
is correct or false.
It will be very ugly, so I will seriously reconsider my choice at this point. You can take at least two directions:
- Instead of using the mukka Fake implementation of HTTPRPSpacebase. It seems that you are expecting such specific behavior of implementation, in which a test double with embedded logic looks like a better option. Soon, there is a duplicate test double that can have semi-complex arguments that mimics the desired production implementation. In excellent books you can read more about Fox and other test doubles.
- Reconsider your initial assumptions It seems to me that you are binding your customer very closely for any special behavior of the HTTPRPSpacebase, so you are violating the Liskov replacement principle. However, I can be considered wrong, because in a method called 'end' there is some meaning beyond purely meaning, but still, I personally think that better design is possible or not.
/ html>
Comments
Post a Comment