Base solution for your next web application
Open Closed

Localization issue on Test #9803


User avatar
0
andmattia created

Prerequisites

  • 4.8.1
  • Angular
  • netCore 2.2

I try to test our method that derived from ApplicationService and I try to validate my permission via IPermissionChecker.Authorize.

When I test it I receive

Abp.AbpException
No language defined!
   in Abp.Localization.MultiTenantLocalizationDictionaryProvider.GetDefaultDictionary()
   in Abp.Localization.Dictionaries.DictionaryBasedLocalizationSource.GetStringOrNull(String name, CultureInfo culture, Boolean tryDefaults)
   in Abp.Localization.Dictionaries.DictionaryBasedLocalizationSource.GetString(String name, CultureInfo culture)
   in Abp.Localization.LocalizableString.Localize(ILocalizationContext context)
   in System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   in System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   in System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   in Abp.Authorization.PermissionCheckerExtensions.LocalizePermissionNames(IPermissionChecker permissionChecker, String[] permissionNames)
   in Abp.Authorization.PermissionCheckerExtensions.<AuthorizeAsync>d__9.MoveNext()

I look into base test project but I don't find anithing related to Localization/Language, how can I solve it?


4 Answer(s)
  • User Avatar
    0
    andmattia created

    I think this issue is related to our arch beacuse we have 2 DbContext in 2 separate EFCore project. So when application run normally 2 dbcontext are resolved normally but during the test I see that test base project use a "fake" dbcontext (based on sqlLite).

    I look into the demo app with 2 dbcontext but is not our case (because we use 2 different project).

    Any Idea how can I start my Test with 2 dbContext?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @andmattia

    We don't have such an experience but if thi is the only problem, you can replace MultiTenantLocalizationDictionaryProvider with a fake one for your test. Could that work ?

  • User Avatar
    0
    andmattia created

    Hi after a lot of rework I found a partial solution to our context

    public override void PreInitialize()
            {
                //....
                 RegisterFakeService<firstDbContext>();
                RegisterFakeService<secondDbContext>();
                //....
                }
    
    RegisterIdentity(iocManager);
    
                var builder = new DbContextOptionsBuilder<firstDbContext>();
                var builder2 = new DbContextOptionsBuilder<secondDbContext>();
    
                var sqlite1 = new SqliteConnection("Data Source=firstDbContext.db");
                var sqlite2 = new SqliteConnection("Data Source=secondDbContext.db");
                
                builder.UseSqlite(sqlite1);
                builder2.UseSqlite(sqlite2);
                
                iocManager.IocContainer.Register(
                    Component
                        .For<DbContextOptions<firstDbContext>>()
                        .Instance(builder.Options)
                        .LifestyleSingleton()
                );
    
                iocManager.IocContainer.Register(
                    Component
                        .For<DbContextOptions<secondDbContext>>()
                        .Instance(builder2.Options)
                        .LifestyleSingleton()
                );
    
                sqlite1.Open();
                sqlite2.Open();
    
                new firstDbContext(builder.Options).Database.EnsureCreated();
                new secondDbContext(builder2.Options).Database.EnsureCreated();
    

    So now I have a problem related to sqlLite that I not allow multiple connection. So I need to check if I can redo Seed or other strategy

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @andmattia

    Thank you for sharing the solution. If that doesn't work, maybe you can try to use a real database but its perfomance will be much slower.