質問

I am try to integrate SagePayMvc.dll into a ASP.NET Web API project which requires ControllerContext.RequestContext to be passed in order to form the Notification Url.

Currently I am experiencing some difficulties in achieving this, I need to pass the ControllerContext.RequestContext from this web api controller:

public class PaymentStartController : ApiController
{
    private PaymentRepository paymentRepository = new PaymentRepository();
    private SagePayHelper sagePayHelper = new SagePayHelper();

    public Order MakePaymentInitial(Payment payment)
    {
        Order order = new Order();

        order = sagePayHelper.MakePayment(payment, context);
        paymentRepository.InsertVendorTXCode(order.VendorTxCode);
        paymentRepository.InsertInitialPaymentDetails(order, payment);
        return order;
    }

}

I have tried to add a public ControllerContext controllerContext = new ControllerContext() below the SagePayHelper instantiation and then subsequently added var context = controllerContext.RequestContext, the problem with this none of the methods inside RequestContext are instantiated either so when SagePayMvc arrives at the point of building the Notification Url which is done inside an IUrlResolver interface an error is thrown.

Is there a way of mocking up ControllerContext.RequestContext, I have previously used RhinoMocks or would it be more prudent to revert to the way I previously implemented SagePayMvc down in the forms project (the forms project is an MVC 4 application that serializes and sends the form data to the web api).

Any advise would be much appreciated.

役に立ちましたか?

解決

ASP.NET Web API uses completely different runtime components from ASP.NET MVC for representing the context and request/response messages. It looks like the API you are using is heavily tied to ASP.NET MVC, which makes it really hard to reuse in ASP.NET Web API unless you initialize the ASP.NET MVC content doing manual mappings. I think it would be easier for you to just use ASP.NET MVC for invoking that method expecting the MVC context.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top