0

Can anyone advise on how to go about Mocking the 'RequestContext' in a WCF service.

I'm currently working on a legacy WCF service that relies heavily upon headers being set in the request context.

Below I have a factory that I'd like to test, but I'm struggling mocking out the request context.

    public IMerchantProvider GetProvider(RequestContext requestContext)
    {
        var mobileRequest = _mobileRequestGenerator.GenerateMobileRequest(requestContext);

        if (UseMerchantService)
        {
            return new MerchantServiceProvider(new MobileObjectsMapper(Mapper.Instance), mobileRequest); //IOC This New, guys.
        }

        return new DataServiceMerchantProvider(mobileRequest, _merchantProgramListHelper, _merchantOfferHelper); 
    }

Note: I am using Moq to mock out the other dependencies.

Thanks,

HelloAmigo
  • 55
  • 6
  • What Edition of visual studio do you use? Enterprise? – zaitsman Jun 12 '17 at 09:23
  • Enterprise 2015 – HelloAmigo Jun 12 '17 at 09:37
  • 1
    @HelloAmigo, The `RequestContext` is abstract. What is stopping the mocking of it? It is unclear from the OP how it is used. Provide a [mcve] that can be used to reproduce the issue. – Nkosi Jun 12 '17 at 10:17
  • @HelloAmigo With enterprise you can use Microsoft Fakes to shim out whatever you use. However, i have to agree with Nkosi - before i can provide an actual example, you need to provide a bit more code of what it is you are trying to test. – zaitsman Jun 12 '17 at 12:58

0 Answers0