Base solution for your next web application

Activities of "pradippatil"

Thanks for the reply!

I needed that because I did not want to start transaction. I got that working by setting "isTransactional: false" in UOW attribute.

One more question is should we set isTransactional: false on application service methods which only performs get/select operation? Just to avoid unnecessary starting transactions in such case. Will it be useful to improve the performance?

Thanks!

Hi,

I have tried to add below code in EntityFramework and Web project module classe's PreInitiliaze method: In which module's PreInitialize method we need to add below code?

Configuration.UnitOfWork.OverrideFilter(AbpDataFilters.MayHaveTenant, false);
            Configuration.UnitOfWork.OverrideFilter(AbpDataFilters.MustHaveTenant, false);

But still only MayHaveTenant filter got disabled and MustHaveTenant filter was still enabled.

What I am missing here?

Thanks

Hi,

Is it a good idea to disable tenant filters globally in the DbContext itself?

protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.DisableFilterGlobally(AbpDataFilters.MayHaveTenant);
            modelBuilder.DisableFilterGlobally(AbpDataFilters.MustHaveTenant);
        }

I have disabled filters globally using above code in DbContext class, but MayHaveTenant filter is still enabled. Any idea why DisableFilterGlobally not working?

Thanks

Okay, Thanks!

I would like to know when permissions inserted in cache? I mean which event and class

Thanks

Hi,

Can anyone help me on this?

Thanks

First issue has been resolved, it was due to old data.

How to update permission cache when permissions of role changed?

Thanks

Does anyone has answer for this?

Thanks

Answer

Hi,

Finally, I got rid of this issue of using custom session properties in unit testing.

However, I tried the below code as suggested:

Configuration.ReplaceService<IAbpSession, TestGPASession>();

But, didn't work.

So, I tried to use interface IGPASession instead of GPASession concrete class as property type in App Service Base class and registered it in AppTestBase's PreInitilize method and It worked!! Below is working code snippet:

public abstract class GodseyPrecisionAgAppServiceBase : ApplicationService
    {
        public TenantManager TenantManager { get; set; }

        public UserManager UserManager { get; set; }

        //public GPASession GPASession { get; set; }
        public IGPASession GPASession { get; set; }
public abstract class AppTestBase : AbpIntegratedTestBase<GodseyPrecisionAgTestModule>
    {
        private DbConnection _hostDb;
        private Dictionary<int, DbConnection> _tenantDbs; //only used for db per tenant architecture
        public TestGPASession GPASession { get; private set; }

        protected AppTestBase()
        {
            GPASession = Resolve<TestGPASession>();
protected override void PreInitialize()
        {
            LocalIocManager.Register<IGPASession, TestGPASession>();

            base.PreInitialize();

            UseSingleDatabase();
            //UseDatabasePerTenant();
        }

Thanks for the help!

Answer

Hi,

Can you please help me on above issue (using custom session in unit testing)?

Thanks

Answer

I have added a property in application services base class as below:

public abstract class GodseyPrecisionAgAppServiceBase : ApplicationService
    {
        public GPASession GPASession { get; set; }

I am using it in application services as below:

public async Task<ListResultDto<RoleListDto>> GetRoles(GetRolesInput input)
        {
            var roles = await _roleManager
                .Roles
                .Where(r => r.OrgAdminUserId == GPASession.OrgAdminUserId)
                .WhereIf(
                    !input.Permission.IsNullOrWhiteSpace(),
                    r => r.Permissions.Any(rp => rp.Name == input.Permission && rp.IsGranted)
                )
                .ToListAsync();

            return new ListResultDto<RoleListDto>(roles.MapTo<List<RoleListDto>>());
        }

Now, when I tried to write unit tests for this method, GPASession.OrgAdminUserId property is always null, because it reads the value from Claim. So, I created one TestGPASession class as below:

public class TestGPASession : ClaimsAbpSession
    {
        public ITenantIdAccessor TenantIdAccessor { get; set; }

        public TestGPASession(IMultiTenancyConfig multiTenancy)
            : base(multiTenancy)
        {

        }

        public long? ParentUserId { get; set; }

        public long? OrgAdminUserId { get; set; }

        public bool IsSuperAdmin { get; set; }
    }

And done changes to use it in AppTestBase class as below:

public abstract class AppTestBase : AbpIntegratedTestBase<GodseyPrecisionAgTestModule>
    {
        private DbConnection _hostDb;
        private Dictionary<int, DbConnection> _tenantDbs; //only used for db per tenant architecture
        public TestGPASession GPASession { get; private set; }

        protected AppTestBase()
        {
            GPASession = Resolve<TestGPASession>();

            //Seed initial data for host
            AbpSession.TenantId = null;
            UsingDbContext(context =>
            {
                context.EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
                context.EventBus = NullEventBus.Instance;

                new InitialHostDbBuilder(context).Create();
                new DefaultTenantBuilder(context).Create();
            });

            //Seed initial data for default tenant
            AbpSession.TenantId = 1;
            UsingDbContext(context =>
            {
                context.EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
                context.EventBus = NullEventBus.Instance;

                new TenantRoleAndUserBuilder(context, 1).Create();
                new TestDataBuilder(context, 1).Create();
            });

            LoginAsDefaultTenantAdmin();
        }

        protected override void PreInitialize()
        {
           LocalIocManager.Register<IAbpSession, TestGPASession>();

            base.PreInitialize();

            UseSingleDatabase();
            //UseDatabasePerTenant();
        }

Now, I am facing an issue with dependency injection, in RoleAppService when I access GPASession object, it always resolved as GPASession not with TestGPASession, though I have registered in PreInitilize method as LocalIocManager.Register<IAbpSession, TestGPASession>();. Can you please tell me what I am missing here?

Thanks

Showing 1 to 10 of 19 entries