samedi 21 février 2015

How to mock UmbracoContext for unit testing?

I am writing unit tests for ASP.NET MVC application using RhinoMocks and Umbraco. For this I need to mock UmbracoContext, and so used below code. But Umbraco.Core.ApplicationContext.Current throws ArgumentNullException. Please suggest resolution for this:



var contextBase = MockRepository.GenerateMock<HttpContextBase>();
var request = MockRepository.GenerateMock<HttpRequestBase>();
var response = MockRepository.GenerateMock<HttpResponseBase>();
var session = MockRepository.GenerateMock<HttpSessionStateBase>();
var server = MockRepository.GenerateMock<HttpServerUtilityBase>();

contextBase.Stub(ctx => ctx.Request).Return(request);
contextBase.Stub(ctx => ctx.Response).Return(response);
contextBase.Stub(ctx => ctx.Session).Return(session);
contextBase.Stub(ctx => ctx.Server).Return(server);

var umbracoCtx = UmbracoContext.EnsureContext(contextBase, Umbraco.Core.ApplicationContext.Current);

Aucun commentaire:

Enregistrer un commentaire