SessionID: NotImplementedException on Unit Tests

390 Views Asked by At

I am trying to create unit tests for my ASP.NET MVC project, but facing an issue that could not resolve since quite some time. I am always getting NotImplementedException on Session.SessionID:

System.NotImplementedException: The method or operation is not implemented.
    at MvcContrib.TestHelper.MockSession.get_SessionID()

Here is my TestMethod:

[TestMethod]
public void CannAddCategory()
{
    TestControllerBuilder controllerBuilder = new TestControllerBuilder();

    this.Login();

    HomeController controller = new HomeController();
    controllerBuilder.InitializeController(controller);

    GetAllQuestionsFromInitialCategory(controller);
}

I tried to debug the method, in order to find out the issue, but the error is the same:

System.NotImplementedException: 'The method or operation is not implemented.'

on

this.context = ContextSessionStore.GetInstance().GetQuestionnaireContext(Session.SessionID);

I looked further in SO and there were some suggestions on mocking the Session manually. This did not work as well for me. The error remains.

Manual mocking of session:

var mock = new MockRepository();
var mockSession = mock.Stub<HttpSessionStateBase>();

controller.HttpContext.BackToRecord();
controller.HttpContext.Stub(c => c.Session).Return(mockSession);
controller.HttpContext.Replay()

Any suggestion is appreciated.

UPDATE

Controller method that uses SessionID:

protected QuestionnaireContext Database
{
    get
    {
        if (Session == null)
        {
            this.context = new QuestionnaireContext();
            return this.context;
        }

        this.context = ContextSessionStore.GetInstance().GetQuestionnaireContext(Session.SessionID);
        return this.context;
    }

    private set
    {
        this.context = value;
    }
}
0

There are 0 best solutions below