Geeks With Blogs
Abhishek Anand Bits & Bytes about .net technology framework. moq
Unit tests for HttpClient using HttpMessageHandler
You can unit test a class that uses HttpClient by giving that HttpClient a mock HttpMessageHandler. This way, you can capture the request and prevent it from actually going over the wire. Here is an example using Moq. HttpClient depends on HttpMessageHandler’s SendAsync() method, so give SendAsync() a stub implementation and use Moq’s Callback() to capture arguments. var handler = new Mock<HttpMessageHandler&... handler.Protected() .Setup<Task<HttpRespo... ......

Posted On Wednesday, November 20, 2013 4:32 PM

Moq – Return a Parameter
Moq provides an additional overload for the Returns method that takes a lambda expression with the same parameters as the method signature. When this overload is used, Moq will inject the parameters passed to the Setup method into the Returns as its lambda expression parameters. Note: The parameters for the lambda expression must match up in both number and ordering to the method signature. Example 1: public interface ITestInterface { string SomeMethod(string str); } … mockTestInterface.Setup(i => ......

Posted On Monday, November 18, 2013 6:27 PM

Copyright © Abhishek Anand | Powered by: