/// <summary> /// Class that mocks HttpContext. /// </summary> public MockHttpContext() { _applicationStateMock = new Mock <HttpApplicationStateBase>(); _contextMock = new Mock <HttpContextBase>(); _requestMock = new Mock <HttpRequestBase>(); _responseMock = new Mock <HttpResponseBase>(); _sessionMock = new Mock <HttpSessionStateBase>(); _serverMock = new Mock <HttpServerUtilityBase>(); _paramsCollection = new NameValueCollection(); _cachePolicyMock = new Mock <HttpCachePolicyBase>(); _postedFiles = new HttpFileCollectionMock(); _contextMock.Setup(c => c.Application).Returns(_applicationStateMock.Object); _contextMock.Setup(c => c.Request).Returns(_requestMock.Object); _contextMock.Setup(c => c.Response).Returns(_responseMock.Object); _contextMock.Setup(c => c.Session).Returns(_sessionMock.Object); _contextMock.Setup(c => c.Server).Returns(_serverMock.Object); _requestMock.Setup(c => c.Params).Returns(_paramsCollection); _responseMock.Setup(c => c.Cache).Returns(_cachePolicyMock.Object); _requestMock.Setup(m => m.Files).Returns(_postedFiles); _requestMock.Setup(r => r.InputStream).Returns(() => { return(_requestStream); }); _responseStream = new MemoryStream(); _responseMock.Setup(m => m.OutputStream).Returns(_responseStream); }
private MemoryStream _responseStream; // Response value written to this string builder. #endregion Fields #region Constructors /// <summary> /// Class that mocks HttpContext. /// </summary> public MockHttpContext() { _applicationStateMock = new Mock<HttpApplicationStateBase>(); _contextMock = new Mock<HttpContextBase>(); _requestMock = new Mock<HttpRequestBase>(); _responseMock = new Mock<HttpResponseBase>(); _sessionMock = new Mock<HttpSessionStateBase>(); _serverMock = new Mock<HttpServerUtilityBase>(); _paramsCollection = new NameValueCollection(); _cachePolicyMock = new Mock<HttpCachePolicyBase>(); _postedFiles = new HttpFileCollectionMock(); _contextMock.Setup(c => c.Application).Returns(_applicationStateMock.Object); _contextMock.Setup(c => c.Request).Returns(_requestMock.Object); _contextMock.Setup(c => c.Response).Returns(_responseMock.Object); _contextMock.Setup(c => c.Session).Returns(_sessionMock.Object); _contextMock.Setup(c => c.Server).Returns(_serverMock.Object); _requestMock.Setup(c => c.Params).Returns(_paramsCollection); _responseMock.Setup(c => c.Cache).Returns(_cachePolicyMock.Object); _requestMock.Setup(m => m.Files).Returns(_postedFiles); _requestMock.Setup(r => r.InputStream).Returns(() => { return _requestStream; }); _responseStream = new MemoryStream(); _responseMock.Setup(m => m.OutputStream).Returns(_responseStream); }