lundi 18 mai 2020

How to mock long chain reference without mocking everything in between?

I have a method that accepts argument RewriteContext rewrite, but then it accesses:

context.HttpContext.Request.PathBase.Value?.Replace('\\', '/')

To test it I create:

Mock<RewriteContext> rewriteContextMock = new Mock<RewriteContext>();

but then how do I setup this context.HttpContext.Request.PathBase.Value? to just return a given string? Do I have to mock everything in between:

  • HttpContext
  • HttpRequest
  • PathBase

?

Aucun commentaire:

Enregistrer un commentaire