I'm trying to Mock an HttpWebRequest (from the System.Net namespace) object, but I keep getting runtime errors. It seems that the only constructor for HttpWebRequest is protected and has been Deprecated by Microsoft. If this is the case, how would I could about Mocking an object which doesn't give access to it's constructor?
Here is my code. It dies when Arranging the HttpUtils.CreateWebRequest call. CreateWebRequest is a static method of the non-static class HttpUtils.
Here is my code. It dies when Arranging the HttpUtils.CreateWebRequest call. CreateWebRequest is a static method of the non-static class HttpUtils.
private HttpWebRequest _webRequestMock;
private void SetupMocks() {_webRequestMock = Mock.Create<HttpWebRequest>();_webResponseMock = Mock.Create<WebResponse>(); Mock.SetupStatic<HttpUtils>(Behavior.Strict); Mock.Arrange(() => HttpUtils.CreateWebRequest(Arg.IsAny<string>())).Returns(_webRequestMock); Mock.Arrange(() => _webRequestMock.GetResponse()).Returns(_webResponseMock); }