Base solution for your next web application
Open Closed

Session when using Abp.TestBase.AbpIntegratedTestBase #226


User avatar
0
bvz created

I am writing unit tests for Abp, and I have a class that inherits from Abp.TestBase.AbpIntegratedTestBase.

When I run this code:

var current = LocalIocManager.IocContainer.Resolve<IAbpSession>();

It resolves to a session of type:

Abp.TestBase.Runtime.Session.TestAbpSession

I did not register this in Castle, so I am guessing that AbpIntegratedTestBase is doing this registration. How can I override this with my own session for testing purposes, so that I can set the logged in user Id for testing?

Thank you for your time and effort!


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    TestAbpSession has setter. You can do it:

    Resolve<TestAbpSession>().UserId = 42;
    

    If you want to override it, you can override PreInitialize method in your test class and register it using LocalIocManager.Register...