How I would make fun of a request

using the following in moq

public Mock<HttpRequestBase> Request { get; set; } 

how can I mock this request [....]

 (in controller) var modelFromPost = Request["mymodel"] 

that's what i still have

 public class ContextMocks { public Mock<HttpContextBase> HttpContext { get; set; } public Mock<HttpRequestBase> Request { get; set; } public RouteData RouteData { get; set; } public ContextMocks(Controller controller) { HttpContext = new Mock<HttpContextBase>(); HttpContext.Setup(x => x.Request).Returns(Request.Object); } } 

Hurrah!

+6
source share
1 answer

You can mock indexers using the SetupGet method:

 ContextMocks.Request.SetupGet(r => r["mymodel"]).Returns(myModel); 
+5
source

Source: https://habr.com/ru/post/921735/


All Articles